setmeal cache
This commit is contained in:
@@ -3,6 +3,7 @@ package com.sky;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.cache.annotation.EnableCaching;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -10,6 +11,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
|
|||||||
*/
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableTransactionManagement //开启注解方式的事务管理
|
@EnableTransactionManagement //开启注解方式的事务管理
|
||||||
|
@EnableCaching
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SkyApplication {
|
public class SkyApplication {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
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.cache.annotation.CacheEvict;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -43,6 +44,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping
|
||||||
@ApiOperation("新增套餐")
|
@ApiOperation("新增套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",key = "#setmealDTO.categoryId")
|
||||||
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
public Result insert(@RequestBody SetmealDTO setmealDTO){
|
||||||
log.info("新增套餐: {}",setmealDTO);
|
log.info("新增套餐: {}",setmealDTO);
|
||||||
setmealService.insert(setmealDTO);
|
setmealService.insert(setmealDTO);
|
||||||
@@ -56,6 +58,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@DeleteMapping
|
@DeleteMapping
|
||||||
@ApiOperation("批量删除套餐")
|
@ApiOperation("批量删除套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
public Result delete(@RequestParam List<Long> ids){
|
public Result delete(@RequestParam List<Long> ids){
|
||||||
log.info("批量删除套餐: {}",ids);
|
log.info("批量删除套餐: {}",ids);
|
||||||
setmealService.deleteBatch(ids);
|
setmealService.deleteBatch(ids);
|
||||||
@@ -82,6 +85,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@PutMapping
|
@PutMapping
|
||||||
@ApiOperation("修改套餐")
|
@ApiOperation("修改套餐")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
public Result update(@RequestBody SetmealDTO setmealDTO){
|
public Result update(@RequestBody SetmealDTO setmealDTO){
|
||||||
log.info("修改套餐: {}",setmealDTO);
|
log.info("修改套餐: {}",setmealDTO);
|
||||||
setmealService.updateWithSetmealDishes(setmealDTO);
|
setmealService.updateWithSetmealDishes(setmealDTO);
|
||||||
@@ -96,6 +100,7 @@ public class SetmealController {
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/status/{status}")
|
@PostMapping("/status/{status}")
|
||||||
@ApiOperation("套餐起售停售")
|
@ApiOperation("套餐起售停售")
|
||||||
|
@CacheEvict(cacheNames = "setmealCache",allEntries = true)
|
||||||
public Result startOrStop(@PathVariable Integer status,Long id){
|
public Result startOrStop(@PathVariable Integer status,Long id){
|
||||||
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
log.info("套餐起售停售: 状态:{},ID:{}",status,id);
|
||||||
setmealService.startOrStop(status,id);
|
setmealService.startOrStop(status,id);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import io.swagger.annotations.Api;
|
|||||||
import io.swagger.annotations.ApiOperation;
|
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.cache.annotation.Cacheable;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -26,6 +27,7 @@ public class SetmealController {
|
|||||||
|
|
||||||
@GetMapping("/list")
|
@GetMapping("/list")
|
||||||
@ApiOperation("select setmeal by categoryId")
|
@ApiOperation("select setmeal by categoryId")
|
||||||
|
@Cacheable(cacheNames = "setmealCache",key = "#categoryId")
|
||||||
public Result<List<Setmeal>> list(Integer categoryId){
|
public Result<List<Setmeal>> list(Integer categoryId){
|
||||||
log.info("select setmeal by categoryId :{}", categoryId);
|
log.info("select setmeal by categoryId :{}", categoryId);
|
||||||
List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(categoryId);
|
List<Setmeal> setmealList = setmealService.selectSetmealByCategoryId(categoryId);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import com.sky.vo.DishItemVO;
|
|||||||
import com.sky.vo.SetmealVO;
|
import com.sky.vo.SetmealVO;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user