|
@@ -9,19 +9,23 @@ import com.sky.service.DishService;
|
|
import com.sky.vo.DishVO;
|
|
import com.sky.vo.DishVO;
|
|
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.data.redis.core.RedisTemplate;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Set;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 菜品管理
|
|
* 菜品管理
|
|
*/
|
|
*/
|
|
-@RestController
|
|
|
|
|
|
+@RestController("adminDishController")
|
|
@RequestMapping("/admin/dish")
|
|
@RequestMapping("/admin/dish")
|
|
@Slf4j
|
|
@Slf4j
|
|
public class DishController {
|
|
public class DishController {
|
|
@Autowired
|
|
@Autowired
|
|
private DishService dishService;
|
|
private DishService dishService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisTemplate redisTemplate;
|
|
/**
|
|
/**
|
|
* 添加菜品
|
|
* 添加菜品
|
|
* @param dishDTO
|
|
* @param dishDTO
|
|
@@ -31,6 +35,9 @@ public class DishController {
|
|
public Result save(@RequestBody DishDTO dishDTO){
|
|
public Result save(@RequestBody DishDTO dishDTO){
|
|
log.info("新增菜品:{}",dishDTO);
|
|
log.info("新增菜品:{}",dishDTO);
|
|
dishService.saveWithFlavor(dishDTO);
|
|
dishService.saveWithFlavor(dishDTO);
|
|
|
|
+ //清理缓存数据
|
|
|
|
+ String key = "dish" + dishDTO.getCategoryId();
|
|
|
|
+ cleanCache(key);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -54,6 +61,8 @@ public class DishController {
|
|
@DeleteMapping
|
|
@DeleteMapping
|
|
public Result delete(@RequestParam List<Long> ids){
|
|
public Result delete(@RequestParam List<Long> ids){
|
|
log.info("批量删除菜品{}",ids);
|
|
log.info("批量删除菜品{}",ids);
|
|
|
|
+ //将所有菜品缓存数据清理掉,所有以dish_开头的key
|
|
|
|
+ cleanCache("dish*");
|
|
dishService.deleteBatch(ids);
|
|
dishService.deleteBatch(ids);
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
@@ -79,6 +88,9 @@ public class DishController {
|
|
public Result update(@RequestBody DishDTO dishDTO){
|
|
public Result update(@RequestBody DishDTO dishDTO){
|
|
log.info("修改菜品信息{}",dishDTO);
|
|
log.info("修改菜品信息{}",dishDTO);
|
|
dishService.updateWithFlavor(dishDTO);
|
|
dishService.updateWithFlavor(dishDTO);
|
|
|
|
+
|
|
|
|
+ //将所有菜品缓存数据清理掉,所有以dish_开头的key
|
|
|
|
+ cleanCache("dish*");
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -92,6 +104,9 @@ public class DishController {
|
|
public Result isSole(@PathVariable Integer status,Long id){
|
|
public Result isSole(@PathVariable Integer status,Long id){
|
|
log.info("菜品起售停售:{}{}",status,id);
|
|
log.info("菜品起售停售:{}{}",status,id);
|
|
dishService.isSole(status,id);
|
|
dishService.isSole(status,id);
|
|
|
|
+
|
|
|
|
+ //将所有菜品缓存数据清理掉,所有以dish_开头的key
|
|
|
|
+ cleanCache("dish*");
|
|
return Result.success();
|
|
return Result.success();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -107,4 +122,12 @@ public class DishController {
|
|
|
|
|
|
return Result.success(list);
|
|
return Result.success(list);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 清理缓存数据
|
|
|
|
+ */
|
|
|
|
+ private void cleanCache(String patten){
|
|
|
|
+ Set keys = redisTemplate.keys(patten);
|
|
|
|
+ redisTemplate.delete(keys);
|
|
|
|
+ }
|
|
}
|
|
}
|