Compare commits
6 Commits
e9bdc8baeb
...
39640025af
Author | SHA1 | Date |
---|---|---|
|
39640025af | |
|
97de686244 | |
|
25cf3769ec | |
|
612a929ddf | |
|
a914b2dc00 | |
|
ac4e7d8108 |
|
@ -1,17 +1,13 @@
|
|||
package com.sky.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Configurable;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.sky.config;
|
||||
|
||||
import ch.qos.logback.classic.pattern.MessageConverter;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
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;
|
||||
|
@ -47,7 +44,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
|||
.addPathPatterns("/admin/**")
|
||||
.excludePathPatterns("/admin/employee/login");
|
||||
|
||||
registry.addInterceptor(jwtTokenAdminInterceptor)
|
||||
registry.addInterceptor(jwtTokenUserInterceptor)
|
||||
.addPathPatterns("/user/**")
|
||||
.excludePathPatterns("/user/user/login")
|
||||
.excludePathPatterns("/user/shop/status");
|
||||
|
|
|
@ -10,10 +10,12 @@ import com.sky.vo.DishVO;
|
|||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/admin/dish")
|
||||
|
@ -22,6 +24,8 @@ import java.util.List;
|
|||
public class DishController {
|
||||
@Resource
|
||||
private DishService dishService;
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 新增菜品和口味
|
||||
|
@ -34,6 +38,10 @@ public class DishController {
|
|||
public Result<String> save(@RequestBody DishDTO dishDTO) {
|
||||
log.info("新增菜品:{}", dishDTO);
|
||||
dishService.saveWithFlavor(dishDTO);
|
||||
|
||||
// 修改、新增清理Redis数据
|
||||
String key = "dish_" + dishDTO.getCategoryId();
|
||||
redisTemplate.delete(key);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
@ -62,6 +70,9 @@ public class DishController {
|
|||
public Result<String> delete(@RequestParam List<Long> ids) {
|
||||
log.info("菜品批量删除:{}", ids);
|
||||
dishService.deleteBatch(ids);
|
||||
|
||||
// 以dish_开头全部删除
|
||||
cleanRedisCache();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
@ -90,6 +101,9 @@ public class DishController {
|
|||
public Result<String> update(@RequestBody DishDTO dishDTO) {
|
||||
log.info("修改菜品:{}", dishDTO);
|
||||
dishService.updateWithFlavor(dishDTO);
|
||||
|
||||
// 如果修改了就将所有的缓存数据全部删除
|
||||
cleanRedisCache();
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
|
@ -119,4 +133,14 @@ public class DishController {
|
|||
List<Dish> list = dishService.list(categoryId);
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果修改了就将所有的缓存数据全部删除
|
||||
*/
|
||||
private void cleanRedisCache() {
|
||||
Set keys = redisTemplate.keys("dish_*");
|
||||
if (keys != null && !keys.isEmpty()) {
|
||||
redisTemplate.delete(keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
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.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 javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RestController("adminRestController")
|
||||
@RequestMapping("/admin/setmeal")
|
||||
@Api(tags = "套餐相关接口")
|
||||
@Slf4j
|
||||
|
@ -33,4 +34,70 @@ public class SetmealController {
|
|||
setmealService.saveWithDish(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param setmealPageQueryDTO 请求参数
|
||||
* @return 返回数据
|
||||
*/
|
||||
@ApiOperation("分页查询")
|
||||
@GetMapping("page")
|
||||
public Result<PageResult> pageResultResult(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
PageResult pageResult = setmealService.pageQuery(setmealPageQueryDTO);
|
||||
return Result.success(pageResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
*
|
||||
* @param status Integer
|
||||
* @param id Long
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation("套餐起售停售")
|
||||
@PostMapping("status/{status}")
|
||||
public Result startOrStop(@PathVariable Integer status, Long id) {
|
||||
setmealService.startOrStop(status, id);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
*
|
||||
* @param ids 删除集合
|
||||
* @return Null
|
||||
*/
|
||||
@ApiOperation("批量删除套餐")
|
||||
@DeleteMapping("")
|
||||
public Result delete(@RequestParam List<Long> ids) {
|
||||
setmealService.delete(ids);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
*
|
||||
* @param id Long
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation("根据id查询套餐")
|
||||
@GetMapping("{id}")
|
||||
public Result getById(@PathVariable Long id) {
|
||||
SetmealVO setmealVO = setmealService.getById(id);
|
||||
return Result.success(setmealVO);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
*
|
||||
* @param setmealDTO SetmealDTO
|
||||
* @return Result
|
||||
*/
|
||||
@ApiOperation("修改套餐")
|
||||
@PutMapping()
|
||||
public Result update(@RequestBody SetmealDTO setmealDTO) {
|
||||
setmealService.update(setmealDTO);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,11 @@ 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 javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@RestController("userCategoryController")
|
||||
|
@ -16,15 +17,16 @@ import java.util.List;
|
|||
@Api(tags = "C端-分类接口")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
@Resource
|
||||
private CategoryService categoryService;
|
||||
|
||||
/**
|
||||
* 查询分类
|
||||
* @param type
|
||||
* @return
|
||||
*
|
||||
* @param type Integer
|
||||
* @return Result<List < Category>>
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@GetMapping("list")
|
||||
@ApiOperation("查询分类")
|
||||
public Result<List<Category>> list(Integer type) {
|
||||
List<Category> list = categoryService.list(type);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.sky.controller.user;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.sky.constant.StatusConstant;
|
||||
import com.sky.entity.Dish;
|
||||
import com.sky.result.Result;
|
||||
|
@ -8,35 +9,52 @@ 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.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RestController("userDishController")
|
||||
@RequestMapping("/user/dish")
|
||||
@Slf4j
|
||||
@Api(tags = "C端-菜品浏览接口")
|
||||
public class DishController {
|
||||
@Autowired
|
||||
@Resource
|
||||
private DishService dishService;
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 根据分类id查询菜品
|
||||
*
|
||||
* @param categoryId
|
||||
* @return
|
||||
* @param categoryId Long
|
||||
* @return Result<List < DishVO>>
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("根据分类id查询菜品")
|
||||
public Result<List<DishVO>> list(Long categoryId) {
|
||||
public Result<List<DishVO>> list(@RequestParam Long categoryId) {
|
||||
// 设置Redis中key
|
||||
String key = "dish_" + categoryId;
|
||||
// 查询Redis中数据
|
||||
List<DishVO> list = (List<DishVO>) redisTemplate.opsForValue().get(key);
|
||||
// 如果不为空返回集合
|
||||
if (list != null && !list.isEmpty()) {
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
// 如果Redis中没有,将值放入
|
||||
Dish dish = new Dish();
|
||||
dish.setCategoryId(categoryId);
|
||||
dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
|
||||
|
||||
List<DishVO> list = dishService.listWithFlavor(dish);
|
||||
|
||||
dish.setStatus(StatusConstant.ENABLE);// 查询起售中的菜品
|
||||
// 将这个数据保存到redis中
|
||||
list = dishService.listWithFlavor(dish);
|
||||
redisTemplate.opsForValue().set(key, JSON.toJSON(list), 7, TimeUnit.DAYS);
|
||||
// 如果Redis中没有,返回这个数据并保存这个数据
|
||||
return Result.success(list);
|
||||
}
|
||||
|
||||
|
|
|
@ -74,4 +74,12 @@ public interface DishMapper {
|
|||
* @return List<Dish>
|
||||
*/
|
||||
List<Dish> list(Dish dish);
|
||||
|
||||
/**
|
||||
* 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||
*
|
||||
* @param id Long
|
||||
* @return List<Dish>
|
||||
*/
|
||||
List<Dish> getBySetmealId(Long id);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
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.entity.SetmealDish;
|
||||
import com.sky.enumeration.OperationType;
|
||||
import com.sky.vo.DishItemVO;
|
||||
import com.sky.vo.SetmealVO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -41,4 +44,27 @@ public interface SetMealDishMapper {
|
|||
* @param setmealDishes List<SetmealDish>
|
||||
*/
|
||||
void insertBatch(List<SetmealDish> setmealDishes);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||
* @return Page<SetmealVO>
|
||||
*/
|
||||
Page<SetmealVO> pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 根据套餐id删除套餐和菜品的关联关系
|
||||
*
|
||||
* @param setmealId Long
|
||||
*/
|
||||
void deleteBySetmealId(Long setmealId);
|
||||
|
||||
/**
|
||||
* 根据套餐id查询套餐和菜品的关联关系
|
||||
*
|
||||
* @param id Long
|
||||
* @return List<SetmealDish>
|
||||
*/
|
||||
List<SetmealDish> getBySetmealId(Long id);
|
||||
}
|
||||
|
|
|
@ -41,4 +41,28 @@ public interface SetmealMapper {
|
|||
*/
|
||||
@AutoFill(OperationType.INSERT)
|
||||
void insert(Setmeal setmeal);
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
*
|
||||
* @param setmeal Setmeal
|
||||
*/
|
||||
@AutoFill(OperationType.UPDATE)
|
||||
void update(Setmeal setmeal);
|
||||
|
||||
|
||||
/**
|
||||
* 根据id获取套餐
|
||||
*
|
||||
* @param id Long
|
||||
* @return Setmeal
|
||||
*/
|
||||
Setmeal getById(Long id);
|
||||
|
||||
/**
|
||||
* 删除套餐表中的数据
|
||||
*
|
||||
* @param setmealId Long
|
||||
*/
|
||||
void deleteById(Long setmealId);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
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;
|
||||
|
||||
|
@ -31,4 +34,42 @@ public interface SetmealService {
|
|||
* @param setmealDTO SetmealDTO
|
||||
*/
|
||||
void saveWithDish(SetmealDTO setmealDTO);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
*
|
||||
* @param status Integer
|
||||
* @param id Long
|
||||
*/
|
||||
void startOrStop(Integer status, Long id);
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
*
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
void delete(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
*
|
||||
* @param id Long
|
||||
* @return SetmealVO
|
||||
*/
|
||||
SetmealVO getById(Long id);
|
||||
|
||||
/**
|
||||
* 修改套餐
|
||||
*
|
||||
* @param setmealDTO SetmealDTO
|
||||
*/
|
||||
void update(SetmealDTO setmealDTO);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.sky.service.DishService;
|
|||
import com.sky.vo.DishVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -34,6 +35,8 @@ public class DishServiceImpl implements DishService {
|
|||
private DishFlavorMapper dishFlavorMapper;
|
||||
@Resource
|
||||
private SetMealDishMapper setMealDishMapper;
|
||||
@Resource
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 新增菜品和口味
|
||||
|
@ -195,6 +198,10 @@ public class DishServiceImpl implements DishService {
|
|||
}
|
||||
}
|
||||
}
|
||||
// 停售时将Redis缓存清除
|
||||
dish = dishMapper.getById(id);
|
||||
String key = "dish_" + dish.getCategoryId();
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,13 +1,23 @@
|
|||
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.stereotype.Service;
|
||||
|
@ -70,4 +80,110 @@ public class SetmealServiceImpl implements SetmealService {
|
|||
// 保存套餐和菜品的关联关系
|
||||
setmealDishMapper.insertBatch(setmealDishes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*
|
||||
* @param setmealPageQueryDTO SetmealPageQueryDTO
|
||||
* @return PageResult
|
||||
*/
|
||||
@Override
|
||||
public PageResult pageQuery(SetmealPageQueryDTO setmealPageQueryDTO) {
|
||||
int pageNum = setmealPageQueryDTO.getPage();
|
||||
int pageSize = setmealPageQueryDTO.getPageSize();
|
||||
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
Page<SetmealVO> page = setmealDishMapper.pageQuery(setmealPageQueryDTO);
|
||||
return new PageResult(page.getTotal(), page.getResult());
|
||||
}
|
||||
|
||||
/**
|
||||
* 套餐起售停售
|
||||
*
|
||||
* @param status Integer
|
||||
* @param id Long
|
||||
*/
|
||||
@Override
|
||||
public void startOrStop(Integer status, Long id) {
|
||||
// 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售"
|
||||
if (status.equals(StatusConstant.ENABLE)) {
|
||||
List<Dish> dishList = dishMapper.getBySetmealId(id);
|
||||
if (dishList != null && !dishList.isEmpty()) {
|
||||
dishList.forEach(dish -> {
|
||||
if (dish.getStatus().equals(StatusConstant.DISABLE)) {
|
||||
throw new SetmealEnableFailedException(MessageConstant.SETMEAL_ENABLE_FAILED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Setmeal setmeal = Setmeal.builder().id(id).status(status).build();
|
||||
setmealMapper.update(setmeal);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除套餐
|
||||
*
|
||||
* @param ids List<Long>
|
||||
*/
|
||||
@Override
|
||||
public void delete(List<Long> ids) {
|
||||
ids.forEach(id -> {
|
||||
// 根据id获取套餐
|
||||
Setmeal setmeal = setmealMapper.getById(id);
|
||||
// 起售中商品不能删除
|
||||
if (setmeal.getStatus().equals(StatusConstant.ENABLE)) {
|
||||
throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
|
||||
}
|
||||
});
|
||||
|
||||
ids.forEach(setmealId -> {
|
||||
// 删除套餐表中的数据
|
||||
setmealMapper.deleteById(setmealId);
|
||||
// 删除套餐菜品关系表中的数据
|
||||
setmealDishMapper.deleteBySetmealId(setmealId);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据id查询套餐
|
||||
*
|
||||
* @param id Long
|
||||
* @return SetmealVO
|
||||
*/
|
||||
@Override
|
||||
public SetmealVO getById(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 SetmealDTO
|
||||
*/
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ spring:
|
|||
port: ${sky.redis.port}
|
||||
password: ${sky.redis.password}
|
||||
database: ${sky.redis.database}
|
||||
timeout: 5000
|
||||
|
||||
|
||||
mybatis:
|
||||
|
|
|
@ -108,4 +108,12 @@
|
|||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
|
||||
<!-- 起售套餐时,判断套餐内是否有停售菜品,有停售菜品提示"套餐内包含未启售菜品,无法启售" -->
|
||||
<select id="getBySetmealId" resultType="com.sky.entity.Dish">
|
||||
select a.*
|
||||
from dish a
|
||||
left join setmeal_dish b on a.id = b.dish_id
|
||||
where b.setmeal_id = #{id}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -44,6 +44,13 @@
|
|||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
|
||||
<delete id="deleteBySetmealId">
|
||||
delete
|
||||
from setmeal_dish
|
||||
where setmeal_id = #{setmealId}
|
||||
</delete>
|
||||
|
||||
<!-- 查询对应套餐id -->
|
||||
<select id="getSetMealDishIds" resultType="java.lang.Long">
|
||||
select *
|
||||
|
@ -60,4 +67,35 @@
|
|||
left join dish d on sd.dish_id = d.id
|
||||
where sd.setmeal_id = #{setmealId}
|
||||
</select>
|
||||
|
||||
<!-- 分页查询 -->
|
||||
<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>
|
||||
|
||||
<!-- 根据套餐id查询套餐和菜品的关联关系 -->
|
||||
<select id="getBySetmealId" resultType="com.sky.entity.SetmealDish">
|
||||
select *
|
||||
from setmeal_dish
|
||||
where setmeal_id = #{setmealId}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
@ -10,6 +10,51 @@
|
|||
#{createUser}, #{updateUser})
|
||||
</insert>
|
||||
|
||||
<!-- 套餐起售停售 -->
|
||||
<update id="update">
|
||||
update setmeal
|
||||
<set>
|
||||
<if test="categoryId != null">
|
||||
category_id = #{categoryId},
|
||||
</if>
|
||||
<if test="name != null">
|
||||
name = #{name},
|
||||
</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="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="createUser != null">
|
||||
create_user = #{createUser},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
<if test="updateUser != null">
|
||||
update_user = #{updateUser},
|
||||
</if>
|
||||
</set>
|
||||
where id = #{id};
|
||||
</update>
|
||||
|
||||
<!-- 根据套餐id删除套餐和菜品的关联关系 -->
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from setmeal
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<!-- 根据分类id查询套餐的数量 -->
|
||||
<select id="countByCategoryId" resultType="java.lang.Integer">
|
||||
select count(id)
|
||||
|
@ -40,4 +85,11 @@
|
|||
left join dish d on sd.dish_id = d.id
|
||||
where sd.setmeal_id = #{setmealId}
|
||||
</select>
|
||||
|
||||
<!-- 根据id获取套餐 -->
|
||||
<select id="getById" resultType="com.sky.entity.Setmeal">
|
||||
select *
|
||||
from setmeal
|
||||
where id = #{id}
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue