From edde32e8e2cf74cbfdfcba0be71d67d306ed5aff Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Fri, 30 May 2025 14:57:28 +0800 Subject: [PATCH 1/7] test --- .../cook/mapper/CookRecipeDetailMapper.java | 8 +++- .../service/impl/CookRecipeServiceImpl.java | 38 ++++++++++++------- .../mapper/cook/CookRecipeDetailMapper.xml | 17 +++++---- .../mapper/cook/CookRecipeDishesMapper.xml | 4 +- 4 files changed, 43 insertions(+), 24 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java index 5bf420f..bd0cf5c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeDetailMapper.java @@ -1,7 +1,9 @@ package com.bonus.canteen.core.cook.mapper; +import java.time.LocalDate; import java.util.List; import com.bonus.canteen.core.cook.domain.CookRecipeDetail; +import org.apache.ibatis.annotations.Param; /** * 菜品计划详情信息Mapper接口 @@ -60,5 +62,9 @@ public interface CookRecipeDetailMapper { public List getAllCookRecipeDetailIds(Long[] recipeIds); - public List getToDeleteCookRecipeDetailIds(Long recipeId); + public List getToDeleteCookRecipeDetailIds4PointDays(@Param("recipeId") Long recipeId, @Param("dateList") List dateList); + + public List getToDeleteCookRecipeDetailIds4Daily(Long recipeId); + + public List getToDeleteCookRecipeDetailIds4Weekly(Long recipeId); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index 1a33cdc..3e9ed19 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -201,25 +201,14 @@ public class CookRecipeServiceImpl implements ICookRecipeService { throw new ServiceException("该菜谱名称已存在,请重新输入"); } int count = cookRecipeMapper.insertCookRecipe(cookRecipeDTO); //插入菜谱 - createRecipeDetails(cookRecipeDTO, true); + createRecipeDetails(cookRecipeDTO); return count; } catch (Exception e) { throw new ServiceException(e.getMessage()); } } - private void createRecipeDetails(CookRecipeDTO cookRecipeDTO, boolean isCreate) { - // 更新菜谱时, - // 指定日期菜谱,删掉指定日期的菜谱 - // 循环菜谱,删掉模板数据 + 今日开始的详情数据 - if (!isCreate) { - List cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds(cookRecipeDTO.getRecipeId()); - if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) { - Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); - cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray); - cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray); - } - } + private void createRecipeDetails(CookRecipeDTO cookRecipeDTO) { // 插入指定日期、日循环摸板、周循环模板 if (!CollectionUtils.isEmpty(cookRecipeDTO.getRecipeDateList())) { for (CookRecipeDateDTO recipeDateDTO : cookRecipeDTO.getRecipeDateList()) { @@ -334,7 +323,28 @@ public class CookRecipeServiceImpl implements ICookRecipeService { throw new ServiceException("该菜谱名称已存在,请重新输入"); } int count = cookRecipeMapper.updateCookRecipe(cookRecipeDTO); - createRecipeDetails(cookRecipeDTO, false); + List cookRecipeDetailIds = new ArrayList<>(); + // 更新菜谱时,指定日期菜谱,删掉指定日期的菜谱 + if (RecipeTypeEnum.POINT_DATE.key().equals(cookRecipeDTO.getRecipeType())) { + List dateList = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyDate).collect(Collectors.toList()); + cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4PointDays(cookRecipeDTO.getRecipeId(), dateList); + } + // 循环日菜谱,删掉模板数据 + 今日开始的详情数据 + if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType())) { + cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4Daily(cookRecipeDTO.getRecipeId()); + } + // 循环周菜谱,删掉指定周x模板数据 + 今日开始的周x的详情数据 + if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { + List weekDayList = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList()); + cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4Weekly(cookRecipeDTO.getRecipeId()); + } + if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) { + Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); + cookRecipeDishesMapper.deleteCookRecipeDishesByCookRecipeDetailIds(cookRecipeDetailArray); + cookRecipeDetailMapper.deleteCookRecipeDetailByRecipeDetailIds(cookRecipeDetailArray); + } + // 重新创建菜谱 + createRecipeDetails(cookRecipeDTO); return count; } catch (Exception e) { throw new ServiceException(e.getMessage()); diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml index e589bdf..e418f60 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeDetailMapper.xml @@ -107,14 +107,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT distinct(crd.recipe_detail_id) FROM cook_recipe_detail crd - left join cook_recipe cr ON cr.recipe_id = crd.recipe_id - where cr.recipe_id = #{recipeId} and cr.recipe_type = 1 and crd.apply_date >= NOW()-1 - - UNION + left join cook_recipe cr ON cr.recipe_id = crd.recipe_id + where cr.recipe_id = #{recipeId} and cr.recipe_type = 1 and crd.apply_date in + + #{applyDate} + + + - UNION - + + cr.del_flag = 0 and cr.recipe_name like concat('%', #{recipeName}, '%') and cr.recipe_type = #{recipeType} and cr.stall_id = #{stallId} From 8f1dc34334a66a264c97f76ef6a93d16342312fa Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Fri, 30 May 2025 16:46:33 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E8=8F=9C=E8=B0=B1=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/mapper/cook/CookRecipeMapper.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml index b7de7d9..4d6c13d 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml @@ -420,14 +420,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - SELECT distinct(crd.recipe_detail_id) FROM cook_recipe_detail crd left join cook_recipe cr ON cr.recipe_id = crd.recipe_id - where cr.recipe_id = #{recipeId} and cr.recipe_type = 3 and crd.detail_type = 1 - - UNION + where cr.recipe_id = #{recipeId} and cr.recipe_type = 3 and crd.detail_type = 1 and crd.apply_week in + + #{applyWeek} + + + - + + del_flag = '0' and area_name like concat('%', #{areaName}, '%') and parent_id = #{parentId} and manager = #{manager} @@ -37,12 +38,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml index 2423238..f28116c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/basic/BasicCanteenMapper.xml @@ -40,7 +40,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - where bc.canteen_id = #{canteenId} and bc.del_flag = 0 + where bc.canteen_id = #{canteenId} and bc.del_flag = '0' - + + bs.del_flag = '0' and bs.stall_name like concat('%', #{stallName}, '%') and bs.area_id = #{areaId} and bs.canteen_id = #{canteenId} @@ -65,12 +66,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - cr.del_flag = 0 + ba.del_flag = '0' and bc.del_flag = '0' and bs.del_flag = '0' and cr.del_flag = '0' and cr.recipe_name like concat('%', #{recipeName}, '%') and cr.recipe_type = #{recipeType} and cr.stall_id = #{stallId} @@ -79,7 +79,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - AND recipe_id in + AND cr.recipe_id in #{item} @@ -237,12 +237,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" @@ -382,12 +382,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" basic_stall t1 LEFT JOIN basic_canteen t2 ON t1.canteen_id = t2.canteen_id LEFT JOIN basic_area t3 ON t2.area_id = t3.area_id - where 1=1 + where t1.del_flag = '0' and t2.del_flag = '0' and t3.del_flag = '0' AND EXISTS ( select null from cook_recipe_bind_app t4 INNER JOIN cook_recipe t5 on t4.recipe_id = t5.recipe_id - where t5.stall_id = t1.stall_id AND t4.bind_type = #{bindType} + where t5.del_flag = '0' and t5.stall_id = t1.stall_id AND t4.bind_type = #{bindType} and t5.recipe_name like #{recipeName} ) From 070bf9c495dbc3b629b3119909ec6f60d010d1d7 Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Sat, 31 May 2025 10:51:27 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E8=8F=9C=E8=B0=B1=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/CookRecipeServiceImpl.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java index f72a843..653fb25 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/service/impl/CookRecipeServiceImpl.java @@ -241,11 +241,13 @@ public class CookRecipeServiceImpl implements ICookRecipeService { if (!CollectionUtils.isEmpty(cookRecipeDTO.getRecipeDateList())) { for (CookRecipeDateDTO recipeDateDTO : cookRecipeDTO.getRecipeDateList()) { List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 - continue; + if (!CollectionUtils.isEmpty(detailList)) { + for (CookRecipeDetailDTO detailDTO : detailList) { + if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 + continue; + } + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } } } @@ -254,11 +256,13 @@ public class CookRecipeServiceImpl implements ICookRecipeService { if (!CollectionUtils.isEmpty(generatedRecipeDateList)) { for (CookRecipeDateDTO recipeDateDTO : generatedRecipeDateList) { List detailList = recipeDateDTO.getDetailList(); - for (CookRecipeDetailDTO detailDTO : detailList) { - if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 - continue; + if (!CollectionUtils.isEmpty(detailList)) { + for (CookRecipeDetailDTO detailDTO : detailList) { + if (CollectionUtils.isEmpty(detailDTO.getDishesList())) { //不插入空数据 + continue; + } + insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } - insertDetailAndDishes(cookRecipeDTO, recipeDateDTO, detailDTO); } } } @@ -293,15 +297,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } } recipeDateListNew.add(cookRecipeDateDTO); -// if (!CollectionUtils.isEmpty(cookRecipeDateDTO.getDetailList())) { -// List detailList = cookRecipeDateDTO.getDetailList(); -// for (CookRecipeDetailDTO detail : detailList) { -// if (!CollectionUtils.isEmpty(detail.getDishesList())) { -// recipeDateListNew.add(cookRecipeDateDTO); -// } -// break; -// } -// } } } return recipeDateListNew;