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 446230b..5ae6d39 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,5 +1,6 @@ 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; @@ -61,7 +62,13 @@ 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); List getCookRecipeDetailLTemplate(@Param("recipeId") Long recipeId, @Param("detailType") String detailType); + } 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 3d65022..a90e06f 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}