苍穹外卖项目初始化代码-提交订单
This commit is contained in:
@@ -3,11 +3,13 @@ package com.sky;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableTransactionManagement //开启注解方式的事务管理
|
||||
@Slf4j
|
||||
@EnableCaching
|
||||
public class SkyApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SkyApplication.class, args);
|
||||
|
||||
18
sky-server/src/main/java/com/sky/annotation/AutoFill.java
Normal file
18
sky-server/src/main/java/com/sky/annotation/AutoFill.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.sky.annotation;
|
||||
|
||||
import com.sky.enumeration.OperationType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 公共字段自动填充注解(标记)
|
||||
**/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface AutoFill {
|
||||
//当前操作类型:INSERT、UPDATE
|
||||
OperationType value(); //sky-common模块中的枚举
|
||||
}
|
||||
82
sky-server/src/main/java/com/sky/aspect/AutoFillAspect.java
Normal file
82
sky-server/src/main/java/com/sky/aspect/AutoFillAspect.java
Normal file
@@ -0,0 +1,82 @@
|
||||
package com.sky.aspect;
|
||||
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.constant.AutoFillConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公共字段自动填充的切面
|
||||
*/
|
||||
@Aspect //通过这个注解来标记当前这个类是一个切面类
|
||||
@Component //注意:切面对象本质也是一个spring容器中的bean对象
|
||||
@Slf4j
|
||||
public class AutoFillAspect {
|
||||
|
||||
/**
|
||||
* 通过切入点指定我们需要拦截哪些类或者哪些方法
|
||||
*/
|
||||
// @Pointcut("execution(* com.sky.mapper.*.*(..)) && @annotation(com.sky.annotation.AutoFill)")
|
||||
@Pointcut("@annotation(com.sky.annotation.AutoFill)")
|
||||
public void autoFilePointCut() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 前置通知:在通知中进行公共字段的赋值
|
||||
*/
|
||||
@Before("autoFilePointCut()")
|
||||
public void autoFill(JoinPoint joinPoint) {
|
||||
log.info("开始进行公共字段自动填充...");
|
||||
//为实体类中公共的属性设置值
|
||||
MethodSignature signature = (MethodSignature) joinPoint.getSignature();//获得方法签名对象
|
||||
//获得当前被拦截的方法对象
|
||||
Method method = signature.getMethod();
|
||||
//获得当前方法上的注解对象
|
||||
AutoFill annotation = method.getAnnotation(AutoFill.class);
|
||||
//获得当前数据库操作类型,从注解中就可以获取到
|
||||
//本次数据库操作的类型是什么?
|
||||
OperationType operationType = annotation.value();
|
||||
System.out.println(operationType);
|
||||
//实体类在哪?在连接点的方法参数中
|
||||
//获得当前被拦截的方法上的参数列表
|
||||
Object[] args = joinPoint.getArgs();
|
||||
//安全判断,没有参数则不操作
|
||||
if (args == null || args.length == 0) {
|
||||
return;
|
||||
}
|
||||
//不能写死employee
|
||||
Object entity = args[0];
|
||||
//赋的值是什么?
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Long currentId = BaseContext.getCurrentId();
|
||||
//判断当前数据库操作类型
|
||||
//需要为4个属性赋值,需要通过反射来赋值
|
||||
try {
|
||||
if (operationType == OperationType.INSERT) {
|
||||
// Method setCreateTimeMethod = entity.getClass().getDeclaredMethod("setCreateTime", LocalDateTime.class);
|
||||
Method setCreateTimeMethod = entity.getClass().getDeclaredMethod(AutoFillConstant.SET_CREATE_TIME, LocalDateTime.class);
|
||||
Method setCreateUserMethod = entity.getClass().getDeclaredMethod("setCreateUser", Long.class);
|
||||
setCreateUserMethod.invoke(entity, currentId);
|
||||
//通过反射来调用上面的方法
|
||||
setCreateTimeMethod.invoke(entity, now);//相当于 category.setCreateTime(now);
|
||||
}
|
||||
Method setUpdateTimeMethod = entity.getClass().getDeclaredMethod("setUpdateTime", LocalDateTime.class);
|
||||
setUpdateTimeMethod.invoke(entity, now);
|
||||
Method setUpdateUserMethod = entity.getClass().getDeclaredMethod("setUpdateUser", Long.class);
|
||||
setUpdateUserMethod.invoke(entity, currentId);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.properties.InmindAliOSSProperties;
|
||||
import com.sky.utils.InmindAliOSSUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class OssConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean//当bean对象不存在则创建,保证spring中只有一个bean对象
|
||||
public InmindAliOSSUtils inmindAliOSSUtils(InmindAliOSSProperties aliOSSProperties) {
|
||||
log.info("开始创建阿里云文件上传工具类对象:{}", aliOSSProperties);
|
||||
return new InmindAliOSSUtils(aliOSSProperties);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sky.config;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
|
||||
/**
|
||||
* redis的配置类
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
|
||||
@Bean
|
||||
//由于导入了Spring的redis起步依赖,已经将redis连接工厂类,加载到spring容器,只要定义参数就可以直接使用
|
||||
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
log.info("开始创建redis模板对象...");
|
||||
RedisTemplate redisTemplate = new RedisTemplate();
|
||||
//设置redis的连接工厂对象
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
//设置redis key的序列化器
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
package com.sky.config;
|
||||
|
||||
import com.sky.interceptor.JwtTokenAdminInterceptor;
|
||||
import com.sky.interceptor.JwtTokenUserInterceptor;
|
||||
import com.sky.json.JacksonObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.converter.HttpMessageConverter;
|
||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import springfox.documentation.builders.ApiInfoBuilder;
|
||||
import springfox.documentation.builders.PathSelectors;
|
||||
import springfox.documentation.builders.RequestHandlerSelectors;
|
||||
@@ -15,26 +20,36 @@ import springfox.documentation.service.ApiInfo;
|
||||
import springfox.documentation.spi.DocumentationType;
|
||||
import springfox.documentation.spring.web.plugins.Docket;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 配置类,注册web层相关组件
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
//public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
public class WebMvcConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Autowired
|
||||
private JwtTokenAdminInterceptor jwtTokenAdminInterceptor;
|
||||
@Autowired
|
||||
private JwtTokenUserInterceptor jwtTokenUserInterceptor;
|
||||
|
||||
/**
|
||||
* 注册自定义拦截器
|
||||
*
|
||||
* @param registry
|
||||
*/
|
||||
protected void addInterceptors(InterceptorRegistry registry) {
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
log.info("开始注册自定义拦截器...");
|
||||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||
.addPathPatterns("/admin/**")
|
||||
.excludePathPatterns("/admin/employee/login");
|
||||
|
||||
registry.addInterceptor(jwtTokenUserInterceptor)
|
||||
.addPathPatterns("/user/**")
|
||||
.excludePathPatterns("/user/user/login")
|
||||
.excludePathPatterns("/user/shop/status");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -42,16 +57,36 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
public Docket docket1() {
|
||||
log.info("准备生成接口文档...");
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("管理端接口")
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket docket2() {
|
||||
log.info("准备生成接口文档...");
|
||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||
.title("苍穹外卖项目接口文档")
|
||||
.version("2.0")
|
||||
.description("苍穹外卖项目接口文档")
|
||||
.build();
|
||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||
.groupName("用户端接口")
|
||||
.apiInfo(apiInfo)
|
||||
.select()
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
@@ -61,8 +96,28 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
* 设置静态资源映射
|
||||
* @param registry
|
||||
*/
|
||||
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/doc.html").addResourceLocations("classpath:/META-INF/resources/");
|
||||
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 扩展springMVC框架的消息转化器
|
||||
* @param converters
|
||||
*/
|
||||
@Override
|
||||
public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
|
||||
log.info("扩展消息转换器.....");
|
||||
//创建一个消息转换器对象(注意:千万不要选错类MappingJackson2CborHttpMessageConverter)
|
||||
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
|
||||
//需要为消息转换器设置一个对象转换器,对象转换器可以将java对象序列化为json数据
|
||||
converter.setObjectMapper(new JacksonObjectMapper());
|
||||
//将自己的消息转化器加入容器中
|
||||
converters.add(0,converter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分类管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/category")
|
||||
@Api(tags = "分类相关接口")
|
||||
@Slf4j
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 新增分类
|
||||
* @param categoryDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增分类")
|
||||
public Result<String> save(@RequestBody CategoryDTO categoryDTO){
|
||||
log.info("新增分类:{}", categoryDTO);
|
||||
categoryService.save(categoryDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分类分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分类分页查询")
|
||||
public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
|
||||
log.info("分页查询:{}", categoryPageQueryDTO);
|
||||
PageResult pageResult = categoryService.pageQuery(categoryPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除分类
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("删除分类")
|
||||
public Result<String> deleteById(Long id){
|
||||
log.info("删除分类:{}", id);
|
||||
categoryService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
* @param categoryDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改分类")
|
||||
public Result<String> update(@RequestBody CategoryDTO categoryDTO){
|
||||
categoryService.update(categoryDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用、禁用分类
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("启用禁用分类")
|
||||
public Result<String> startOrStop(@PathVariable("status") Integer status, Long id){
|
||||
categoryService.startOrStop(status,id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据类型查询分类")
|
||||
public Result<List<Category>> list(Integer type){
|
||||
List<Category> list = categoryService.list(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.utils.InmindAliOSSUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
/*
|
||||
通用接口
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/common")
|
||||
@Api(tags = "通用接口")
|
||||
@Slf4j
|
||||
public class CommonController {
|
||||
|
||||
@Autowired
|
||||
private InmindAliOSSUtils aliOssUtil;
|
||||
|
||||
/**
|
||||
* 文件上传
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/upload")
|
||||
@ApiOperation("文件上传")
|
||||
public Result<String> upload(MultipartFile file){
|
||||
try {
|
||||
//调用阿里云OSS工具类,将文件上传到阿里云服务器,返回完整url地址
|
||||
String path = aliOssUtil.upload(file);
|
||||
return Result.success(path);
|
||||
} catch (Exception e) {
|
||||
log.error("文件上传失败!");
|
||||
}
|
||||
return Result.error(MessageConstant.UPLOAD_FAILED);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@RestController()
|
||||
@RequestMapping("/admin/dish")
|
||||
@Api(tags = "菜品相关接口")
|
||||
@Slf4j
|
||||
public class DishController {
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 新增菜品
|
||||
* @param dishDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增菜品")
|
||||
public Result add(@RequestBody DishDTO dishDTO){
|
||||
log.info("新增菜品:{}",dishDTO);
|
||||
dishService.saveWithFlavor(dishDTO);
|
||||
String key = "dish_"+dishDTO.getCategoryId();
|
||||
cleanCache(key);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("菜品分页查询")
|
||||
public Result<PageResult> page(DishPageQueryDTO dishPageQueryDTO){
|
||||
log.info("菜品分页查询:{}",dishPageQueryDTO);
|
||||
PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除菜品
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("菜品批量删除")
|
||||
public Result delete(@RequestParam List<Long> ids){//@RequestParam:能够使用springmvc框架对1,2,3进行切割解析到集合中
|
||||
log.info("菜品批量删除:{}",ids);
|
||||
dishService.deleteBatch(ids);
|
||||
cleanCache("dish_*");
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据id查询菜品
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询菜品")
|
||||
public Result<DishVO> getById(@PathVariable Long id){
|
||||
log.info("根据id查询菜品:{}",id);
|
||||
DishVO dishVO = dishService.getByIdWithFlavor(id);
|
||||
return Result.success(dishVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改菜品
|
||||
* @param dishDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改菜品")
|
||||
public Result update(@RequestBody DishDTO dishDTO){
|
||||
log.info("修改菜品:{}",dishDTO);
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
cleanCache("dish_*");
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 菜品起售停售
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("菜品起售停售")
|
||||
public Result<String> startOrStop(@PathVariable Integer status, Long id){
|
||||
dishService.startOrStop(status,id);
|
||||
|
||||
cleanCache("dish_*");
|
||||
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<Dish>> list(Long categoryId){
|
||||
List<Dish> list = dishService.list(categoryId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清理缓存数据
|
||||
* @param pattern
|
||||
*/
|
||||
public void cleanCache(String pattern){
|
||||
//查询所有dish_开头的key
|
||||
Set keys = redisTemplate.keys(pattern);
|
||||
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,21 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.EmployeeService;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import com.sky.vo.EmployeeLoginVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -24,6 +26,7 @@ import java.util.Map;
|
||||
@RestController
|
||||
@RequestMapping("/admin/employee")
|
||||
@Slf4j
|
||||
@Api(tags = "员工相关接口")//描述当前的作用
|
||||
public class EmployeeController {
|
||||
|
||||
@Autowired
|
||||
@@ -38,6 +41,7 @@ public class EmployeeController {
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("员工登录")//描述当前方法的作用
|
||||
public Result<EmployeeLoginVO> login(@RequestBody EmployeeLoginDTO employeeLoginDTO) {
|
||||
log.info("员工登录:{}", employeeLoginDTO);
|
||||
|
||||
@@ -66,9 +70,66 @@ public class EmployeeController {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("员工退出")
|
||||
@PostMapping("/logout")
|
||||
public Result<String> logout() {
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("新增员工")
|
||||
@PostMapping
|
||||
public Result<String> save(@RequestBody EmployeeDTO employeeDTO) {
|
||||
log.info("新增员工:{}",employeeDTO);
|
||||
System.out.println("当前线程的id:"+Thread.currentThread().getId());
|
||||
employeeService.save(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 员工分页查询
|
||||
* @param employeePageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation("员工分页查询")
|
||||
@GetMapping("/page")
|
||||
public Result<PageResult> page(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||
log.info("员工分页查询:{}",employeePageQueryDTO);
|
||||
PageResult pageResult = employeeService.pageQuery(employeePageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("启用禁用员工账号")
|
||||
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||
log.info("启用禁用员工账号:{},{}",status,id);
|
||||
employeeService.startOrStop(status,id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据Id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据Id查询员工")
|
||||
public Result<Employee> getById(@PathVariable Long id){
|
||||
Employee employee = employeeService.getById(id);
|
||||
return Result.success(employee);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改员工
|
||||
* @param employeeDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("编辑员工")
|
||||
public Result update(@RequestBody EmployeeDTO employeeDTO){
|
||||
log.info("编辑员工信息:{}",employeeDTO);
|
||||
employeeService.update(employeeDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 套餐管理
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/admin/setmeal")
|
||||
@Api(tags = "套餐相关接口")
|
||||
@Slf4j
|
||||
public class SetmealController {
|
||||
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")//key: setmealCache::2
|
||||
public Result save(@RequestBody SetmealDTO setmealDTO) {
|
||||
setmealService.saveWithDish(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperation("分页查询")
|
||||
public Result<PageResult> page(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("批量删除套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result delete(@RequestParam List<Long> ids){
|
||||
setmealService.deleteBatch(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐,用于修改页面回显数据
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询套餐")
|
||||
public Result<SetmealVO> getById(@PathVariable Long id) {
|
||||
SetmealVO setmealVO = setmealService.getByIdWithDish(id);
|
||||
return Result.success(setmealVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
*
|
||||
* @param setmealDTO
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("修改套餐")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO) {
|
||||
setmealService.update(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
* @param status
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/status/{status}")
|
||||
@ApiOperation("套餐起售停售")
|
||||
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||
public Result startOrStop(@PathVariable Integer status, Long id) {
|
||||
setmealService.startOrStop(status, id);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.sky.controller.admin;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 店铺营业状态
|
||||
**/
|
||||
@RestController("adminShopController")
|
||||
@RequestMapping("/admin/shop")
|
||||
@Api(tags = "店铺状态相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
public static final String SHOP_STATUS = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 设置营业状态
|
||||
* @param status
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/{status}")
|
||||
@ApiOperation("设置营业状态")
|
||||
public Result setStatus(@PathVariable Integer status){
|
||||
log.info("设置店铺的营业状态:{}",status == 1?"营业中":"打烊中");
|
||||
redisTemplate.opsForValue().set(SHOP_STATUS,status);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取营业状态
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
|
||||
log.info("获取店铺的营业状态:{}",status == 1?"营业中":"打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.AddressBookService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/addressBook")
|
||||
@Api(tags = "C端地址簿接口")
|
||||
public class AddressBookController {
|
||||
|
||||
@Autowired
|
||||
private AddressBookService addressBookService;
|
||||
|
||||
/**
|
||||
* 查询当前登录用户的所有地址信息
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询当前登录用户的所有地址信息")
|
||||
public Result<List<AddressBook>> list() {
|
||||
AddressBook addressBook = new AddressBook();
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
List<AddressBook> list = addressBookService.list(addressBook);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增地址
|
||||
*
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@PostMapping
|
||||
@ApiOperation("新增地址")
|
||||
public Result save(@RequestBody AddressBook addressBook) {
|
||||
addressBookService.save(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
@ApiOperation("根据id查询地址")
|
||||
public Result<AddressBook> getById(@PathVariable Long id) {
|
||||
AddressBook addressBook = addressBookService.getById(id);
|
||||
return Result.success(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id修改地址
|
||||
*
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@PutMapping
|
||||
@ApiOperation("根据id修改地址")
|
||||
public Result update(@RequestBody AddressBook addressBook) {
|
||||
addressBookService.update(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认地址
|
||||
*
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
@PutMapping("/default")
|
||||
@ApiOperation("设置默认地址")
|
||||
public Result setDefault(@RequestBody AddressBook addressBook) {
|
||||
addressBookService.setDefault(addressBook);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除地址
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping
|
||||
@ApiOperation("根据id删除地址")
|
||||
public Result deleteById(Long id) {
|
||||
addressBookService.deleteById(id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询默认地址
|
||||
*/
|
||||
@GetMapping("default")
|
||||
@ApiOperation("查询默认地址")
|
||||
public Result<AddressBook> getDefault() {
|
||||
//SQL:select * from address_book where user_id = ? and is_default = 1
|
||||
AddressBook addressBook = new AddressBook();
|
||||
addressBook.setIsDefault(1);
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
List<AddressBook> list = addressBookService.list(addressBook);
|
||||
|
||||
if (list != null && list.size() == 1) {
|
||||
return Result.success(list.get(0));
|
||||
}
|
||||
|
||||
return Result.error("没有查询到默认地址");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.CategoryService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
@RestController("userCategoryController")
|
||||
@RequestMapping("/user/category")
|
||||
@Api(tags = "C端-分类接口")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询分类")
|
||||
public Result<List<Category>> list(Integer type) {
|
||||
List<Category> list = categoryService.list(type);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.ReactiveRedisOperations;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
@RestController("userDishController")
|
||||
@RequestMapping("/user/dish")
|
||||
@Slf4j
|
||||
@Api(tags = "C端-菜品浏览接口")
|
||||
public class DishController {
|
||||
@Autowired
|
||||
private DishService dishService;
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
*
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<DishVO>> list(Long categoryId) {
|
||||
//这里采用redis中的String数据类型存储数据,但是redis的string与java的string不是同一个概念,它可以将对象序列化到reids中,再从redis中反序列化出对应的对象
|
||||
//1.构造redis中的key,规则:dish_分类id
|
||||
String key = "dish_"+categoryId;
|
||||
//2.查询redis中是否存在菜品数据
|
||||
List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
|
||||
//3.如果存在,直接返回,无须查询数据库
|
||||
if (list != null && list.size() > 0) {
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
//4.如果不存在,查询数据库,将查询到的数据翻入redis中
|
||||
Dish dish = new Dish();
|
||||
dish.setCategoryId(categoryId);
|
||||
dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
|
||||
|
||||
list = dishService.listWithFlavor(dish);
|
||||
//5.保存到redis中
|
||||
redisTemplate.opsForValue().set(key,list);
|
||||
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 订单操作控制器
|
||||
*
|
||||
**/
|
||||
@RestController("userOrderController")//控制器重新定义一个名字,与管理端的订单管理进行区分
|
||||
@RequestMapping("/user/order")
|
||||
@Api(tags = "用户端订单相关接口")
|
||||
@Slf4j
|
||||
public class OrderController {
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
/**
|
||||
* 用户下单
|
||||
*
|
||||
* @param ordersSubmitDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperation("用户下单")
|
||||
public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
|
||||
log.info("用户下单,参数为:{}", ordersSubmitDTO);
|
||||
OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
|
||||
return Result.success(orderSubmitVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
|
||||
@RestController("userSetmealController")
|
||||
@RequestMapping("/user/setmeal")
|
||||
@Api(tags = "C端-套餐浏览接口")
|
||||
public class SetmealController {
|
||||
@Autowired
|
||||
private SetmealService setmealService;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
*
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询套餐")
|
||||
//key: setmealCache::categoryId (查询或储存缓存!!!!)
|
||||
@Cacheable(cacheNames = "setmealCache" ,key = "#categoryId")
|
||||
public Result<List<Setmeal>> list(Long categoryId) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
setmeal.setCategoryId(categoryId);
|
||||
setmeal.setStatus(StatusConstant.ENABLE);
|
||||
|
||||
List<Setmeal> list = setmealService.list(setmeal);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据套餐id查询包含的菜品列表
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/dish/{id}")
|
||||
@ApiOperation("根据套餐id查询包含的菜品列表")
|
||||
public Result<List<DishItemVO>> dishList(@PathVariable("id") Long id) {
|
||||
List<DishItemVO> list = setmealService.getDishItemById(id);
|
||||
return Result.success(list);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.result.Result;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 店铺营业状态
|
||||
**/
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/user/shop")
|
||||
@Api(tags = "店铺状态相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {//控制器会放入spring,重名会有问题
|
||||
|
||||
public static final String SHOP_STATUS = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 获取营业状态
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
|
||||
log.info("获取店铺的营业状态:{}",status == 1?"营业中":"打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.ShoppingCartService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/shoppingCart")
|
||||
@Slf4j
|
||||
@Api(tags = "C端购物车相关接口")
|
||||
public class ShoppingCartController {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCartService shoppingCartService;
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
* @param shoppingCartDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
@ApiOperation("添加购物车")
|
||||
public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
|
||||
log.info("添加购物车,商品信息:{}",shoppingCartDTO);
|
||||
shoppingCartService.addShoppingCart(shoppingCartDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看购物车
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查看购物车")
|
||||
public Result<List<ShoppingCart>> showShoppingCart(){
|
||||
log.info("查看购物车!!");
|
||||
List<ShoppingCart> list = shoppingCartService.showShoppingCart();
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
* @return
|
||||
*/
|
||||
@DeleteMapping("/clean")
|
||||
@ApiOperation("清空购物车")
|
||||
public Result cleanShoppingCart(){
|
||||
shoppingCartService.cleanShoppingCart();
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.sky.controller.user;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.result.Result;
|
||||
import com.sky.service.UserService;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import com.sky.vo.UserLoginVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/user/user")
|
||||
@Slf4j
|
||||
@Api(tags = "C端用户相关接口")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Autowired
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
/**
|
||||
* 微信用户登录
|
||||
* @param userLoginDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/login")
|
||||
@ApiOperation("微信用户登录")
|
||||
public Result<UserLoginVO> wxLogin(@RequestBody UserLoginDTO userLoginDTO){
|
||||
log.info("微信用户登录:{}", userLoginDTO.getCode());
|
||||
User user = userService.wxLogin(userLoginDTO);
|
||||
//为微信用户生成jwt令牌
|
||||
Map<String, Object> claims = new HashMap<>();
|
||||
claims.put(JwtClaimsConstant.USER_ID, user.getId());
|
||||
String token = JwtUtil.createJWT(jwtProperties.getUserSecretKey(), jwtProperties.getUserTtl(), claims);
|
||||
UserLoginVO userLoginVO = UserLoginVO.builder()
|
||||
.id(user.getId())
|
||||
.openid(user.getOpenid())
|
||||
.token(token)
|
||||
.build();
|
||||
return Result.success(userLoginVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package com.sky.handler;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.exception.BaseException;
|
||||
import com.sky.result.Result;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||
|
||||
import java.sql.SQLIntegrityConstraintViolationException;
|
||||
|
||||
/**
|
||||
* 全局异常处理器,处理项目中抛出的业务异常
|
||||
*/
|
||||
@@ -24,4 +27,24 @@ public class GlobalExceptionHandler {
|
||||
return Result.error(ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理SQL异常
|
||||
* @param ex
|
||||
* @return
|
||||
*/
|
||||
@ExceptionHandler
|
||||
public Result exceptionHandler(SQLIntegrityConstraintViolationException ex){
|
||||
//Duplicate entry 'zhangsan' for key 'idx_username'
|
||||
String message = ex.getMessage();
|
||||
if(message.contains("Duplicate entry")){
|
||||
String[] split = message.split(" ");
|
||||
String username = split[2];
|
||||
// String msg = username + "已经存在";
|
||||
String msg = username + MessageConstant.ALEADY_EXISTS;
|
||||
return Result.error(msg);
|
||||
}else {
|
||||
return Result.error(MessageConstant.UNKNOWN_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.sky.interceptor;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
@@ -47,6 +48,7 @@ public class JwtTokenAdminInterceptor implements HandlerInterceptor {
|
||||
Claims claims = JwtUtil.parseJWT(jwtProperties.getAdminSecretKey(), token);
|
||||
Long empId = Long.valueOf(claims.get(JwtClaimsConstant.EMP_ID).toString());
|
||||
log.info("当前员工id:", empId);
|
||||
BaseContext.setCurrentId(empId);
|
||||
//3、通过,放行
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
package com.sky.interceptor;
|
||||
|
||||
import com.sky.constant.JwtClaimsConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.properties.JwtProperties;
|
||||
import com.sky.utils.JwtUtil;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* jwt令牌校验的拦截器
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class JwtTokenUserInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JwtProperties jwtProperties;
|
||||
|
||||
/**
|
||||
* 校验jwt
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param handler
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
System.out.println("当前线程的id:"+Thread.currentThread().getId());
|
||||
|
||||
//判断当前拦截到的是Controller的方法还是其他资源
|
||||
if (!(handler instanceof HandlerMethod)) {
|
||||
//当前拦截到的不是动态方法,直接放行
|
||||
return true;
|
||||
}
|
||||
|
||||
//1、从请求头中获取令牌
|
||||
String token = request.getHeader(jwtProperties.getUserTokenName());
|
||||
|
||||
//2、校验令牌
|
||||
try {
|
||||
log.info("jwt校验:{}", token);
|
||||
Claims claims = JwtUtil.parseJWT(jwtProperties.getUserSecretKey(), token);
|
||||
Long userId = Long.valueOf(claims.get(JwtClaimsConstant.USER_ID).toString());
|
||||
log.info("当前用户id:{}", userId);
|
||||
//保存登录id
|
||||
BaseContext.setCurrentId(userId);
|
||||
//3、通过,放行
|
||||
return true;
|
||||
} catch (Exception ex) {
|
||||
//4、不通过,响应401状态码
|
||||
response.setStatus(401);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.AddressBook;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface AddressBookMapper {
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
List<AddressBook> list(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param addressBook
|
||||
*/
|
||||
@Insert("insert into address_book" +
|
||||
" (user_id, consignee, phone, sex, province_code, province_name, city_code, city_name, district_code," +
|
||||
" district_name, detail, label, is_default)" +
|
||||
" values (#{userId}, #{consignee}, #{phone}, #{sex}, #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}," +
|
||||
" #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
|
||||
void insert(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from address_book where id = #{id}")
|
||||
AddressBook getById(Long id);
|
||||
|
||||
/**
|
||||
* 根据id修改
|
||||
* @param addressBook
|
||||
*/
|
||||
void update(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* 根据 用户id修改 是否默认地址
|
||||
* @param addressBook
|
||||
*/
|
||||
@Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
|
||||
void updateIsDefaultByUserId(AddressBook addressBook);
|
||||
|
||||
/**
|
||||
* 根据id删除地址
|
||||
* @param id
|
||||
*/
|
||||
@Delete("delete from address_book where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
|
||||
}
|
||||
53
sky-server/src/main/java/com/sky/mapper/CategoryMapper.java
Normal file
53
sky-server/src/main/java/com/sky/mapper/CategoryMapper.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
* @param category
|
||||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
@Insert("insert into category(type, name, sort, status, create_time, update_time, create_user, update_user)" +
|
||||
" VALUES" +
|
||||
" (#{type}, #{name}, #{sort}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
|
||||
void insert(Category category);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
Page<Category> pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据id删除分类
|
||||
* @param id
|
||||
*/
|
||||
@Delete("delete from category where id = #{id}")
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 根据id修改分类
|
||||
* @param category
|
||||
*/
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Category category);
|
||||
|
||||
/**
|
||||
* 根据类型查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<Category> list(Integer type);
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.DishFlavor;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DishFlavorMapper {
|
||||
void insertBath(List<DishFlavor> flavors);
|
||||
|
||||
/**
|
||||
* 根据菜品id,删除对应的口味数据
|
||||
* @param dishId
|
||||
*/
|
||||
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
||||
void deleteByDishId(Long dishId);
|
||||
|
||||
void deleteByDishIds(List<Long> dishIds);
|
||||
|
||||
/**
|
||||
* 根据菜品id查询对应的口味数据
|
||||
* @param dishId
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from dish_flavor where dish_id = #{dishId}")
|
||||
List<DishFlavor> getByDishId(Long dishId);
|
||||
}
|
||||
71
sky-server/src/main/java/com/sky/mapper/DishMapper.java
Normal file
71
sky-server/src/main/java/com/sky/mapper/DishMapper.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface DishMapper {
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品数量
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
@Select("select count(id) from dish where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long categoryId);
|
||||
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Dish dish);
|
||||
|
||||
Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据主键查询菜品
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from dish where id = #{id}")
|
||||
Dish getById(Long id);
|
||||
|
||||
/**
|
||||
* 根据id删除菜品
|
||||
* @param dishId
|
||||
*/
|
||||
@Delete("delete from dish where id = #{dishId}")
|
||||
void deleteById(Long dishId);
|
||||
|
||||
void deleteByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id动态修改菜品数据
|
||||
* @param dish
|
||||
*/
|
||||
@AutoFill(value = OperationType.UPDATE)
|
||||
void update(Dish dish);
|
||||
|
||||
/**
|
||||
* 动态条件查询菜品
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Dish dish);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
@Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
|
||||
List<Dish> getBySetmealId(Long setmealId);
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.annotation.AutoFill;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
@@ -15,4 +20,22 @@ public interface EmployeeMapper {
|
||||
@Select("select * from employee where username = #{username}")
|
||||
Employee getByUsername(String username);
|
||||
|
||||
|
||||
@AutoFill(OperationType.INSERT)
|
||||
@Insert("insert into employee (name, username, password, phone, sex, id_number, create_time, update_time, create_user, update_user) " +
|
||||
"values (#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{createTime},#{updateTime},#{createUser},#{updateUser})")
|
||||
void insert(Employee employee);
|
||||
|
||||
Page<Employee> pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Employee employee);
|
||||
|
||||
/**
|
||||
* 根据Id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from employee where id = #{id}")
|
||||
Employee getById(Long id);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.OrderDetail;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderDetailMapper {
|
||||
/**
|
||||
* 批量保存订单明细
|
||||
* @param orderDetailList
|
||||
*/
|
||||
void insertBatch(List<OrderDetail> orderDetailList);
|
||||
}
|
||||
13
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
13
sky-server/src/main/java/com/sky/mapper/OrderMapper.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.Orders;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Options;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
@Insert("insert into orders (number, status, user_id, address_book_id, order_time, checkout_time, pay_method, pay_status, amount, remark," +"phone, address, consignee, estimated_delivery_time, delivery_status, pack_amount,tableware_number,tableware_status) values (#{number}, #{status}, #{userId}, #{addressBookId}, #{orderTime}, #{checkoutTime}, #{payMethod},#{payStatus}, #{amount}, #{remark}, #{phone}, #{address}, #{consignee},#{estimatedDeliveryTime}, #{deliveryStatus}, #{packAmount}, #{tablewareNumber}, #{tablewareStatus})")
|
||||
@Options(useGeneratedKeys = true,keyProperty = "id")
|
||||
void insert(Orders order);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.SetmealDish;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 操作套餐和菜品的关系表
|
||||
**/
|
||||
@Mapper
|
||||
public interface SetmealDishMapper {
|
||||
/**
|
||||
* 根据菜品id查询套餐id
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* 根据菜品id查询关联套餐id
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
//select setmeal_id from setmeal_dish where dish_id in(1,2,3);
|
||||
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 批量保存套餐和菜品的关联关系
|
||||
* @param setmealDishes
|
||||
*//*
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
*//**
|
||||
* 根据套餐id删除套餐和菜品的关联关系
|
||||
* @param setmealId
|
||||
*//*
|
||||
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
|
||||
*//**
|
||||
* 根据套餐id查询套餐和菜品的关联关系
|
||||
* @param setmealId
|
||||
* @return
|
||||
*//*
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long setmealId);*/
|
||||
|
||||
/**
|
||||
* 批量保存套餐和菜品的关联关系
|
||||
* @param setmealDishes
|
||||
*/
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
/**
|
||||
* 根据套餐id删除套餐和菜品的关联关系
|
||||
* @param setmealId
|
||||
*/
|
||||
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询套餐和菜品的关联关系
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||
List<SetmealDish> getBySetmealId(Long setmealId);
|
||||
}
|
||||
85
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
85
sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
Normal file
@@ -0,0 +1,85 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface SetmealMapper {
|
||||
|
||||
/**
|
||||
* 根据分类id查询套餐的数量
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||
Integer countByCategoryId(Long id);
|
||||
|
||||
/**
|
||||
* 根据id修改套餐
|
||||
*
|
||||
* @param setmeal
|
||||
*/
|
||||
void update(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 新增套餐
|
||||
* @param setmeal
|
||||
*/
|
||||
void insert(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Select("select * from setmeal where id = #{id}")
|
||||
Setmeal getById(Long id);
|
||||
|
||||
/**
|
||||
* 根据id删除套餐
|
||||
* @param setmealId
|
||||
*/
|
||||
@Delete("delete from setmeal where id = #{id}")
|
||||
void deleteById(Long setmealId);
|
||||
|
||||
/**
|
||||
* 动态条件查询套餐
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询菜品选项
|
||||
* @param setmealId
|
||||
* @return
|
||||
*/
|
||||
@Select("select sd.name, sd.copies, d.image, d.description " +
|
||||
"from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
|
||||
"where sd.setmeal_id = #{setmealId}")
|
||||
List<DishItemVO> getDishItemBySetmealId(Long setmealId);
|
||||
|
||||
/**
|
||||
* 根据条件统计套餐数量
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
Integer countByMap(Map map);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import org.apache.ibatis.annotations.Delete;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Update;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 购物车持久层接口
|
||||
**/
|
||||
@Mapper
|
||||
public interface ShoppingCartMapper {
|
||||
|
||||
/**
|
||||
* 动态条件查询
|
||||
* @param shoppingCart
|
||||
* @return
|
||||
*/
|
||||
List<ShoppingCart> list(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* 更新商品数量
|
||||
*/
|
||||
@Update("update shopping_cart set number = #{number} where id = #{id}")
|
||||
void updateNumberById(ShoppingCart cart);
|
||||
|
||||
/**
|
||||
* 新增购物车数据
|
||||
* @param shoppingCart
|
||||
*/
|
||||
@Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
|
||||
void insert(ShoppingCart shoppingCart);
|
||||
|
||||
/**
|
||||
* 根据用户id删除购物车数据
|
||||
* @param userId
|
||||
*/
|
||||
@Delete("delete from shopping_cart where user_id = #{userId}")
|
||||
void deleteByUserId(Long userId);
|
||||
}
|
||||
23
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
23
sky-server/src/main/java/com/sky/mapper/UserMapper.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.sky.mapper;
|
||||
|
||||
import com.sky.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
//根据openid查询用户
|
||||
@Select("select * from user where openid = #{openid}")
|
||||
User getByOpenid(String openid);
|
||||
|
||||
/**
|
||||
* 插入数据
|
||||
* @param user
|
||||
* @Options(useGeneratedKeys = true,keyProperty = "id")
|
||||
*/
|
||||
void insert(User user);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.entity.AddressBook;
|
||||
import java.util.List;
|
||||
|
||||
public interface AddressBookService {
|
||||
|
||||
List<AddressBook> list(AddressBook addressBook);
|
||||
|
||||
void save(AddressBook addressBook);
|
||||
|
||||
AddressBook getById(Long id);
|
||||
|
||||
void update(AddressBook addressBook);
|
||||
|
||||
void setDefault(AddressBook addressBook);
|
||||
|
||||
void deleteById(Long id);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.result.PageResult;
|
||||
import java.util.List;
|
||||
|
||||
public interface CategoryService {
|
||||
|
||||
/**
|
||||
* 新增分类
|
||||
* @param categoryDTO
|
||||
*/
|
||||
void save(CategoryDTO categoryDTO);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据id删除分类
|
||||
* @param id
|
||||
*/
|
||||
void deleteById(Long id);
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
* @param categoryDTO
|
||||
*/
|
||||
void update(CategoryDTO categoryDTO);
|
||||
|
||||
/**
|
||||
* 启用、禁用分类
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
/**
|
||||
* 根据类型查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
List<Category> list(Integer type);
|
||||
}
|
||||
43
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
43
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface DishService {
|
||||
void saveWithFlavor(DishDTO dishDTO);
|
||||
|
||||
PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
|
||||
|
||||
void deleteBatch(List<Long> ids);
|
||||
|
||||
DishVO getByIdWithFlavor(Long id);
|
||||
|
||||
void updateWithFlavor(DishDTO dishDTO);
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
List<Dish> list(Long categoryId);
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
List<DishVO> listWithFlavor(Dish dish);
|
||||
|
||||
/**
|
||||
* 菜品起售停售
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
}
|
||||
@@ -1,7 +1,10 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.result.PageResult;
|
||||
|
||||
public interface EmployeeService {
|
||||
|
||||
@@ -12,4 +15,13 @@ public interface EmployeeService {
|
||||
*/
|
||||
Employee login(EmployeeLoginDTO employeeLoginDTO);
|
||||
|
||||
void save(EmployeeDTO employeeDTO);
|
||||
|
||||
PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO);
|
||||
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
Employee getById(Long id);
|
||||
|
||||
void update(EmployeeDTO employeeDTO);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
|
||||
public interface OrderService {
|
||||
OrderSubmitVO submit(OrdersSubmitDTO ordersSubmitDTO);
|
||||
}
|
||||
71
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
71
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* desc
|
||||
*
|
||||
**/
|
||||
public interface SetmealService {
|
||||
/**
|
||||
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void saveWithDish(SetmealDTO setmealDTO);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
*/
|
||||
void deleteBatch(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询套餐和关联的菜品数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
SetmealVO getByIdWithDish(Long id);
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
* @param setmealDTO
|
||||
*/
|
||||
void update(SetmealDTO setmealDTO);
|
||||
|
||||
/**
|
||||
* 套餐起售、停售
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
List<Setmeal> list(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<DishItemVO> getDishItemById(Long id);
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ShoppingCartService {
|
||||
void addShoppingCart(ShoppingCartDTO shoppingCartDTO);
|
||||
|
||||
List<ShoppingCart> showShoppingCart();
|
||||
|
||||
void cleanShoppingCart();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.sky.service;
|
||||
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
|
||||
public interface UserService {
|
||||
User wxLogin(UserLoginDTO userLoginDTO);
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.mapper.AddressBookMapper;
|
||||
import com.sky.service.AddressBookService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class AddressBookServiceImpl implements AddressBookService {
|
||||
@Autowired
|
||||
private AddressBookMapper addressBookMapper;
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
*
|
||||
* @param addressBook
|
||||
* @return
|
||||
*/
|
||||
public List<AddressBook> list(AddressBook addressBook) {
|
||||
return addressBookMapper.list(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增地址
|
||||
*
|
||||
* @param addressBook
|
||||
*/
|
||||
public void save(AddressBook addressBook) {
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
addressBook.setIsDefault(0);
|
||||
addressBookMapper.insert(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public AddressBook getById(Long id) {
|
||||
AddressBook addressBook = addressBookMapper.getById(id);
|
||||
return addressBook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id修改地址
|
||||
*
|
||||
* @param addressBook
|
||||
*/
|
||||
public void update(AddressBook addressBook) {
|
||||
addressBookMapper.update(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认地址
|
||||
*
|
||||
* @param addressBook
|
||||
*/
|
||||
@Transactional
|
||||
public void setDefault(AddressBook addressBook) {
|
||||
//1、将当前用户的所有地址修改为非默认地址 update address_book set is_default = ? where user_id = ?
|
||||
addressBook.setIsDefault(0);
|
||||
addressBook.setUserId(BaseContext.getCurrentId());
|
||||
addressBookMapper.updateIsDefaultByUserId(addressBook);
|
||||
|
||||
//2、将当前地址改为默认地址 update address_book set is_default = ? where id = ?
|
||||
addressBook.setIsDefault(1);
|
||||
addressBookMapper.update(addressBook);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除地址
|
||||
*
|
||||
* @param id
|
||||
*/
|
||||
public void deleteById(Long id) {
|
||||
addressBookMapper.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.CategoryDTO;
|
||||
import com.sky.dto.CategoryPageQueryDTO;
|
||||
import com.sky.entity.Category;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.CategoryMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.CategoryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 分类业务层
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
/**
|
||||
* 新增分类
|
||||
* @param categoryDTO
|
||||
*/
|
||||
public void save(CategoryDTO categoryDTO) {
|
||||
Category category = new Category();
|
||||
//属性拷贝
|
||||
BeanUtils.copyProperties(categoryDTO, category);
|
||||
|
||||
//分类状态默认为禁用状态0
|
||||
category.setStatus(StatusConstant.DISABLE);
|
||||
|
||||
//设置创建时间、修改时间、创建人、修改人
|
||||
// category.setCreateTime(LocalDateTime.now());
|
||||
// category.setUpdateTime(LocalDateTime.now());
|
||||
// category.setCreateUser(BaseContext.getCurrentId());
|
||||
// category.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param categoryPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
|
||||
PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
|
||||
//下一条sql进行分页,自动加入limit关键字分页
|
||||
Page<Category> page = categoryMapper.pageQuery(categoryPageQueryDTO);
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id删除分类
|
||||
* @param id
|
||||
*/
|
||||
public void deleteById(Long id) {
|
||||
//查询当前分类是否关联了菜品,如果关联了就抛出业务异常
|
||||
Integer count = dishMapper.countByCategoryId(id);
|
||||
if(count > 0){
|
||||
//当前分类下有菜品,不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_DISH);
|
||||
}
|
||||
|
||||
//查询当前分类是否关联了套餐,如果关联了就抛出业务异常
|
||||
count = setmealMapper.countByCategoryId(id);
|
||||
if(count > 0){
|
||||
//当前分类下有菜品,不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.CATEGORY_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
|
||||
//删除分类数据
|
||||
categoryMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改分类
|
||||
* @param categoryDTO
|
||||
*/
|
||||
public void update(CategoryDTO categoryDTO) {
|
||||
Category category = new Category();
|
||||
BeanUtils.copyProperties(categoryDTO,category);
|
||||
|
||||
//设置修改时间、修改人
|
||||
// category.setUpdateTime(LocalDateTime.now());
|
||||
// category.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
categoryMapper.update(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用、禁用分类
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
Category category = Category.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.updateTime(LocalDateTime.now())
|
||||
.updateUser(BaseContext.getCurrentId())
|
||||
.build();
|
||||
categoryMapper.update(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据类型查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
public List<Category> list(Integer type) {
|
||||
return categoryMapper.list(type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.dto.DishDTO;
|
||||
import com.sky.dto.DishPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.DishFlavor;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.mapper.DishFlavorMapper;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.DishService;
|
||||
import com.sky.vo.DishVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class DishServiceImpl implements DishService {
|
||||
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
/*
|
||||
新增菜品和对应的口味
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public void saveWithFlavor(DishDTO dishDTO) {
|
||||
Dish dish = new Dish();
|
||||
BeanUtils.copyProperties(dishDTO, dish);
|
||||
//向菜品插入1条数据
|
||||
dishMapper.insert(dish);
|
||||
//获取insert语句生成的主键
|
||||
Long dishId = dish.getId();
|
||||
|
||||
//向口味表插入n条数据
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if (flavors != null && flavors.size() > 0) {
|
||||
flavors.forEach(flavor -> {
|
||||
flavor.setDishId(dishId);
|
||||
});
|
||||
//批量插入
|
||||
dishFlavorMapper.insertBath(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品分页查询
|
||||
* @param dishPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
|
||||
PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
|
||||
Page<DishVO> page = dishMapper.pageQuery(dishPageQueryDTO);
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除菜品
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
//1.判断菜品的起售状态,如果起售中提示不能删除
|
||||
ids.forEach(id->{
|
||||
Dish dish = dishMapper.getById(id);
|
||||
//判断售卖状态
|
||||
if(dish.getStatus() == StatusConstant.ENABLE){
|
||||
//起售中,不能删除,抛出业务异常
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
//2.判断当前菜品是否被套餐关联了
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
|
||||
if(setmealIds != null && setmealIds.size() > 0){
|
||||
//菜品被套餐关联了,不能删除,抛出业务异常
|
||||
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||
}
|
||||
|
||||
//遍历菜品id,删除菜品和口味
|
||||
//3.根据菜品id集合批量删除菜品数据
|
||||
//4.根据菜品id集合批量删除关联的口味数据
|
||||
//以下代码可以优化,用一条sql就执行结束
|
||||
/*for (Long dishId : ids) {
|
||||
dishMapper.deleteById(dishId);//根据主键id删除菜品
|
||||
dishFlavorMapper.deleteByDishId(dishId);//根据菜品id删除口味
|
||||
}*/
|
||||
|
||||
//3.根据菜品id集合批量删除菜品数据
|
||||
dishMapper.deleteByIds(ids);
|
||||
//4.根据菜品id集合批量删除关联的口味数据
|
||||
//delete from dish_flavor where dish_id in(?,?,?);
|
||||
dishFlavorMapper.deleteByDishIds(ids);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品和对应的口味数据
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public DishVO getByIdWithFlavor(Long id) {
|
||||
//1.查询2张表:菜品表和口味表
|
||||
//2.根据id查询菜品
|
||||
Dish dish = dishMapper.getById(id);
|
||||
//3.根据菜品id查询关联的口味
|
||||
List<DishFlavor> dishFlavors = dishFlavorMapper.getByDishId(id);
|
||||
|
||||
DishVO dishVO = new DishVO();
|
||||
//对象属性拷贝
|
||||
BeanUtils.copyProperties(dish,dishVO);
|
||||
dishVO.setFlavors(dishFlavors);
|
||||
|
||||
return dishVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id修改菜品基本信息和对应的口味信息
|
||||
* @param dishDTO
|
||||
*/
|
||||
@Override
|
||||
public void updateWithFlavor(DishDTO dishDTO) {
|
||||
//1.影响几张表:2张,分别是菜品表和口味表
|
||||
|
||||
Dish dish = new Dish();
|
||||
BeanUtils.copyProperties(dishDTO,dish);
|
||||
|
||||
//2.修改菜品信息
|
||||
dishMapper.update(dish);
|
||||
|
||||
//3.对于口味表,先执行删除,再重新添加
|
||||
dishFlavorMapper.deleteByDishId(dishDTO.getId());
|
||||
|
||||
//4.重新插入口味数据
|
||||
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||
if(flavors != null && flavors.size() > 0){
|
||||
for (DishFlavor flavor : flavors) {
|
||||
//重新设置菜品id
|
||||
flavor.setDishId(dishDTO.getId());
|
||||
}
|
||||
//批量插入口味数据
|
||||
dishFlavorMapper.insertBath(flavors);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
* @param categoryId
|
||||
* @return
|
||||
*/
|
||||
public List<Dish> list(Long categoryId) {
|
||||
Dish dish = Dish.builder()
|
||||
.categoryId(categoryId)
|
||||
.status(StatusConstant.ENABLE)
|
||||
.build();
|
||||
return dishMapper.list(dish);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 条件查询菜品和口味
|
||||
* @param dish
|
||||
* @return
|
||||
*/
|
||||
public List<DishVO> listWithFlavor(Dish dish) {
|
||||
List<Dish> dishList = dishMapper.list(dish);
|
||||
|
||||
List<DishVO> dishVOList = new ArrayList<>();
|
||||
|
||||
for (Dish d : dishList) {
|
||||
DishVO dishVO = new DishVO();
|
||||
BeanUtils.copyProperties(d,dishVO);
|
||||
|
||||
//根据菜品id查询对应的口味
|
||||
List<DishFlavor> flavors = dishFlavorMapper.getByDishId(d.getId());
|
||||
|
||||
dishVO.setFlavors(flavors);
|
||||
dishVOList.add(dishVO);
|
||||
}
|
||||
|
||||
return dishVOList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品起售停售
|
||||
*
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
@Transactional
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
Dish dish = Dish.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
dishMapper.update(dish);
|
||||
|
||||
if (status == StatusConstant.DISABLE) {
|
||||
// 如果是停售操作,还需要将包含当前菜品的套餐也停售
|
||||
List<Long> dishIds = new ArrayList<>();
|
||||
dishIds.add(id);
|
||||
// select setmeal_id from setmeal_dish where dish_id in (?,?,?)
|
||||
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(dishIds);
|
||||
if (setmealIds != null && setmealIds.size() > 0) {
|
||||
for (Long setmealId : setmealIds) {
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(setmealId)
|
||||
.status(StatusConstant.DISABLE)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,29 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.PasswordConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.EmployeeDTO;
|
||||
import com.sky.dto.EmployeeLoginDTO;
|
||||
import com.sky.dto.EmployeePageQueryDTO;
|
||||
import com.sky.entity.Employee;
|
||||
import com.sky.exception.AccountLockedException;
|
||||
import com.sky.exception.AccountNotFoundException;
|
||||
import com.sky.exception.PasswordErrorException;
|
||||
import com.sky.mapper.EmployeeMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.EmployeeService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class EmployeeServiceImpl implements EmployeeService {
|
||||
|
||||
@@ -39,7 +50,8 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
}
|
||||
|
||||
//密码比对
|
||||
// TODO 后期需要进行md5加密,然后再进行比对
|
||||
// 后期需要进行md5加密,然后再进行比对
|
||||
password = DigestUtils.md5DigestAsHex(password.getBytes());
|
||||
if (!password.equals(employee.getPassword())) {
|
||||
//密码错误
|
||||
throw new PasswordErrorException(MessageConstant.PASSWORD_ERROR);
|
||||
@@ -54,4 +66,86 @@ public class EmployeeServiceImpl implements EmployeeService {
|
||||
return employee;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void save(EmployeeDTO employeeDTO) {
|
||||
System.out.println("当前线程的id:"+Thread.currentThread().getId());
|
||||
Employee employee = new Employee();
|
||||
//对象属性拷贝
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
//设置账号的状态,默认正常状态 1:正常 0 表示锁定
|
||||
employee.setStatus(StatusConstant.ENABLE);
|
||||
//设置默认密码
|
||||
employee.setPassword(DigestUtils.md5DigestAsHex(PasswordConstant.DEFAULT_PASSWORD.getBytes()));
|
||||
//设置创建时间和修改时间
|
||||
employee.setCreateTime(LocalDateTime.now());
|
||||
employee.setUpdateTime(LocalDateTime.now());
|
||||
//设置当前记录创建人id和修改人的id
|
||||
//后期需要改为当前登录用户的id
|
||||
// employee.setCreateUser(BaseContext.getCurrentId());
|
||||
// employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
|
||||
employeeMapper.insert(employee);
|
||||
}
|
||||
|
||||
/*
|
||||
员工分页查询
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(EmployeePageQueryDTO employeePageQueryDTO) {
|
||||
//select * from employee limit 0,10;
|
||||
//开始分页查询
|
||||
PageHelper.startPage(employeePageQueryDTO.getPage(), employeePageQueryDTO.getPageSize());
|
||||
Page<Employee> page = employeeMapper.pageQuery(employeePageQueryDTO);
|
||||
long total = page.getTotal();
|
||||
List<Employee> records = page.getResult();
|
||||
return new PageResult(total, records);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启用禁用员工账号
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
@Override
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
//update employee set status = ? where id = ?
|
||||
//写法1:普通写法
|
||||
/*Employee employee = new Employee();
|
||||
employee.setId(id);
|
||||
employee.setStatus(status);*/
|
||||
//写法2:构建器方式创建实体对象
|
||||
Employee employee = Employee.builder().status(status).id(id).build();
|
||||
//应该动态更新,如果要更新其他参数,写死参数不方便扩展,所以传员工实体类
|
||||
employeeMapper.update(employee);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询员工
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Employee getById(Long id) {
|
||||
Employee employee = employeeMapper.getById(id);
|
||||
employee.setPassword("****");
|
||||
return employee;
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑员工信息
|
||||
* @param employeeDTO
|
||||
*/
|
||||
@Override
|
||||
public void update(EmployeeDTO employeeDTO) {
|
||||
Employee employee = new Employee();
|
||||
//对象的属性拷贝
|
||||
BeanUtils.copyProperties(employeeDTO, employee);
|
||||
//补充其他属性
|
||||
// employee.setUpdateTime(LocalDateTime.now());
|
||||
// employee.setUpdateUser(BaseContext.getCurrentId());
|
||||
employeeMapper.update(employee);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.OrdersSubmitDTO;
|
||||
import com.sky.entity.AddressBook;
|
||||
import com.sky.entity.OrderDetail;
|
||||
import com.sky.entity.Orders;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.exception.AddressBookBusinessException;
|
||||
import com.sky.exception.ShoppingCartBusinessException;
|
||||
import com.sky.mapper.*;
|
||||
import com.sky.service.OrderService;
|
||||
import com.sky.vo.OrderSubmitVO;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
private ShoppingCartMapper shoppingCartMapper;
|
||||
@Autowired
|
||||
private AddressBookMapper addressBookMapper;
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private OrderDetailMapper orderDetailMapper;
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
|
||||
/**
|
||||
* 用户下单
|
||||
* @param ordersSubmitDTO
|
||||
* @return
|
||||
*/
|
||||
@Transactional
|
||||
public OrderSubmitVO submit(OrdersSubmitDTO ordersSubmitDTO) {
|
||||
//1.处理各种业务异常(地址簿为空,购物车数据为空)
|
||||
AddressBook addressBook = addressBookMapper.getById(ordersSubmitDTO.getAddressBookId());
|
||||
if (addressBook == null) {
|
||||
//抛出地址簿为空业务异常
|
||||
throw new AddressBookBusinessException(MessageConstant.ADDRESS_BOOK_IS_NULL);
|
||||
}
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
ShoppingCart cart = new ShoppingCart();
|
||||
cart.setUserId(userId);
|
||||
List<ShoppingCart> cartList = shoppingCartMapper.list(cart);
|
||||
if (cartList == null || cartList.size() == 0) {
|
||||
//抛出购物车数据为空业务异常
|
||||
throw new ShoppingCartBusinessException(MessageConstant.SHOPPING_CART_IS_NULL);
|
||||
}
|
||||
|
||||
|
||||
//2.向订单表插入一条数据
|
||||
Orders orders = new Orders();
|
||||
BeanUtils.copyProperties(ordersSubmitDTO,orders);
|
||||
orders.setOrderTime(LocalDateTime.now());//下单时间
|
||||
orders.setPayStatus(Orders.UN_PAID);//未支付
|
||||
orders.setStatus(Orders.PENDING_PAYMENT);//待付款
|
||||
orders.setNumber(String.valueOf(System.currentTimeMillis()));//订单号
|
||||
orders.setPhone(addressBook.getPhone());
|
||||
orders.setConsignee(addressBook.getConsignee());//收货人
|
||||
orders.setUserId(userId);
|
||||
orders.setAddress(addressBook.getProvinceName()+addressBook.getCityName()+addressBook.getDistrictName()+addressBook.getDetail());
|
||||
|
||||
|
||||
orderMapper.insert(orders);
|
||||
//3.向订单明细表插入n条数据
|
||||
List<OrderDetail> orderDetailList = new ArrayList<>();
|
||||
for (ShoppingCart shoppingCart : cartList) {
|
||||
OrderDetail orderDetail = new OrderDetail();//订单明细
|
||||
BeanUtils.copyProperties(shoppingCart,orderDetail);
|
||||
orderDetail.setOrderId(orders.getId());//设置当前订单明细关联的订单id
|
||||
orderDetailList.add(orderDetail);
|
||||
}
|
||||
orderDetailMapper.insertBatch(orderDetailList);
|
||||
|
||||
//4.清空当前用户的购物车数据
|
||||
shoppingCartMapper.deleteByUserId(userId);
|
||||
//5.封装VO返回结果
|
||||
OrderSubmitVO orderSubmitVO = OrderSubmitVO.builder()
|
||||
.id(orders.getId())
|
||||
.orderNumber(orders.getNumber())
|
||||
.orderTime(orders.getOrderTime())
|
||||
.orderAmount(orders.getAmount())
|
||||
.build();
|
||||
return orderSubmitVO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.github.pagehelper.Page;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.dto.SetmealDTO;
|
||||
import com.sky.dto.SetmealPageQueryDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.SetmealDish;
|
||||
import com.sky.exception.DeletionNotAllowedException;
|
||||
import com.sky.exception.SetmealEnableFailedException;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealDishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.result.PageResult;
|
||||
import com.sky.service.SetmealService;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 套餐业务实现
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SetmealServiceImpl implements SetmealService {
|
||||
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
@Autowired
|
||||
private SetmealDishMapper setmealDishMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
|
||||
/**
|
||||
* 新增套餐,同时需要保存套餐和菜品的关联关系
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Transactional
|
||||
public void saveWithDish(SetmealDTO setmealDTO) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//向套餐表插入数据
|
||||
setmealMapper.insert(setmeal);
|
||||
|
||||
//获取生成的套餐id
|
||||
Long setmealId = setmeal.getId();
|
||||
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishes.forEach(setmealDish -> {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
});
|
||||
|
||||
//保存套餐和菜品的关联关系
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param setmealPageQueryDTO
|
||||
* @return
|
||||
*/
|
||||
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
int pageNum = setmealPageQueryDTO.getPage();
|
||||
int pageSize = setmealPageQueryDTO.getPageSize();
|
||||
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
Page<SetmealVO> page = setmealMapper.pageQuery(setmealPageQueryDTO);
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
* @param ids
|
||||
*/
|
||||
@Transactional
|
||||
public void deleteBatch(List<Long> ids) {
|
||||
ids.forEach(id -> {
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
if(StatusConstant.ENABLE == setmeal.getStatus()){
|
||||
//起售中的套餐不能删除
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
ids.forEach(setmealId -> {
|
||||
//删除套餐表中的数据
|
||||
setmealMapper.deleteById(setmealId);
|
||||
//删除套餐菜品关系表中的数据
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐和套餐菜品关系
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public SetmealVO getByIdWithDish(Long id) {
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
List<SetmealDish> setmealDishes = setmealDishMapper.getBySetmealId(id);
|
||||
|
||||
SetmealVO setmealVO = new SetmealVO();
|
||||
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||
setmealVO.setSetmealDishes(setmealDishes);
|
||||
|
||||
return setmealVO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
*
|
||||
* @param setmealDTO
|
||||
*/
|
||||
@Transactional
|
||||
public void update(SetmealDTO setmealDTO) {
|
||||
Setmeal setmeal = new Setmeal();
|
||||
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||
|
||||
//1、修改套餐表,执行update
|
||||
setmealMapper.update(setmeal);
|
||||
|
||||
//套餐id
|
||||
Long setmealId = setmealDTO.getId();
|
||||
|
||||
//2、删除套餐和菜品的关联关系,操作setmeal_dish表,执行delete
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
|
||||
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||
setmealDishes.forEach(setmealDish -> {
|
||||
setmealDish.setSetmealId(setmealId);
|
||||
});
|
||||
//3、重新插入套餐和菜品的关联关系,操作setmeal_dish表,执行insert
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 套餐起售、停售
|
||||
* @param status
|
||||
* @param id
|
||||
*/
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
//起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||
if(status == StatusConstant.ENABLE){
|
||||
//select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = ?
|
||||
List<Dish> dishList = dishMapper.getBySetmealId(id);
|
||||
if(dishList != null && dishList.size() > 0){
|
||||
dishList.forEach(dish -> {
|
||||
if(StatusConstant.DISABLE == dish.getStatus()){
|
||||
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Setmeal setmeal = Setmeal.builder()
|
||||
.id(id)
|
||||
.status(status)
|
||||
.build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param setmeal
|
||||
* @return
|
||||
*/
|
||||
public List<Setmeal> list(Setmeal setmeal) {
|
||||
List<Setmeal> list = setmealMapper.list(setmeal);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询菜品选项
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public List<DishItemVO> getDishItemById(Long id) {
|
||||
return setmealMapper.getDishItemBySetmealId(id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.sky.context.BaseContext;
|
||||
import com.sky.dto.ShoppingCartDTO;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.entity.Setmeal;
|
||||
import com.sky.entity.ShoppingCart;
|
||||
import com.sky.mapper.DishMapper;
|
||||
import com.sky.mapper.SetmealMapper;
|
||||
import com.sky.mapper.ShoppingCartMapper;
|
||||
import com.sky.service.ShoppingCartService;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ShoppingCartServiceImpl implements ShoppingCartService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ShoppingCartMapper shoppingCartMapper;
|
||||
@Autowired
|
||||
private DishMapper dishMapper;
|
||||
@Autowired
|
||||
private SetmealMapper setmealMapper;
|
||||
|
||||
/**
|
||||
* 添加购物车
|
||||
* @param shoppingCartDTO
|
||||
*/
|
||||
public void addShoppingCart(ShoppingCartDTO shoppingCartDTO) {
|
||||
ShoppingCart shoppingCart = new ShoppingCart();
|
||||
BeanUtils.copyProperties(shoppingCartDTO,shoppingCart);
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
|
||||
//1、判断当前购物车中是否存在该商品(有可能是菜品,也可能是套餐)----只能查询自己购物车中的商品 where user_id = ?
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(shoppingCart);
|
||||
|
||||
//2、如果已经存在,则数量 + 1(因为添加购物车时,是直接添加一个菜品或者套餐,所以如果存在直接+1即可)
|
||||
if(list != null && list.size() > 0){
|
||||
ShoppingCart cart = list.get(0);
|
||||
cart.setNumber(cart.getNumber()+1);
|
||||
//update shopping_cart set number = ? where id = ?
|
||||
shoppingCartMapper.updateNumberById(cart);
|
||||
}else{
|
||||
//3、如果不存在,向购物车表插入1条数据
|
||||
// insert into shopping_cart(...) values(...)
|
||||
//判断本次添加的商品是菜品还是套餐
|
||||
if(shoppingCartDTO.getDishId() != null){
|
||||
//本次添加的是菜品,查询菜品表,获取菜品的名称、图片路径、单价
|
||||
Dish dish = dishMapper.getById(shoppingCartDTO.getDishId());
|
||||
//封装购物车对象
|
||||
shoppingCart = ShoppingCart.builder()
|
||||
.dishId(shoppingCartDTO.getDishId())
|
||||
.name(dish.getName())
|
||||
.image(dish.getImage())
|
||||
.dishFlavor(shoppingCartDTO.getDishFlavor())
|
||||
.amount(dish.getPrice())
|
||||
.build();
|
||||
}else {
|
||||
//本次添加的是套餐,查询套餐表,获取套餐的名称、图片路径、单价
|
||||
Setmeal setmeal = setmealMapper.getById(shoppingCartDTO.getSetmealId());
|
||||
//封装购物车对象
|
||||
shoppingCart = ShoppingCart.builder()
|
||||
.setmealId(shoppingCartDTO.getSetmealId())
|
||||
.name(setmeal.getName())
|
||||
.image(setmeal.getImage())
|
||||
.amount(setmeal.getPrice())
|
||||
.build();
|
||||
}
|
||||
shoppingCart.setUserId(BaseContext.getCurrentId());
|
||||
shoppingCart.setNumber(1);
|
||||
shoppingCart.setCreateTime(LocalDateTime.now());
|
||||
shoppingCartMapper.insert(shoppingCart);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 查看购物车
|
||||
* @return
|
||||
*/
|
||||
public List<ShoppingCart> showShoppingCart() {
|
||||
//select * from shopping_cart where user_id = ?
|
||||
Long userId = BaseContext.getCurrentId();
|
||||
ShoppingCart cart = ShoppingCart.builder()
|
||||
.userId(userId)
|
||||
.build();
|
||||
|
||||
List<ShoppingCart> list = shoppingCartMapper.list(cart);
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空购物车
|
||||
*/
|
||||
public void cleanShoppingCart() {//方法名体现的是业务功能
|
||||
// delete from shopping_cart where user_id = ?
|
||||
shoppingCartMapper.deleteByUserId(BaseContext.getCurrentId());//体现的是数据库操作
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.sky.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.sky.constant.MessageConstant;
|
||||
import com.sky.dto.UserLoginDTO;
|
||||
import com.sky.entity.User;
|
||||
import com.sky.exception.LoginFailedException;
|
||||
import com.sky.mapper.UserMapper;
|
||||
import com.sky.properties.WeChatProperties;
|
||||
import com.sky.service.UserService;
|
||||
import com.sky.utils.HttpClientUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
//微信服务接口地址
|
||||
public static final String WX_LOGIN = "https://api.weixin.qq.com/sns/jscode2session";
|
||||
|
||||
@Autowired
|
||||
private WeChatProperties weChatProperties;
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
/**
|
||||
* 微信登录
|
||||
* @param userLoginDTO
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public User wxLogin(UserLoginDTO userLoginDTO) {
|
||||
//1.调用微信接口服务,获取当前微信用户端openid
|
||||
String openid = getOpenid(userLoginDTO.getCode());
|
||||
|
||||
//2.判断openid是否是空,如果为空,表示登录失败,抛出业务异常
|
||||
if (openid == null) {
|
||||
throw new LoginFailedException(MessageConstant.LOGIN_FAILED);
|
||||
}
|
||||
//3.判断当前用户是否为新用户
|
||||
User user = userMapper.getByOpenid(openid);
|
||||
//4.如果是新用户,自动完成注册
|
||||
if (user == null) {
|
||||
user = User.builder()
|
||||
.openid(openid)
|
||||
.createTime(LocalDateTime.now())
|
||||
.build();
|
||||
userMapper.insert(user);
|
||||
}
|
||||
//返回用户对象
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
//调用微信接口服务,获取当前微信用户端openid
|
||||
private String getOpenid(String code){
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("appid", weChatProperties.getAppid());
|
||||
map.put("secret", weChatProperties.getSecret());
|
||||
map.put("js_code", code);
|
||||
map.put("grant_type", " authorization_code");
|
||||
String json = HttpClientUtil.doGet(WX_LOGIN, map);
|
||||
|
||||
JSONObject jsonObject = JSON.parseObject(json);
|
||||
String openid = jsonObject.getString("openid");
|
||||
return openid;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,18 @@ sky:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
host: localhost
|
||||
port: 3306
|
||||
database: sky_take_out
|
||||
database: sky_take_out1
|
||||
username: root
|
||||
password: 1234
|
||||
alioss:
|
||||
endpoint: https://oss-cn-shanghai.aliyuncs.com
|
||||
bucket-name: inmind-test
|
||||
region: cn-shanghai
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
password: 123456
|
||||
database: 10 #不配置的话,默认是0号数据库
|
||||
wechat:
|
||||
appid: wx3a8ed8d8e9c9552a
|
||||
secret: 8ada060abc5326be3a446a75df4c77b3
|
||||
|
||||
@@ -12,6 +12,14 @@ spring:
|
||||
url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: ${sky.datasource.username}
|
||||
password: ${sky.datasource.password}
|
||||
mvc:
|
||||
pathmatch:
|
||||
matching-strategy: ant_path_matcher #swagger配置兼容Springboot
|
||||
redis:
|
||||
host: ${sky.redis.host}
|
||||
port: ${sky.redis.port}
|
||||
# password: ${sky.redis.password}
|
||||
database: ${sky.redis.database} #不配置的话,默认是0号数据库
|
||||
|
||||
mybatis:
|
||||
#mapper配置文件
|
||||
@@ -20,6 +28,8 @@ mybatis:
|
||||
configuration:
|
||||
#开启驼峰命名
|
||||
map-underscore-to-camel-case: true
|
||||
#输出mybatis的日志
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
logging:
|
||||
level:
|
||||
@@ -34,6 +44,16 @@ sky:
|
||||
# 设置jwt签名加密时使用的秘钥
|
||||
admin-secret-key: inmind
|
||||
# 设置jwt过期时间
|
||||
admin-ttl: 7200000
|
||||
admin-ttl: 86400000
|
||||
# 设置前端传递过来的令牌名称
|
||||
admin-token-name: token
|
||||
user-secret-key: inmind
|
||||
user-ttl: 3600000
|
||||
user-token-name: authentication
|
||||
alioss:
|
||||
endpoint: ${sky.alioss.endpoint}
|
||||
bucket-name: ${sky.alioss.bucket-name}
|
||||
region: ${sky.alioss.region}
|
||||
wechat:
|
||||
appid: ${sky.wechat.appid}
|
||||
secret: ${sky.wechat.secret}
|
||||
|
||||
45
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
45
sky-server/src/main/resources/mapper/AddressBookMapper.xml
Normal file
@@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.AddressBookMapper">
|
||||
|
||||
<select id="list" parameterType="AddressBook" resultType="AddressBook">
|
||||
select * from address_book
|
||||
<where>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
and phone = #{phone}
|
||||
</if>
|
||||
<if test="isDefault != null">
|
||||
and is_default = #{isDefault}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<update id="update" parameterType="addressBook">
|
||||
update address_book
|
||||
<set>
|
||||
<if test="consignee != null">
|
||||
consignee = #{consignee},
|
||||
</if>
|
||||
<if test="sex != null">
|
||||
sex = #{sex},
|
||||
</if>
|
||||
<if test="phone != null">
|
||||
phone = #{phone},
|
||||
</if>
|
||||
<if test="detail != null">
|
||||
detail = #{detail},
|
||||
</if>
|
||||
<if test="label != null">
|
||||
label = #{label},
|
||||
</if>
|
||||
<if test="isDefault != null">
|
||||
is_default = #{isDefault},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
52
sky-server/src/main/resources/mapper/CategoryMapper.xml
Normal file
52
sky-server/src/main/resources/mapper/CategoryMapper.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.CategoryMapper">
|
||||
|
||||
<select id="pageQuery" resultType="com.sky.entity.Category">
|
||||
select * from category
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
and name like concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="type != null">
|
||||
and type = #{type}
|
||||
</if>
|
||||
</where>
|
||||
order by sort asc , create_time desc
|
||||
</select>
|
||||
|
||||
<update id="update" parameterType="Category">
|
||||
update category
|
||||
<set>
|
||||
<if test="type != null">
|
||||
type = #{type},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="sort != null">
|
||||
sort = #{sort},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="updateUser != null">
|
||||
update_user = #{updateUser}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="list" resultType="Category">
|
||||
select * from category
|
||||
where status = 1
|
||||
<if test="type != null">
|
||||
and type = #{type}
|
||||
</if>
|
||||
order by sort asc,create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
19
sky-server/src/main/resources/mapper/DishFlavorMapper.xml
Normal file
19
sky-server/src/main/resources/mapper/DishFlavorMapper.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.DishFlavorMapper">
|
||||
|
||||
<insert id="insertBath">
|
||||
insert into dish_flavor(dish_id, name, value)
|
||||
values
|
||||
<foreach collection="flavors" item="df" separator=",">
|
||||
(#{df.dishId},#{df.name},#{df.value})
|
||||
</foreach>
|
||||
</insert>
|
||||
<delete id="deleteByDishIds">
|
||||
delete from dish_flavor where dish_id in
|
||||
<foreach collection="dishIds" item="dishId" open="(" close=")" separator=",">
|
||||
#{dishId}
|
||||
</foreach>
|
||||
</delete>
|
||||
</mapper>
|
||||
65
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
65
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.DishMapper">
|
||||
<!--
|
||||
useGeneratedKeys="true"表示获取主键的值
|
||||
keyProperty="id"表示将主键值赋值给id属性
|
||||
-->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user,status)
|
||||
values (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
|
||||
</insert>
|
||||
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||
select d.*,c.name as categoryName from dish d left join category c on d.category_id = c.id
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
and d.name like concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and d.category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and d.status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
order by d.create_time desc
|
||||
</select>
|
||||
|
||||
<delete id="deleteByIds">
|
||||
delete from dish where id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="id">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<update id="update">
|
||||
update dish
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||
<if test="price != null">price = #{price},</if>
|
||||
<if test="image != null">image = #{image},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="updateUser != null">update_user = #{updateUser},</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="list" resultType="Dish" parameterType="Dish">
|
||||
select * from dish
|
||||
<where>
|
||||
<if test="name != null">
|
||||
and name like concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -2,4 +2,31 @@
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.EmployeeMapper">
|
||||
<select id="pageQuery" resultType="com.sky.entity.Employee">
|
||||
select * from employee
|
||||
<where>
|
||||
<if test="name != null and name != ''">
|
||||
and name like concat('%',#{name},"%")
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<update id="update" parameterType="com.sky.entity.Employee">
|
||||
update employee
|
||||
<set>
|
||||
<if test="name != null and name !=''"> name = #{name},</if>
|
||||
<if test="username != null and username !=''"> username = #{username},</if>
|
||||
<if test="password != null and password !=''"> password = #{password},</if>
|
||||
<if test="phone != null and phone !=''"> phone = #{phone},</if>
|
||||
<if test="sex != null and sex !=''"> sex = #{sex},</if>
|
||||
<if test="idNumber != null and idNumber !=''"> id_number = #{idNumber},</if>
|
||||
<if test="status != null "> status = #{status},</if>
|
||||
<if test="createTime != null "> create_time = #{createTime},</if>
|
||||
<if test="updateTime != null "> update_time = #{updateTime},</if>
|
||||
<if test="createUser != null "> create_user = #{createUser},</if>
|
||||
<if test="updateUser != null "> update_user = #{updateUser},</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
</mapper>
|
||||
|
||||
10
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
10
sky-server/src/main/resources/mapper/OrderDetailMapper.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.OrderDetailMapper">
|
||||
<insert id="insertBatch" parameterType="java.util.List">
|
||||
insert into order_detail (name, image, order_id, dish_id, setmeal_id, dish_flavor, number, amount) VALUES
|
||||
<foreach collection="orderDetailList" separator="," item="od">
|
||||
(#{od.name},#{od.image},#{od.orderId},#{od.dishId},#{od.setmealId},#{od.dishFlavor},#{od.number},#{od.amount})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
20
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
20
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.SetmealDishMapper">
|
||||
|
||||
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||
select setmeal_id from setmeal_dish where dish_id in
|
||||
<foreach collection="ids" open="(" close=")" separator="," item="dishId">
|
||||
#{dishId}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insertBatch">
|
||||
insert into setmeal_dish (setmeal_id,dish_id,name,price,copies)
|
||||
values
|
||||
<foreach collection="setmealDishes" item="sd" separator=",">
|
||||
(#{sd.setmealId},#{sd.dishId},#{sd.name},#{sd.price},#{sd.copies})
|
||||
</foreach>
|
||||
</insert>
|
||||
</mapper>
|
||||
93
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
93
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@@ -0,0 +1,93 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.SetmealMapper">
|
||||
<update id="update">
|
||||
update setmeal
|
||||
<set>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
category_id = #{categoryId},
|
||||
</if>
|
||||
<if test="price != null">
|
||||
price = #{price},
|
||||
</if>
|
||||
<if test="status != null">
|
||||
status = #{status},
|
||||
</if>
|
||||
<if test="description != null">
|
||||
description = #{description},
|
||||
</if>
|
||||
<if test="image != null">
|
||||
image = #{image},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="updateUser != null">
|
||||
update_user = #{updateUser}
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into setmeal
|
||||
(category_id, name, price, status, description, image, create_time, update_time, create_user, update_user)
|
||||
values (#{categoryId}, #{name}, #{price}, #{status}, #{description}, #{image}, #{createTime}, #{updateTime},
|
||||
#{createUser}, #{updateUser})
|
||||
</insert>
|
||||
|
||||
<select id="pageQuery" resultType="com.sky.vo.SetmealVO">
|
||||
select
|
||||
s.*,c.name categoryName
|
||||
from
|
||||
setmeal s
|
||||
left join
|
||||
category c
|
||||
on
|
||||
s.category_id = c.id
|
||||
<where>
|
||||
<if test="name != null">
|
||||
and s.name like concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and s.status = #{status}
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and s.category_id = #{categoryId}
|
||||
</if>
|
||||
</where>
|
||||
order by s.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="list" parameterType="Setmeal" resultType="Setmeal">
|
||||
select * from setmeal
|
||||
<where>
|
||||
<if test="name != null">
|
||||
and name like concat('%',#{name},'%')
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and category_id = #{categoryId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="countByMap" resultType="java.lang.Integer">
|
||||
select count(id) from setmeal
|
||||
<where>
|
||||
<if test="status != null">
|
||||
and status = #{status}
|
||||
</if>
|
||||
<if test="categoryId != null">
|
||||
and category_id = #{categoryId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
21
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
21
sky-server/src/main/resources/mapper/ShoppingCartMapper.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.ShoppingCartMapper">
|
||||
<select id="list" resultType="com.sky.entity.ShoppingCart">
|
||||
select * from shopping_cart
|
||||
<where>
|
||||
<if test="dishId != null">
|
||||
and dish_id = #{dishId}
|
||||
</if>
|
||||
<if test="dishFlavor != null">
|
||||
and dish_flavor = #{dishFlavor}
|
||||
</if>
|
||||
<if test="setmealId != null">
|
||||
and setmeal_id = #{setmealId}
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
and user_id = #{userId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
14
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
14
sky-server/src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.sky.mapper.UserMapper">
|
||||
<!--
|
||||
useGeneratedKeys="true"表示获取主键的值
|
||||
keyProperty="id"表示将主键值赋值给id属性
|
||||
-->
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into user (openid, name, phone, sex, id_number, avatar, create_time)
|
||||
values (#{openid},#{name},#{phone},#{sex},#{idNumber},#{avatar},#{createTime})
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user