content: package com.sky.controller.admin;
  
  import java.util.List;
  
  import com.sky.service.SetmealService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.cache.annotation.CacheEvict;
  import org.springframework.web.bind.annotation.DeleteMapping;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.PostMapping;
  import org.springframework.web.bind.annotation.PutMapping;
  import org.springframework.web.bind.annotation.RequestBody;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestParam;
  import org.springframework.web.bind.annotation.RestController;
  
  import com.sky.dto.SetmealDTO;
  import com.sky.dto.SetmealPageQueryDTO;
  import com.sky.result.PageResult;
  import com.sky.result.Result;
  import com.sky.vo.SetmealVO;
  
  import lombok.extern.slf4j.Slf4j;
  
  @RestController
  @RequestMapping("/admin/setmeal")
  @Slf4j
  public class SetmealController {
  
      @Autowired
      private SetmealService setmealService;
  
      /**
       * 新增套餐
       *
       * @param setmealDTO
       * @return
       */
      @PostMapping
      @CacheEvict(cacheNames = "setmealCache", key = "#setmealDTO.categoryId")
      public Result<String> save(@RequestBody SetmealDTO setmealDTO) {
          log.info("新增套餐：{}", setmealDTO);
          setmealService.saveWithDish(setmealDTO);
          return Result.success();
      }
  
      /**
       * 分页查询
       *
       * @param setmealPageQueryDTO
       * @return
       */
      @GetMapping("/page")
      public Result<PageResult<SetmealVO>> page(SetmealPageQueryDTO setmealPageQueryDTO) {
          log.info("分页查询套餐列表，请求参数：{}", setmealPageQueryDTO);
          PageResult<SetmealVO> pageResult = setmealService.pageQuery(setmealPageQueryDTO);
          return Result.success(pageResult);
      }
  
      /**
       * 批量删除套餐
       *
       * @param ids
       * @return
       */
      @DeleteMapping
      @CacheEvict(cacheNames = "setmealCache", allEntries = true)
      public Result<String> delete(@RequestParam List<Long> ids) {
          log.info("删除套餐，ids：{}", ids);
          setmealService.deleteBatch(ids);
          return Result.success();
      }
  
      /**
       * 根据id查询套餐
       *
       * @param id
       * @return
       */
      @GetMapping("/{id}")
      public Result<SetmealVO> getById(@PathVariable Long id) {
          log.info("根据id查询套餐，id：{}", id);
          SetmealVO setmealVO = setmealService.getById(id);
          return Result.success(setmealVO);
      }
  
      /**
       * 修改套餐
       *
       * @param setmealDTO
       * @return
       */
      @PutMapping
      @CacheEvict(cacheNames = "setmealCache", allEntries = true)
      public Result<String> update(@RequestBody SetmealDTO setmealDTO) {
          log.info("修改套餐，请求参数：{}", setmealDTO);
          setmealService.update(setmealDTO);
          return Result.success();
      }
  
      /**
       * 启用或停用套餐
       *
       * @param status
       * @param id
       * @return
       */
      @PostMapping("/status/{status}")
      @CacheEvict(cacheNames = "setmealCache", allEntries = true)
      public Result<String> startOrStop(@PathVariable Integer status, Long id) {
          log.info("启用或停用套餐，status：{}，id：{}", status, id);
          setmealService.startOrStop(status, id);
          return Result.success();
      }
  }