diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java index 05af1b2..a7be698 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java @@ -1,9 +1,12 @@ package com.bonus.canteen.core.common.utils; +import com.bonus.common.houqin.constant.GlobalConstants; + import java.time.DayOfWeek; import java.time.LocalDate; import java.time.temporal.TemporalAdjusters; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; public class DateUtil { @@ -27,4 +30,14 @@ public class DateUtil { return dates; } + public static HashMap getDaysInWeekMap() { + LocalDate now = LocalDate.now(); + HashMap dateHashMap = new HashMap<>(); + for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { + LocalDate applyWeek = now.plusDays((long) i); + dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek); + } + return dateHashMap; + } + } 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 5ae6d39..b2c333c 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 @@ -65,9 +65,11 @@ public interface CookRecipeDetailMapper { public List getToDeleteCookRecipeDetailIds4PointDays(@Param("recipeId") Long recipeId, @Param("dateList") List dateList); - public List getToDeleteCookRecipeDetailIds4Daily(Long recipeId); + public List getToDeleteCookRecipeDetailIds4Daily(@Param("recipeId") Long recipeId); - public List getToDeleteCookRecipeDetailIds4Weekly(Long recipeId); + public List getToDeleteCookRecipeDetailIds4WeeklyTemplate(@Param("recipeId") Long recipeId, @Param("applyWeeks") List applyWeeks); + + public List getToDeleteCookRecipeDetailIds4WeeklyDetail(@Param("recipeId")Long recipeId, @Param("dateList") List dateList); 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 3e9ed19..05acd93 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 @@ -242,7 +242,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService { List recipeDateListNew = new ArrayList<>(); if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) { //每日循环 List recipeDetailList = recipeDateList.get(0).getDetailList(); - //新增详情 LocalDate now = LocalDate.now(); for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO(); @@ -251,13 +250,7 @@ public class CookRecipeServiceImpl implements ICookRecipeService { recipeDateListNew.add(cookRecipeDateDTO); } } else if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { //每周循环 - LocalDate now = LocalDate.now(); - HashMap dateHashMap = new HashMap<>(); - for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { - LocalDate applyWeek = now.plusDays((long) i); - dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek); - } - //新增详情 + HashMap dateHashMap = DateUtil.getDaysInWeekMap(); Iterator> iterator = dateHashMap.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = iterator.next(); @@ -269,7 +262,15 @@ public class CookRecipeServiceImpl implements ICookRecipeService { cookRecipeDateDTO.setDetailList(recipeDateDTO.getDetailList()); } } - 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; @@ -335,8 +336,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService { } // 循环周菜谱,删掉指定周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()); + List applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList()); + HashMap dateHashMap = DateUtil.getDaysInWeekMap(); + List dateList = new ArrayList<>(); + for (Long applyWeek : applyWeeks) { + dateList.add(dateHashMap.get(applyWeek.intValue())); + } + //模板数据 + cookRecipeDetailIds.addAll(cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4WeeklyTemplate(cookRecipeDTO.getRecipeId(), applyWeeks)); + //详情数据 + cookRecipeDetailIds.addAll(cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4WeeklyDetail(cookRecipeDTO.getRecipeId(), dateList)); } if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) { Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); 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 a90e06f..d151e29 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 @@ -131,18 +131,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where cr.recipe_id = #{recipeId} and cr.recipe_type = 2 and crd.detail_type = 2 and crd.apply_date >= NOW()-1 - 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} + + +