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/3] 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}