diff --git a/.idea/compiler.xml b/.idea/compiler.xml
index f9c40ef..51c391f 100644
--- a/.idea/compiler.xml
+++ b/.idea/compiler.xml
@@ -17,9 +17,9 @@
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index abb532a..c176f1e 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -1,6 +1,11 @@
+
+
+
+
+
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 20e6aef..75cbc6f 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -14,7 +14,7 @@
-
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index f547a57..0000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/sky-server/src/main/java/com/sky/controller/admin/DishController.java b/sky-server/src/main/java/com/sky/controller/admin/DishController.java
index c72835f..4b35c41 100644
--- a/sky-server/src/main/java/com/sky/controller/admin/DishController.java
+++ b/sky-server/src/main/java/com/sky/controller/admin/DishController.java
@@ -1,10 +1,7 @@
package com.sky.controller.admin;
-
-import com.sky.dto.DishDTO;
-import com.sky.dto.DishPageQueryDTO;
+import com.sky.constant.StatusConstant;
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;
@@ -13,97 +10,48 @@ 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 org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
import java.util.List;
-import java.util.Set;
-/*
-* 菜品管理
-* */
-@RestController
-@RequestMapping("/admin/dish")
-@Api(tags = "菜品相关接口")
+@RestController("userDishController")
+@RequestMapping("/user/dish")
@Slf4j
+@Api(tags = "C端-菜品浏览接口")
public class DishController {
-
@Autowired
private DishService dishService;
@Autowired
private RedisTemplate redisTemplate;
- @PostMapping
- @ApiOperation("新增菜品")
- public Result save(@RequestBody DishDTO dishDTO){
- log.info("新增菜品:{}",dishDTO);
- dishService.saveWithFlavor(dishDTO);
-
- //清理缓存数据
- String key = "dish_" + dishDTO.getCategoryId();
- redisTemplate.delete(key);
- return Result.success();
- }
-
- @GetMapping("/page")
- @ApiOperation("菜品分页查询")
- public Result page(DishPageQueryDTO dishPageQueryDTO){
- log.info("菜品分页查询:{}",dishPageQueryDTO);
- PageResult pageResult = dishService.pageQuery(dishPageQueryDTO);
- return Result.success(pageResult);
- }
-
- @DeleteMapping
- @ApiOperation("批量删除菜品")
- public Result delete(@RequestParam List ids){
- log.info("菜品批量删除:{}",ids);
- dishService.deleteBatch(ids);
-
- //将所有菜品缓存数据清理掉,所有以dish_开头的key
- cleanCache("dish_*");
- return Result.success();
- }
- @GetMapping("/{id}")
- @ApiOperation("根据菜品id获取信息")
- public Result getById(@PathVariable Long id){
- log.info("根据id获取菜品:{}",id);
- DishVO dishVO = dishService.getById(id);
- return Result.success(dishVO);
- }
-
- @PutMapping
- @ApiOperation("修改菜品")
- public Result update(@RequestBody DishDTO dishDTO){
- log.info("修改菜品:{}",dishDTO);
- dishService.updateWithFlavor(dishDTO);
-
- //将所有菜品缓存数据清理掉,所有以dish_开头的key
- cleanCache("dish_*");
- return Result.success();
- }
-
- @ApiOperation("起售停售菜品")
- @PostMapping("/status/{status}")
- public Result StartOrStop(@PathVariable Integer status,Integer id){
- log.info("起售停售菜品:{}",status == 1 ? "起售" : "停售");
- dishService.startOrStop(status,id);
-
- //将所有菜品缓存数据清理掉,所有以dish_开头的key
- cleanCache("dish_*");
- return Result.success();
- }
+ /**
+ * 根据分类id查询菜品
+ *
+ * @param categoryId
+ * @return
+ */
@GetMapping("/list")
@ApiOperation("根据分类id查询菜品")
- public Result> getByCategoryId(Long categoryId){
- log.info("根据分类id查询菜品:{}",categoryId);
- List list = dishService.getByCategoryId(categoryId);
+ public Result> list(Long categoryId) {
+
+ //构造redis中的key,规则: dish_key分类id
+ String key = "dish_" + categoryId;
+ //查询redis中是否存在菜品数据
+ List list = (List) redisTemplate.opsForValue().get(key);
+ if(list != null && list.size() >0){
+ //如果存在,直接返回,无须查询数据库
+ return Result.success(list);
+ }
+ //如果不存在,查询数据库,将查询到的数据放入redis中
+ Dish dish = new Dish();
+ dish.setCategoryId(categoryId);
+ dish.setStatus(StatusConstant.ENABLE);//查询起售中的菜品
+
+ list = dishService.listWithFlavor(dish);
+ redisTemplate.opsForValue().set(key,list);
+
return Result.success(list);
}
- /*
- * 清理缓存数据
- * */
- private void cleanCache(String pattern){
- Set keys = redisTemplate.keys(pattern);
- redisTemplate.delete(keys);
- }
}
diff --git a/sky-server/src/main/java/com/sky/controller/admin/SetmealController.java b/sky-server/src/main/java/com/sky/controller/admin/SetmealController.java
new file mode 100644
index 0000000..46d33b0
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/controller/admin/SetmealController.java
@@ -0,0 +1,55 @@
+package com.sky.controller.admin;
+
+import com.sky.constant.StatusConstant;
+import com.sky.entity.Setmeal;
+import com.sky.result.Result;
+import com.sky.service.SetmealService;
+import com.sky.vo.DishItemVO;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+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.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import java.util.List;
+
+@RestController("userSetmealController") // 定义一个REST控制器,并指定其bean名称为"userSetmealController"
+@RequestMapping("/user/setmeal") // 设置请求路径前缀为"/user/setmeal"
+@Api(tags = "C端-套餐浏览接口") // 使用Swagger注解标记该控制器的API文档标签
+public class SetmealController {
+ @Autowired // 自动注入SetmealService实例
+ private SetmealService setmealService;
+
+ /**
+ * 根据分类id查询套餐列表
+ *
+ * @param categoryId 分类ID
+ * @return 包含查询结果的Result对象
+ */
+ @GetMapping("/list") // 映射HTTP GET请求到该方法
+ @ApiOperation("根据分类id查询套餐") // 使用Swagger注解描述该操作的功能
+ @Cacheable(cacheNames = "setmealCache", key = "#categoryId") // 启用缓存,缓存名为"setmealCache",键为方法参数categoryId的值
+ public Result> list(Long categoryId) {
+ Setmeal setmeal = new Setmeal(); // 创建一个新的Setmeal对象
+ setmeal.setCategoryId(categoryId); // 设置Setmeal对象的分类ID
+ setmeal.setStatus(StatusConstant.ENABLE); // 设置Setmeal对象的状态为启用状态
+
+ List list = setmealService.list(setmeal); // 调用服务层方法获取符合条件的套餐列表
+ return Result.success(list); // 返回包含查询结果的成功响应
+ }
+
+ /**
+ * 根据套餐id查询包含的菜品列表
+ *
+ * @param id 套餐ID
+ * @return 包含查询结果的Result对象
+ */
+ @GetMapping("/dish/{id}") // 映射HTTP GET请求到该方法,URL中包含动态参数id
+ @ApiOperation("根据套餐id查询包含的菜品列表") // 使用Swagger注解描述该操作的功能
+ public Result> dishList(@PathVariable("id") Long id) { // 从URL路径中提取id参数
+ List list = setmealService.getDishItemById(id); // 调用服务层方法获取指定套餐包含的菜品列表
+ return Result.success(list); // 返回包含查询结果的成功响应
+ }
+}
diff --git a/sky-server/src/main/java/com/sky/mapper/DishFlavorMapper.java b/sky-server/src/main/java/com/sky/mapper/DishFlavorMapper.java
new file mode 100644
index 0000000..87d2e36
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/mapper/DishFlavorMapper.java
@@ -0,0 +1,34 @@
+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 {
+
+ /*
+ * 批量插入口味数据
+ * */
+ void insertBatch(List flavors);
+
+ /*
+ * 根据菜品id删除对应口味
+ * */
+ @Delete("delete from dish_flavor where dish_id = #{dishId}")
+ void deleteByDishId(Long dishId);
+
+ /*
+ * 根据菜品id集合批量删除关联的口味数据
+ * */
+ void deleteByDishIds(List dishIds);
+
+ /*
+ * 根据菜品id返回口味数据
+ * */
+ @Select("select * from dish_flavor where dish_id = #{dishId}")
+ List getByDishId(Long dishId);
+}
diff --git a/sky-server/src/main/java/com/sky/mapper/SetmealMapper.java b/sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
index 801b630..0b7ad45 100644
--- a/sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
+++ b/sky-server/src/main/java/com/sky/mapper/SetmealMapper.java
@@ -1,7 +1,76 @@
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 com.sky.vo.DishItemVO;
+import com.sky.vo.SetmealVO;
+import org.apache.ibatis.annotations.Insert;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import java.util.List;
+import java.util.Map;
+
+@Mapper
public interface SetmealMapper {
- Setmeal getById(Long setmealId);
+
+ /**
+ * 根据分类id查询套餐的数量
+ * @param id
+ * @return
+ */
+ @Select("select count(id) from setmeal where category_id = #{categoryId}")
+ Integer countByCategoryId(Long id);
+
+ /*
+ * 新增套餐
+ * */
+ @AutoFill(OperationType.INSERT)
+ void insert(Setmeal setmeal);
+
+ Page pageQuery(SetmealPageQueryDTO setmealPageQueryDTO);
+
+ /*
+ * 根据套餐id获取套餐数据
+ * */
+ @Select("select * from setmeal where id = #{id}")
+ Setmeal getById(Long Id);
+
+ void deleteBatch(List ids);
+
+
+ @AutoFill(OperationType.UPDATE)
+ void updateWithDish(Setmeal setmeal);
+
+ @Update("update setmeal set status = #{status} where id = #{id}")
+ void startOrStop(Setmeal setmeal);
+
+ /**
+ * 动态条件查询套餐
+ * @param setmeal
+ * @return
+ */
+ List list(Setmeal setmeal);
+
+
+ /**
+ * 根据套餐id查询菜品选项
+ * @param setmealId
+ * @return
+ */
+ @Select("select sd.name, sd.copies, d.image, d.description " +
+ "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
+ "where sd.setmeal_id = #{setmealId}")
+ List getDishItemBySetmealId(Long setmealId);
+
+ /**
+ * 根据条件统计套餐数量
+ * @param map
+ * @return
+ */
+ Integer countByMap(Map map);
}
diff --git a/sky-server/src/main/java/com/sky/service/DishService.java b/sky-server/src/main/java/com/sky/service/DishService.java
new file mode 100644
index 0000000..bbd3515
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/service/DishService.java
@@ -0,0 +1,50 @@
+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 io.swagger.models.auth.In;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+public interface DishService {
+
+ /*
+ * 新增菜品和对应的口味
+ * */
+ void saveWithFlavor(DishDTO dishDTO);
+
+ /*
+ * 菜品分页查询
+ * */
+ PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO);
+
+ void deleteBatch(List ids);
+
+
+ /*
+ * 根据菜品id返回菜品和口味数据
+ * */
+ DishVO getById(Long id);
+
+ /*
+ * 根据id修改菜品基本信息和对应口味信息
+ * */
+ void updateWithFlavor(DishDTO dishDTO);
+
+ List getByCategoryId(Long categoryId);
+
+ /**
+ * 条件查询菜品和口味
+ * @param dish
+ * @return
+ */
+ List listWithFlavor(Dish dish);
+
+
+ void startOrStop(Integer status, Integer id);
+}
diff --git a/sky-server/src/main/java/com/sky/service/SetmealService.java b/sky-server/src/main/java/com/sky/service/SetmealService.java
new file mode 100644
index 0000000..348d7bd
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/service/SetmealService.java
@@ -0,0 +1,65 @@
+package com.sky.service;
+
+import com.sky.dto.SetmealDTO;
+import com.sky.dto.SetmealPageQueryDTO;
+import com.sky.result.PageResult;
+import com.sky.vo.DishItemVO;
+import com.sky.vo.SetmealVO;
+import com.sky.entity.Setmeal;
+
+import java.util.List;
+
+public interface SetmealService {
+ /**
+ * 保存套餐及其包含的菜品信息
+ * @param setmealDTO 包含套餐和菜品信息的数据传输对象
+ */
+ public void saveWithDishes(SetmealDTO setmealDTO);
+
+ /**
+ * 分页查询套餐信息
+ * @param setmealPageQueryDTO 包含分页查询条件的数据传输对象
+ * @return 分页结果,包括总记录数和当前页数据
+ */
+ PageResult page(SetmealPageQueryDTO setmealPageQueryDTO);
+
+ /**
+ * 删除指定ID列表的套餐
+ * @param ids 要删除的套餐ID列表
+ */
+ void delete(List ids);
+
+ /**
+ * 根据ID获取套餐详细信息
+ * @param id 套餐ID
+ * @return 包含套餐详细信息的视图对象
+ */
+ SetmealVO getById(Long id);
+
+ /**
+ * 更新套餐及其包含的菜品信息
+ * @param setmealDTO 包含更新后的套餐和菜品信息的数据传输对象
+ */
+ void updateWithDish(SetmealDTO setmealDTO);
+
+ /**
+ * 启动或停止指定ID的套餐销售状态
+ * @param status 新的销售状态(1表示启用,0表示停用)
+ * @param id 套餐ID
+ */
+ void startOrStop(Integer status, Long id);
+
+ /**
+ * 条件查询套餐列表
+ * @param setmeal 包含查询条件的套餐实体对象
+ * @return 符合条件的套餐列表
+ */
+ List list(Setmeal setmeal);
+
+ /**
+ * 根据套餐ID查询其包含的菜品选项
+ * @param id 套餐ID
+ * @return 包含菜品选项的视图对象列表
+ */
+ List getDishItemById(Long id);
+}
diff --git a/sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java b/sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java
new file mode 100644
index 0000000..6daa8fc
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/service/impl/DishServiceImpl.java
@@ -0,0 +1,190 @@
+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.exception.DeletionNotAllowedException;
+import com.sky.mapper.DishFlavorMapper;
+import com.sky.mapper.DishMapper;
+import com.sky.mapper.SetmealDishMapper;
+import com.sky.result.PageResult;
+import com.sky.service.DishService;
+import com.sky.vo.DishVO;
+import io.swagger.models.auth.In;
+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.ArrayList;
+import java.util.List;
+
+@Service
+@Slf4j
+public class DishServiceImpl implements DishService {
+
+ @Autowired
+ private DishMapper dishMapper;
+
+ @Autowired
+ private DishFlavorMapper dishFlavorMapper;
+ @Autowired
+ private SetmealDishMapper setmealDishMapper;
+
+ /**
+ * 新增菜品和对应的口味
+ * @param dishDTO 包含菜品信息和口味信息的数据传输对象
+ */
+ @Transactional
+ public void saveWithFlavor(DishDTO dishDTO) {
+ // 创建一个新的Dish对象,并从DishDTO中复制属性
+ Dish dish = new Dish();
+ BeanUtils.copyProperties(dishDTO, dish);
+ // 向菜品表插入1条数据
+ dishMapper.insert(dish);
+
+ // 获取insert语句生成的主键值
+ Long dishId = dish.getId();
+
+ // 向口味表插入n条数据
+ List flavors = dishDTO.getFlavors();
+ if (flavors != null && flavors.size() > 0) {
+ flavors.forEach(dishFlavor -> {
+ dishFlavor.setDishId(dishId); // 设置口味的菜品ID为新插入的菜品ID
+ });
+ // 向口味表插入n条数据
+ dishFlavorMapper.insertBatch(flavors);
+ }
+ }
+
+ /**
+ * 分页查询菜品
+ * @param dishPageQueryDTO 包含分页查询条件的数据传输对象
+ * @return 分页结果,包括总记录数和当前页的数据列表
+ */
+ @Override
+ public PageResult pageQuery(DishPageQueryDTO dishPageQueryDTO) {
+ // 开启分页查询,设置当前页和每页显示的记录数
+ PageHelper.startPage(dishPageQueryDTO.getPage(), dishPageQueryDTO.getPageSize());
+ // 根据条件查询菜品数据,返回分页结果
+ Page page = dishMapper.pageQuery(dishPageQueryDTO);
+ return new PageResult(page.getTotal(), page.getResult());
+ }
+
+ /**
+ * 批量删除菜品
+ * @param ids 要删除的菜品ID列表
+ */
+ @Transactional
+ public void deleteBatch(List ids) {
+ // 判断当前菜品是否能删除 -- 起售状态检查
+ for (Long id : ids) {
+ Dish dish = dishMapper.getById(id);
+ if (dish.getStatus() == StatusConstant.ENABLE) {
+ throw new DeletionNotAllowedException(MessageConstant.DISH_ON_SALE);
+ }
+ }
+
+ // 检查菜品是否被套餐关联
+ List setmealIds = setmealDishMapper.getSetmealIdsByDishIds(ids);
+ if (setmealIds != null && setmealIds.size() > 0) {
+ // 当前菜品被套餐关联,抛出异常
+ throw new DeletionNotAllowedException(MessageConstant.DISH_BE_RELATED_BY_SETMEAL);
+ }
+
+ // 根据菜品id集合批量删除菜品数据
+ dishMapper.deleteByIds(ids);
+ // 根据菜品id集合批量删除关联的口味数据
+ dishFlavorMapper.deleteByDishIds(ids);
+ }
+
+ /**
+ * 根据ID查询菜品及其口味信息
+ * @param id 菜品ID
+ * @return 包含菜品基本信息和口味信息的视图对象
+ */
+ @Override
+ public DishVO getById(Long id) {
+ // 根据id查询菜品数据
+ Dish dish = dishMapper.getById(id);
+ // 查询口味数据
+ List dishFlavors = dishFlavorMapper.getByDishId(id);
+ // 封装到vo对象
+ 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 flavors = dishDTO.getFlavors();
+ if (flavors != null && flavors.size() > 0) {
+ flavors.forEach(dishFlavor -> {
+ dishFlavor.setDishId(dishDTO.getId()); // 设置口味的菜品ID为更新后的菜品ID
+ });
+ // 向口味表插入n条数据
+ dishFlavorMapper.insertBatch(flavors);
+ }
+ }
+
+ /**
+ * 根据分类ID查询启用状态的菜品列表
+ * @param categoryId 分类ID
+ * @return 启用状态的菜品列表
+ */
+ @Override
+ public List getByCategoryId(Long categoryId) {
+ Dish dish = Dish.builder()
+ .categoryId(categoryId)
+ .status(StatusConstant.ENABLE)
+ .build();
+ return dishMapper.getByCategoryId(dish);
+ }
+
+ /**
+ * 条件查询菜品和口味信息
+ * @param dish 包含查询条件的菜品对象
+ * @return 符合条件的菜品视图对象列表
+ */
+ public List listWithFlavor(Dish dish) {
+ List dishList = dishMapper.getByCategoryId(dish); // 根据分类ID查询菜品列表
+ List dishVOList = new ArrayList<>(); // 用于存储最终的菜品视图对象列表
+ for (Dish d : dishList) { // 遍历查询到的菜品列表
+ DishVO dishVO = new DishVO(); // 创建新的菜品视图对象
+ BeanUtils.copyProperties(d, dishVO); // 将菜品对象的属性复制到视图对象中
+ // 根据菜品id查询对应的口味
+ List flavors = dishFlavorMapper.getByDishId(d.getId()); // 查询口味列表
+ dishVO.setFlavors(flavors); // 设置视图对象的口味列表属性
+ dishVOList.add(dishVO); // 将视图对象添加到最终列表中
+ }
+ return dishVOList; // 返回最终的菜品视图对象列表
+ }
+
+ /**
+ * 启动或停止菜品销售状态
+ * @param status 目标状态(启用或停用)
+ * @param id 菜品ID
+ */
+ @Override
+ public void startOrStop(Integer status, Integer id) {
+ dishMapper.startOrStop(status, id); // 更新菜品的销售状态
+ }
+}
+
diff --git a/sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java b/sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java
new file mode 100644
index 0000000..c4b6442
--- /dev/null
+++ b/sky-server/src/main/java/com/sky/service/impl/SetmealServiceImpl.java
@@ -0,0 +1,162 @@
+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.Employee;
+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.DishItemVO;
+import com.sky.vo.DishVO;
+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.List;
+
+@Service
+public class SetmealServiceImpl implements SetmealService {
+
+ @Autowired
+ private SetmealMapper setmealMapper; // 注入套餐Mapper
+ @Autowired
+ private DishMapper dishMapper; // 注入菜品Mapper
+ @Autowired
+ private SetmealDishMapper setmealDishMapper; // 注入套餐菜品关系Mapper
+
+ /*
+ * 新增套餐
+ * */
+ @Override
+ @Transactional
+ public void saveWithDishes(SetmealDTO setmealDTO) {
+ // 创建套餐对象并复制属性
+ Setmeal setmeal = new Setmeal();
+ BeanUtils.copyProperties(setmealDTO, setmeal);
+ // 向套餐表插入一条数据
+ setmealMapper.insert(setmeal);
+
+ // 获取新插入的套餐ID
+ Long setmealId = setmealDTO.getId();
+ // 获取套餐中的菜品列表
+ List setmealDishes = setmealDTO.getSetmealDishes();
+ // 为每个菜品设置对应的套餐ID
+ setmealDishes.forEach(setmealDish -> {
+ setmealDish.setSetmealId(setmealId);
+ });
+ // 向套餐菜品关系表插入多条数据
+ setmealDishMapper.insertBatch(setmealDishes);
+ }
+
+ @Override
+ public PageResult page(SetmealPageQueryDTO setmealPageQueryDTO) {
+ // 开启分页查询,设置当前页和每页显示记录数
+ PageHelper.startPage(setmealPageQueryDTO.getPage(), setmealPageQueryDTO.getPageSize());
+ // 执行分页查询,获取结果集
+ Page page = setmealMapper.pageQuery(setmealPageQueryDTO);
+ // 返回分页结果,包含总记录数和当前页数据
+ return new PageResult(page.getTotal(), page.getResult());
+ }
+
+ @Transactional
+ public void delete(List ids) {
+ // 遍历要删除的套餐ID列表
+ for (Long id : ids) {
+ // 根据ID查询套餐信息
+ Setmeal setmeal = setmealMapper.getById(id);
+ // 如果套餐正在销售中,则抛出异常,不允许删除
+ if (setmeal.getStatus() == StatusConstant.ENABLE) {
+ throw new DeletionNotAllowedException(MessageConstant.SETMEAL_ON_SALE);
+ }
+ }
+ // 批量删除套餐表中的数据
+ setmealMapper.deleteBatch(ids);
+ // 批量删除套餐菜品关系表中的数据
+ setmealDishMapper.deleteBySetmealIds(ids);
+ }
+
+ /*
+ * 根据id获取套餐数据
+ * 以及相应的菜品数据
+ * */
+ @Override
+ public SetmealVO getById(Long id) {
+ // 根据ID查询套餐信息
+ Setmeal setmeal = setmealMapper.getById(id);
+ // 创建套餐视图对象并复制属性
+ SetmealVO setmealVO = new SetmealVO();
+ BeanUtils.copyProperties(setmeal, setmealVO);
+ // 根据套餐ID查询关联的菜品列表
+ List setmealDishes = setmealDishMapper.getBySetmealId(id);
+ // 将菜品列表设置到套餐视图对象中
+ setmealVO.setSetmealDishes(setmealDishes);
+ // 返回套餐视图对象
+ return setmealVO;
+ }
+
+ @Transactional
+ public void updateWithDish(SetmealDTO setmealDTO) {
+ // 创建套餐对象并复制属性
+ Setmeal setmeal = new Setmeal();
+ BeanUtils.copyProperties(setmealDTO, setmeal);
+ // 更新套餐表中的数据
+ setmealMapper.updateWithDish(setmeal);
+ // 获取套餐ID
+ Long setmealId = setmealDTO.getId();
+ // 删除旧的套餐菜品关系数据
+ setmealDishMapper.deleteBySetmealId(setmealId);
+ // 获取新的套餐菜品列表
+ List setmealDishes = setmealDTO.getSetmealDishes();
+ // 为每个新的菜品设置对应的套餐ID
+ for (SetmealDish setmealDish : setmealDishes) {
+ setmealDish.setSetmealId(setmealDTO.getId());
+ }
+ // 向套餐菜品关系表插入新的数据
+ setmealDishMapper.insertBatch(setmealDishes);
+ }
+
+ @Override
+ public void startOrStop(Integer status, Long id) {
+ // 构建套餐对象并设置状态和ID
+ Setmeal setmeal = Setmeal.builder()
+ .status(status)
+ .id(id)
+ .build();
+ // 更新套餐表中的销售状态
+ setmealMapper.startOrStop(setmeal);
+ }
+
+ /**
+ * 条件查询
+ * @param setmeal 套餐实体对象,用于封装查询条件
+ * @return 符合条件的套餐列表
+ */
+ public List list(Setmeal setmeal) {
+ // 根据条件查询套餐列表
+ List list = setmealMapper.list(setmeal);
+ // 返回查询结果
+ return list;
+ }
+
+ /**
+ * 根据id查询菜品选项
+ * @param id 套餐ID
+ * @return 菜品选项列表
+ */
+ public List getDishItemById(Long id) {
+ // 根据套餐ID查询菜品选项列表
+ return setmealMapper.getDishItemBySetmealId(id);
+ }
+}
diff --git a/sky-server/src/main/resources/mapper/DishFlavorMapper.xml b/sky-server/src/main/resources/mapper/DishFlavorMapper.xml
new file mode 100644
index 0000000..6f2008b
--- /dev/null
+++ b/sky-server/src/main/resources/mapper/DishFlavorMapper.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+ insert into dish_flavor (dish_id, name, value) values
+
+ (#{flavor.dishId},#{flavor.name},#{flavor.value})
+
+
+
+
+ delete from dish_flavor where dish_id in
+
+ #{dishId}
+
+
+
diff --git a/sky-server/src/main/resources/mapper/DishMapper.xml b/sky-server/src/main/resources/mapper/DishMapper.xml
new file mode 100644
index 0000000..bd022c8
--- /dev/null
+++ b/sky-server/src/main/resources/mapper/DishMapper.xml
@@ -0,0 +1,93 @@
+
+
+
+
+
+ insert into dish (name, category_id, price, image, description, create_time, update_time, create_user, update_user, status)
+ values
+ (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
+
+
+
+ delete from dish where id in
+
+ #{id}
+
+
+
+
+
+
+
+ update dish
+
+
+ name = #{name},
+
+
+ category_id = #{categoryId},
+
+
+ price = #{price},
+
+
+ image = #{image},
+
+
+ description = #{description},
+
+
+ status = #{status},
+
+
+ update_time = #{updateTime},
+
+
+ update_user = #{updateUser},
+
+
+ where id = #{id}
+
+
+
+
diff --git a/sky-server/src/main/resources/mapper/SetmealDishMapper.xml b/sky-server/src/main/resources/mapper/SetmealDishMapper.xml
new file mode 100644
index 0000000..41f3d1b
--- /dev/null
+++ b/sky-server/src/main/resources/mapper/SetmealDishMapper.xml
@@ -0,0 +1,29 @@
+
+
+
+
+
+ insert into setmeal_dish(setmeal_id, dish_id, name, price, copies)
+ values
+
+ (#{setmealDish.setmealId},#{setmealDish.dishId},#{setmealDish.name},#{setmealDish.price},#{setmealDish.copies})
+
+
+
+
+ delete from setmeal_dish
+ where setmeal_id in
+
+ #{setmealId}
+
+
+
+
+
diff --git a/sky-server/src/main/resources/mapper/SetmealMapper.xml b/sky-server/src/main/resources/mapper/SetmealMapper.xml
new file mode 100644
index 0000000..cc98f70
--- /dev/null
+++ b/sky-server/src/main/resources/mapper/SetmealMapper.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+ insert into setmeal(category_id, name, price, description, image, create_time, update_time, create_user, update_user,status)
+ values(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser},#{status})
+
+
+ delete from setmeal
+ where id in
+
+ #{id}
+
+
+
+
+
+ update setmeal
+
+ category_id = #{categoryId},
+ name = #{name},
+ price = #{price},
+ status = #{status},
+ description = #{description},
+ image = #{image},
+ update_time = #{updateTime},
+ update_user = #{updateUser}
+
+ where id = #{id}
+
+
+
+
+
+
+