Compare commits
10 Commits
b7a4d3ecbd
...
5334ef8454
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5334ef8454 | ||
|
|
ac346a870c | ||
|
|
add28bfa5d | ||
|
|
1e2aec636a | ||
|
|
a65c9e0c69 | ||
|
|
e223fbb1a8 | ||
|
|
5419e321c8 | ||
|
|
22e629b6e1 | ||
|
|
b6c3de2165 | ||
|
|
77804a0aba |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -3,4 +3,5 @@
|
|||||||
*.iml
|
*.iml
|
||||||
*.class
|
*.class
|
||||||
*Test.java
|
*Test.java
|
||||||
**/test/
|
**/test/
|
||||||
|
resources/application-dev.properties
|
||||||
@@ -6,7 +6,6 @@ import com.sky.context.BaseContext;
|
|||||||
import com.sky.enumeration.OperationType;
|
import com.sky.enumeration.OperationType;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
import org.aspectj.lang.Signature;
|
|
||||||
import org.aspectj.lang.annotation.Aspect;
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
import org.aspectj.lang.annotation.Before;
|
import org.aspectj.lang.annotation.Before;
|
||||||
import org.aspectj.lang.annotation.Pointcut;
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.sky.utils.AliOssUtil;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Conditional;
|
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@Slf4j
|
||||||
|
public class RedisConfiguration {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||||
|
log.info("开始创建Redis模板对象");
|
||||||
|
RedisTemplate redisTemplate = new RedisTemplate<>();
|
||||||
|
//设置连接工厂对象
|
||||||
|
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||||
|
//设置序列化器
|
||||||
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||||
|
return redisTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.http.converter.HttpMessageConverter;
|
import org.springframework.http.converter.HttpMessageConverter;
|
||||||
import org.springframework.http.converter.cbor.MappingJackson2CborHttpMessageConverter;
|
|
||||||
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
||||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||||
@@ -48,8 +47,8 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public Docket docket() {
|
public Docket docketAdmin() {
|
||||||
log.info("准备生成接口文档...");
|
log.info("准备生成Admin接口文档...");
|
||||||
ApiInfo apiInfo = new ApiInfoBuilder()
|
ApiInfo apiInfo = new ApiInfoBuilder()
|
||||||
.title("苍穹外卖项目接口文档")
|
.title("苍穹外卖项目接口文档")
|
||||||
.version("2.0")
|
.version("2.0")
|
||||||
@@ -57,16 +56,36 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||||||
.build();
|
.build();
|
||||||
//指定版本
|
//指定版本
|
||||||
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
Docket docket = new Docket(DocumentationType.SWAGGER_2)
|
||||||
|
.groupName("管理端接口")
|
||||||
//上文设置的信息
|
//上文设置的信息
|
||||||
.apiInfo(apiInfo)
|
.apiInfo(apiInfo)
|
||||||
.select()
|
.select()
|
||||||
//指定生成接口需要扫描的包
|
//指定生成接口需要扫描的包
|
||||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
|
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||||
|
.paths(PathSelectors.any())
|
||||||
|
.build();
|
||||||
|
return docket;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public Docket docketUser() {
|
||||||
|
log.info("准备生成User接口文档...");
|
||||||
|
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())
|
.paths(PathSelectors.any())
|
||||||
.build();
|
.build();
|
||||||
return docket;
|
return docket;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置静态资源映射
|
* 设置静态资源映射
|
||||||
* @param registry
|
* @param registry
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.sky.controller.admin;
|
package com.sky.controller.admin;
|
||||||
|
|
||||||
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.result.Result;
|
import com.sky.result.Result;
|
||||||
import com.sky.utils.AliOssUtil;
|
import com.sky.utils.AliOssUtil;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@@ -7,7 +8,6 @@ import io.swagger.annotations.ApiOperation;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -43,7 +43,7 @@ public class CommonController {
|
|||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("文件上传失败: " + e);
|
log.error("文件上传失败: " + e);
|
||||||
}
|
}
|
||||||
return null;
|
return Result.error(MessageConstant.UPLOAD_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
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.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/dish")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "菜品相关接口")
|
||||||
|
public class DishController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DishService dishService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
*
|
||||||
|
* @param dishDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增菜品")
|
||||||
|
public Result save(@RequestBody DishDTO dishDTO) {
|
||||||
|
log.info("新增菜品: {}", dishDTO);
|
||||||
|
dishService.saveWithFlavor(dishDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
*
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("菜品分页查询")
|
||||||
|
public Result<PageResult> page(DishPageQueryDTO pageQueryDTO) {
|
||||||
|
log.info("菜品分页查询: {}", pageQueryDTO);
|
||||||
|
PageResult pageResult = dishService.pageQuery(pageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除菜品
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("批量删除菜品")
|
||||||
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
|
log.info("批量删除菜品: {}",ids);
|
||||||
|
dishService.deleteBatch(ids);
|
||||||
|
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);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
@ApiOperation("根据分类id查询菜品")
|
||||||
|
public Result<List> list(Long categoryId){
|
||||||
|
log.info("根据分类id查询菜品: {}",categoryId);
|
||||||
|
List<Dish> dishes = dishService.selectByCategoryId(categoryId);
|
||||||
|
return Result.success(dishes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("菜品起售停售")
|
||||||
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
|
log.info("菜品起售停售: 状态:{},ID:{}",status,id);
|
||||||
|
dishService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
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.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/setmeal")
|
||||||
|
@Slf4j
|
||||||
|
@Api(tags = "套餐相关接口")
|
||||||
|
public class SetmealController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SetmealService setmealService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/page")
|
||||||
|
@ApiOperation("套餐分页查询")
|
||||||
|
public Result<PageResult> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO){
|
||||||
|
log.info("套餐分页查询: {}",setmealPageQueryDTO);
|
||||||
|
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||||
|
return Result.success(pageResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping
|
||||||
|
@ApiOperation("新增套餐")
|
||||||
|
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||||
|
log.info("新增套餐: {}",setmealDTO);
|
||||||
|
setmealService.insert(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@DeleteMapping
|
||||||
|
@ApiOperation("批量删除套餐")
|
||||||
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
|
log.info("批量删除套餐: {}",ids);
|
||||||
|
setmealService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
@ApiOperation("根据id查询套餐")
|
||||||
|
public Result<SetmealVO> getById(@PathVariable Long id){
|
||||||
|
log.info("根据id查询套餐: {}",id);
|
||||||
|
SetmealVO setmealVO = setmealService.getByIdWithSetmealDishes(id);
|
||||||
|
return Result.success(setmealVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PutMapping
|
||||||
|
@ApiOperation("修改套餐")
|
||||||
|
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||||
|
log.info("修改套餐: {}",setmealDTO);
|
||||||
|
setmealService.updateWithSetmealDishes(setmealDTO);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/status/{status}")
|
||||||
|
@ApiOperation("套餐起售停售")
|
||||||
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
|
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
||||||
|
setmealService.startOrStop(status,id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@RestController("adminShopController")
|
||||||
|
@RequestMapping("/admin/shop")
|
||||||
|
@Api(tags = "店铺操作接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
private static final String KEY = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@PutMapping("/{status}")
|
||||||
|
@ApiOperation("设置营业状态")
|
||||||
|
public Result setStatus(@PathVariable String status) {
|
||||||
|
log.info("设置店铺营业状态为: {}",status.equals("1") ? "营业中":"打烊中");
|
||||||
|
redisTemplate.opsForValue().set(KEY, status);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||||
|
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
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.*;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
@RestController("userShopController")
|
||||||
|
@RequestMapping("/admin/user")
|
||||||
|
@Api(tags = "店铺操作接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
|
||||||
|
private static final String KEY = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@GetMapping("/status")
|
||||||
|
@ApiOperation("获取营业状态")
|
||||||
|
public Result<Integer> getStatus(){
|
||||||
|
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||||
|
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||||
|
return Result.success(status);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.method.HandlerMethod;
|
import org.springframework.web.method.HandlerMethod;
|
||||||
import org.springframework.web.servlet.HandlerInterceptor;
|
import org.springframework.web.servlet.HandlerInterceptor;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
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 {
|
||||||
|
/**
|
||||||
|
* 批量插入口味数据
|
||||||
|
* @param flavors
|
||||||
|
*/
|
||||||
|
void insertBatch(List<DishFlavor> flavors);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品ID删除对应的口味
|
||||||
|
* @param dishId
|
||||||
|
*/
|
||||||
|
@Delete("delete from dish_flavor where dish_id = #{dishId}")
|
||||||
|
void deleteByDishId(Long dishId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品id集合批量删除口味数据
|
||||||
|
* @param dishIds
|
||||||
|
*/
|
||||||
|
void deleteByDishIds(List<Long> dishIds);
|
||||||
|
|
||||||
|
@Select("select * from dish_flavor where dish_id = #{dishId}")
|
||||||
|
List<DishFlavor> getByDishId(Long dishId);
|
||||||
|
}
|
||||||
@@ -1,8 +1,17 @@
|
|||||||
package com.sky.mapper;
|
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.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface DishMapper {
|
public interface DishMapper {
|
||||||
|
|
||||||
@@ -14,4 +23,51 @@ public interface DishMapper {
|
|||||||
@Select("select count(id) from dish where category_id = #{categoryId}")
|
@Select("select count(id) from dish where category_id = #{categoryId}")
|
||||||
Integer countByCategoryId(Long categoryId);
|
Integer countByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 插入菜品数据
|
||||||
|
* @param dish
|
||||||
|
*/
|
||||||
|
@AutoFill(OperationType.INSERT)
|
||||||
|
void insert(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<DishVO> pageQuery(DishPageQueryDTO pageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查找菜品
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from dish where id = #{id}")
|
||||||
|
Dish selectById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id删除菜品
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Delete("delete from dish where id = #{id}")
|
||||||
|
void deleteById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据菜品ids集合批量删除菜品
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteByIds(List<Long> ids);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Dish dish);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Select("select * from dish where category_id = #{categoryId}")
|
||||||
|
List<Dish> selectByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
List<Dish> selectByDishIdsAndStatusDisable(List<Long> dishIds);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.sky.enumeration.OperationType;
|
|||||||
import org.apache.ibatis.annotations.Insert;
|
import org.apache.ibatis.annotations.Insert;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface EmployeeMapper {
|
public interface EmployeeMapper {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.sky.entity.Dish;
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
List<Long> getSetmealIdsByDishIds(List<Long> ids);
|
||||||
|
|
||||||
|
void insertBatch(List<SetmealDish> setmealDishes);
|
||||||
|
|
||||||
|
void deleteBySetmealIds(List<Long> setmealIds);
|
||||||
|
|
||||||
|
@Select("select * from setmeal_dish where setmeal_id = #{setmealId}")
|
||||||
|
List<SetmealDish> selectBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
@Delete("delete from setmeal_dish where setmeal_id = #{setmealId}")
|
||||||
|
void deleteBySetmealId(Long setmealId);
|
||||||
|
|
||||||
|
@Select("select * from setmeal_dish where dish_id = #{dishId}")
|
||||||
|
List<SetmealDish> selectByDishId(Long dishId);
|
||||||
|
}
|
||||||
@@ -1,8 +1,15 @@
|
|||||||
package com.sky.mapper;
|
package com.sky.mapper;
|
||||||
|
|
||||||
|
import com.github.pagehelper.Page;
|
||||||
|
import com.sky.annotation.AutoFill;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.entity.Setmeal;
|
||||||
|
import com.sky.enumeration.OperationType;
|
||||||
import org.apache.ibatis.annotations.Mapper;
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface SetmealMapper {
|
public interface SetmealMapper {
|
||||||
|
|
||||||
@@ -14,4 +21,16 @@ public interface SetmealMapper {
|
|||||||
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
@Select("select count(id) from setmeal where category_id = #{categoryId}")
|
||||||
Integer countByCategoryId(Long id);
|
Integer countByCategoryId(Long id);
|
||||||
|
|
||||||
|
Page<Setmeal> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.INSERT)
|
||||||
|
void insert(Setmeal setmeal);
|
||||||
|
|
||||||
|
@Select("select * from setmeal where id = #{id}")
|
||||||
|
Setmeal selectById(Long id);
|
||||||
|
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
@AutoFill(OperationType.UPDATE)
|
||||||
|
void update(Setmeal setmeal);
|
||||||
}
|
}
|
||||||
|
|||||||
60
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
60
sky-server/src/main/java/com/sky/service/DishService.java
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
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 org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface DishService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
void saveWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(DishPageQueryDTO pageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品批量删除
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜品及口味
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
DishVO getByIdWithFlavor(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品基本信息(及口味)
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
void updateWithFlavor(DishDTO dishDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
List<Dish> selectByCategoryId(Long categoryId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
|
}
|
||||||
51
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
51
sky-server/src/main/java/com/sky/service/SetmealService.java
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package com.sky.service;
|
||||||
|
|
||||||
|
import com.sky.dto.SetmealDTO;
|
||||||
|
import com.sky.dto.SetmealPageQueryDTO;
|
||||||
|
import com.sky.result.PageResult;
|
||||||
|
import com.sky.vo.SetmealVO;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface SetmealService {
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
void insert(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
void deleteBatch(List<Long> ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐(及关联菜品)
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SetmealVO getByIdWithSetmealDishes(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
void updateWithSetmealDishes(SetmealDTO setmealDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
void startOrStop(Integer status, Long id);
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import com.github.pagehelper.Page;
|
|||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.dto.CategoryDTO;
|
import com.sky.dto.CategoryDTO;
|
||||||
import com.sky.dto.CategoryPageQueryDTO;
|
import com.sky.dto.CategoryPageQueryDTO;
|
||||||
import com.sky.entity.Category;
|
import com.sky.entity.Category;
|
||||||
@@ -18,8 +17,6 @@ import org.springframework.beans.BeanUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@@ -129,7 +126,6 @@ public class CategoryServiceImpl implements CategoryService {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public List<Category> list(Integer type) {
|
public List<Category> list(Integer type) {
|
||||||
List<Category> list = categoryMapper.selectByType(type);
|
return categoryMapper.selectByType(type);
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,199 @@
|
|||||||
|
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.entity.SetmealDish;
|
||||||
|
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 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 DishServiceImpl implements DishService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DishMapper dishMapper;
|
||||||
|
@Autowired
|
||||||
|
private DishFlavorMapper dishFlavorMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealDishMapper setmealDishMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealMapper setmealMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增菜品
|
||||||
|
*
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void saveWithFlavor(DishDTO dishDTO) {
|
||||||
|
//向菜品表插入数据(一条)
|
||||||
|
Dish dish = new Dish();
|
||||||
|
BeanUtils.copyProperties(dishDTO, dish);
|
||||||
|
dishMapper.insert(dish);
|
||||||
|
|
||||||
|
//获取Insert语句生成的主键值
|
||||||
|
Long id = dish.getId();
|
||||||
|
|
||||||
|
//向口味表插入N条数据
|
||||||
|
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||||
|
if (flavors != null && !flavors.isEmpty()) {
|
||||||
|
//遍历flavors,插入id
|
||||||
|
flavors.forEach(dishFlavor -> dishFlavor.setDishId(id));
|
||||||
|
//批量插入
|
||||||
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品分页查询
|
||||||
|
*
|
||||||
|
* @param pageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(DishPageQueryDTO pageQueryDTO) {
|
||||||
|
//设置分页
|
||||||
|
PageHelper.startPage(pageQueryDTO.getPage(), pageQueryDTO.getPageSize());
|
||||||
|
Page<DishVO> page = dishMapper.pageQuery(pageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品批量删除
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteBatch(List<Long> ids) {
|
||||||
|
//判断菜品是否能够删除
|
||||||
|
//是否有起售中菜品
|
||||||
|
for (Long id : ids) {
|
||||||
|
Dish dish = dishMapper.selectById(id);
|
||||||
|
if (dish.getStatus().equals(StatusConstant.ENABLE)) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//是否关联套餐
|
||||||
|
List<Long> setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
|
||||||
|
if (setmealIds != null && !setmealIds.isEmpty()) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
|
||||||
|
}
|
||||||
|
//删除菜品
|
||||||
|
/*for (Long id : ids) {
|
||||||
|
dishMapper.deleteById(id);
|
||||||
|
//删除菜品口味
|
||||||
|
dishFlavorMapper.deleteByDishId(id);
|
||||||
|
}*/
|
||||||
|
dishMapper.deleteByIds(ids);
|
||||||
|
dishFlavorMapper.deleteByDishIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询菜品及口味
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public DishVO getByIdWithFlavor(Long id) {
|
||||||
|
//根据id查询菜品
|
||||||
|
Dish dish = dishMapper.selectById(id);
|
||||||
|
|
||||||
|
//根据菜品id查询口味
|
||||||
|
List<DishFlavor> dishFlavors = dishFlavorMapper.getByDishId(id);
|
||||||
|
|
||||||
|
//封装到DishVO对象
|
||||||
|
DishVO dishVO = new DishVO();
|
||||||
|
BeanUtils.copyProperties(dish, dishVO);
|
||||||
|
dishVO.setFlavors(dishFlavors);
|
||||||
|
|
||||||
|
return dishVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改菜品基本信息(及口味)
|
||||||
|
*
|
||||||
|
* @param dishDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void updateWithFlavor(DishDTO dishDTO) {
|
||||||
|
//修改菜品基本信息
|
||||||
|
Dish dish = new Dish();
|
||||||
|
BeanUtils.copyProperties(dishDTO, dish);
|
||||||
|
dishMapper.update(dish);
|
||||||
|
|
||||||
|
//删除原有口味数据
|
||||||
|
dishFlavorMapper.deleteByDishId(dishDTO.getId());
|
||||||
|
|
||||||
|
//重新插入新的口味数据
|
||||||
|
List<DishFlavor> flavors = dishDTO.getFlavors();
|
||||||
|
if (flavors != null && !flavors.isEmpty()) {
|
||||||
|
//设置dishId
|
||||||
|
flavors.forEach(dishFlavor -> dishFlavor.setDishId(dish.getId()));
|
||||||
|
//插入新的口味数据
|
||||||
|
dishFlavorMapper.insertBatch(flavors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据分类id查询菜品
|
||||||
|
* @param categoryId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Dish> selectByCategoryId(Long categoryId) {
|
||||||
|
return dishMapper.selectByCategoryId(categoryId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜品起售停售
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void startOrStop(Integer status, Long id) {
|
||||||
|
//更新菜品状态
|
||||||
|
Dish dish = Dish.builder()
|
||||||
|
.id(id)
|
||||||
|
.status(status)
|
||||||
|
.build();
|
||||||
|
dishMapper.update(dish);
|
||||||
|
//如果是改为停售,需要同时停售关联套餐
|
||||||
|
if(status.equals(StatusConstant.DISABLE)) {
|
||||||
|
//检查是否有关联的套餐
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectByDishId(id);
|
||||||
|
if (setmealDishes != null && !setmealDishes.isEmpty()) {
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
for (SetmealDish setmealDish : setmealDishes) {
|
||||||
|
setmeal.setId(setmealDish.getSetmealId());
|
||||||
|
setmeal.setStatus(status);
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,6 @@ import com.github.pagehelper.PageHelper;
|
|||||||
import com.sky.constant.MessageConstant;
|
import com.sky.constant.MessageConstant;
|
||||||
import com.sky.constant.PasswordConstant;
|
import com.sky.constant.PasswordConstant;
|
||||||
import com.sky.constant.StatusConstant;
|
import com.sky.constant.StatusConstant;
|
||||||
import com.sky.context.BaseContext;
|
|
||||||
import com.sky.dto.EmployeeDTO;
|
import com.sky.dto.EmployeeDTO;
|
||||||
import com.sky.dto.EmployeeLoginDTO;
|
import com.sky.dto.EmployeeLoginDTO;
|
||||||
import com.sky.dto.EmployeePageQueryDTO;
|
import com.sky.dto.EmployeePageQueryDTO;
|
||||||
@@ -21,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.DigestUtils;
|
import org.springframework.util.DigestUtils;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
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.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.SetmealVO;
|
||||||
|
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 SetmealServiceImpl implements SetmealService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SetmealMapper setmealMapper;
|
||||||
|
@Autowired
|
||||||
|
private SetmealDishMapper setmealDishMapper;
|
||||||
|
@Autowired
|
||||||
|
private DishMapper dishMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐分页查询
|
||||||
|
*
|
||||||
|
* @param setmealPageQueryDTO
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||||
|
//设置分页
|
||||||
|
PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
|
||||||
|
Page<Setmeal> page = setmealMapper.pageQuery(setmealPageQueryDTO);
|
||||||
|
return new PageResult(page.getTotal(), page.getResult());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void insert(SetmealDTO setmealDTO) {
|
||||||
|
//插入套餐信息
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
setmealMapper.insert(setmeal);
|
||||||
|
|
||||||
|
//插入套餐包含菜品的信息
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
//设置setmealId
|
||||||
|
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmeal.getId()));
|
||||||
|
setmealDishMapper.insertBatch(setmealDishes);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除套餐
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void deleteBatch(List<Long> ids) {
|
||||||
|
//查看套餐是否有在售状态
|
||||||
|
for (Long id : ids) {
|
||||||
|
Setmeal setmeal = setmealMapper.selectById(id);
|
||||||
|
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//批量删除套餐(动态SQL)
|
||||||
|
//删除setmeal数据
|
||||||
|
setmealMapper.deleteBatch(ids);
|
||||||
|
//删除setmeal_dish数据
|
||||||
|
setmealDishMapper.deleteBySetmealIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据id查询套餐(及关联菜品)
|
||||||
|
*
|
||||||
|
* @param id
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public SetmealVO getByIdWithSetmealDishes(Long id) {
|
||||||
|
SetmealVO setmealVO = new SetmealVO();
|
||||||
|
//查询基本套餐信息
|
||||||
|
Setmeal setmeal = setmealMapper.selectById(id);
|
||||||
|
BeanUtils.copyProperties(setmeal, setmealVO);
|
||||||
|
//查询对应菜品信息
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectBySetmealId(id);
|
||||||
|
setmealVO.setSetmealDishes(setmealDishes);
|
||||||
|
return setmealVO;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改套餐
|
||||||
|
*
|
||||||
|
* @param setmealDTO
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateWithSetmealDishes(SetmealDTO setmealDTO) {
|
||||||
|
//更新setmeal基本数据
|
||||||
|
Setmeal setmeal = new Setmeal();
|
||||||
|
BeanUtils.copyProperties(setmealDTO, setmeal);
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
|
||||||
|
//更新setmeal_dish数据
|
||||||
|
//删除原setmeal_dish相关数据
|
||||||
|
setmealDishMapper.deleteBySetmealId(setmealDTO.getId());
|
||||||
|
//添加setmeal_id
|
||||||
|
List<SetmealDish> setmealDishes = setmealDTO.getSetmealDishes();
|
||||||
|
setmealDishes.forEach(setmealDish -> setmealDish.setSetmealId(setmealDTO.getId()));
|
||||||
|
//插入新的数据
|
||||||
|
setmealDishMapper.insertBatch(setmealDTO.getSetmealDishes());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 套餐起售停售
|
||||||
|
*
|
||||||
|
* @param status
|
||||||
|
* @param id
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void startOrStop(Integer status, Long id) {
|
||||||
|
//看是否为起售,如果为起售,需要判断其关联的菜品有停售状态
|
||||||
|
if (status.equals(StatusConstant.ENABLE)) {
|
||||||
|
/*
|
||||||
|
获取其关联的菜品信息--setmeal_dish--setmealDishes--遍历->getDishId
|
||||||
|
先把dishId放到一个集合中,批量查询该dish_id对应且status为0的菜品信息
|
||||||
|
如果查询到,则抛出删除失败异常
|
||||||
|
如果没有,则进行下一步,改变状态
|
||||||
|
*/
|
||||||
|
List<SetmealDish> setmealDishes = setmealDishMapper.selectBySetmealId(id);
|
||||||
|
List<Long> dishIds = new ArrayList<>();
|
||||||
|
setmealDishes.forEach(setmealDish -> dishIds.add(setmealDish.getDishId()));
|
||||||
|
List<Dish> dishes = dishMapper.selectByDishIdsAndStatusDisable(dishIds);
|
||||||
|
if (dishes != null && !dishes.isEmpty()){
|
||||||
|
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//不为起售则直接更改状态
|
||||||
|
Setmeal setmeal = Setmeal.builder()
|
||||||
|
.status(status)
|
||||||
|
.id(id)
|
||||||
|
.build();
|
||||||
|
setmealMapper.update(setmeal);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,10 @@ sky.datasource.port=3306
|
|||||||
sky.datasource.database=sky_take_out
|
sky.datasource.database=sky_take_out
|
||||||
sky.datasource.username=root
|
sky.datasource.username=root
|
||||||
sky.datasource.password=Slhaf20041205
|
sky.datasource.password=Slhaf20041205
|
||||||
|
spring.redis.host=localhost
|
||||||
|
spring.redis.port=6379
|
||||||
|
#spring.redis.password=Slhaf20041205
|
||||||
|
spring.redis.database=0
|
||||||
sky.alioss.access-key-id=LTAI5tKXHfExEucGsrbQvTqo
|
sky.alioss.access-key-id=LTAI5tKXHfExEucGsrbQvTqo
|
||||||
sky.alioss.access-key-secret=FkSXUC0mctKx6Gkyygin3Pyj35xYej
|
sky.alioss.access-key-secret=FkSXUC0mctKx6Gkyygin3Pyj35xYej
|
||||||
sky.alioss.bucket-name=sky-take-out-slhaf
|
sky.alioss.bucket-name=sky-take-out-slhaf
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ spring.datasource.druid.driver-class-name=${sky.datasource.driver-class-name}
|
|||||||
spring.datasource.druid.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
|
spring.datasource.druid.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
|
||||||
spring.datasource.druid.username=${sky.datasource.username}
|
spring.datasource.druid.username=${sky.datasource.username}
|
||||||
spring.datasource.druid.password=${sky.datasource.password}
|
spring.datasource.druid.password=${sky.datasource.password}
|
||||||
|
spring.redis.host=${spring.redis.host}
|
||||||
|
spring.redis.port=${spring.redis.port}
|
||||||
|
#spring.redis.password=${spring.redis.password}
|
||||||
|
spring.redis.database=${spring.redis.database}
|
||||||
mybatis.mapper-locations=classpath:mapper/*.xml
|
mybatis.mapper-locations=classpath:mapper/*.xml
|
||||||
mybatis.type-aliases-package=com.sky.entity
|
mybatis.type-aliases-package=com.sky.entity
|
||||||
mybatis.configuration.map-underscore-to-camel-case=true
|
mybatis.configuration.map-underscore-to-camel-case=true
|
||||||
|
|||||||
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="insertBatch">
|
||||||
|
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" separator="," open="(" close=")">
|
||||||
|
#{dishId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
||||||
58
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
58
sky-server/src/main/resources/mapper/DishMapper.xml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?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">
|
||||||
|
|
||||||
|
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into dish (name, category_id, price, image, description, status, create_time, update_time, create_user,
|
||||||
|
update_user)
|
||||||
|
values (#{name}, #{categoryId}, #{price}, #{image}, #{description}, #{status}, #{createTime}, #{updateTime},
|
||||||
|
#{createUser}, #{updateUser})
|
||||||
|
</insert>
|
||||||
|
<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>
|
||||||
|
<delete id="deleteByIds">
|
||||||
|
delete from dish where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
<select id="pageQuery" resultType="com.sky.vo.DishVO">
|
||||||
|
select dish.*, category.name as categoryName
|
||||||
|
from dish
|
||||||
|
left outer join category
|
||||||
|
on dish.category_id = category.id
|
||||||
|
<where>
|
||||||
|
<if test="name != null">
|
||||||
|
and dish.name like concat('%',#{name},'%')
|
||||||
|
</if>
|
||||||
|
<if test="categoryId != null">
|
||||||
|
and dish.category_id = #{categoryId}
|
||||||
|
</if>
|
||||||
|
<if test="status != null">
|
||||||
|
and dish.status = #{status}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
order by dish.create_time desc
|
||||||
|
</select>
|
||||||
|
<select id="selectByDishIdsAndStatusDisable" resultType="com.sky.entity.Dish">
|
||||||
|
select * from dish where id in
|
||||||
|
<foreach collection="dishIds" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
and status = 0
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
26
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
26
sky-server/src/main/resources/mapper/SetmealDishMapper.xml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<?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">
|
||||||
|
<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>
|
||||||
|
<delete id="deleteBySetmealIds">
|
||||||
|
delete from setmeal_dish where setmeal_id in
|
||||||
|
<foreach collection="setmealIds" item="setmealId" separator="," open="(" close=")">
|
||||||
|
#{setmealId}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="getSetmealIdsByDishIds" resultType="java.lang.Long">
|
||||||
|
select setmeal_id from setmeal_dish where dish_id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</select>
|
||||||
|
</mapper>
|
||||||
41
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
41
sky-server/src/main/resources/mapper/SetmealMapper.xml
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<?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">
|
||||||
|
<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>
|
||||||
|
<update id="update">
|
||||||
|
update setmeal
|
||||||
|
<set>
|
||||||
|
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||||
|
<if test="description != null">description = #{description},</if>
|
||||||
|
<if test="image != null">image = #{image},</if>
|
||||||
|
<if test="name != null">name = #{name},</if>
|
||||||
|
<if test="price != null">price = #{price},</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>
|
||||||
|
<delete id="deleteBatch">
|
||||||
|
delete from setmeal where id in
|
||||||
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<select id="pageQuery" resultType="com.sky.entity.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>
|
||||||
|
</mapper>
|
||||||
Reference in New Issue
Block a user