菜谱管理

This commit is contained in:
sxu 2025-05-30 18:26:40 +08:00
parent 8f1dc34334
commit 33373d50f9
4 changed files with 48 additions and 18 deletions

View File

@ -1,9 +1,12 @@
package com.bonus.canteen.core.common.utils; package com.bonus.canteen.core.common.utils;
import com.bonus.common.houqin.constant.GlobalConstants;
import java.time.DayOfWeek; import java.time.DayOfWeek;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters; import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
public class DateUtil { public class DateUtil {
@ -27,4 +30,14 @@ public class DateUtil {
return dates; return dates;
} }
public static HashMap<Integer, LocalDate> getDaysInWeekMap() {
LocalDate now = LocalDate.now();
HashMap<Integer, LocalDate> 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;
}
} }

View File

@ -65,9 +65,11 @@ public interface CookRecipeDetailMapper {
public List<Long> getToDeleteCookRecipeDetailIds4PointDays(@Param("recipeId") Long recipeId, @Param("dateList") List<LocalDate> dateList); public List<Long> getToDeleteCookRecipeDetailIds4PointDays(@Param("recipeId") Long recipeId, @Param("dateList") List<LocalDate> dateList);
public List<Long> getToDeleteCookRecipeDetailIds4Daily(Long recipeId); public List<Long> getToDeleteCookRecipeDetailIds4Daily(@Param("recipeId") Long recipeId);
public List<Long> getToDeleteCookRecipeDetailIds4Weekly(Long recipeId); public List<Long> getToDeleteCookRecipeDetailIds4WeeklyTemplate(@Param("recipeId") Long recipeId, @Param("applyWeeks") List<Long> applyWeeks);
public List<Long> getToDeleteCookRecipeDetailIds4WeeklyDetail(@Param("recipeId")Long recipeId, @Param("dateList") List<LocalDate> dateList);
List<CookRecipeDetail> getCookRecipeDetailLTemplate(@Param("recipeId") Long recipeId, @Param("detailType") String detailType); List<CookRecipeDetail> getCookRecipeDetailLTemplate(@Param("recipeId") Long recipeId, @Param("detailType") String detailType);

View File

@ -242,7 +242,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
List<CookRecipeDateDTO> recipeDateListNew = new ArrayList<>(); List<CookRecipeDateDTO> recipeDateListNew = new ArrayList<>();
if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) { //每日循环 if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) { //每日循环
List<CookRecipeDetailDTO> recipeDetailList = recipeDateList.get(0).getDetailList(); List<CookRecipeDetailDTO> recipeDetailList = recipeDateList.get(0).getDetailList();
//新增详情
LocalDate now = LocalDate.now(); LocalDate now = LocalDate.now();
for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) { for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) {
CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO(); CookRecipeDateDTO cookRecipeDateDTO = new CookRecipeDateDTO();
@ -251,13 +250,7 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
recipeDateListNew.add(cookRecipeDateDTO); recipeDateListNew.add(cookRecipeDateDTO);
} }
} else if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { //每周循环 } else if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { //每周循环
LocalDate now = LocalDate.now(); HashMap<Integer, LocalDate> dateHashMap = DateUtil.getDaysInWeekMap();
HashMap<Integer, LocalDate> dateHashMap = new HashMap<>();
for (int i = 0; i < GlobalConstants.WEEK_DAYS; ++i) {
LocalDate applyWeek = now.plusDays((long) i);
dateHashMap.put(applyWeek.getDayOfWeek().getValue(), applyWeek);
}
//新增详情
Iterator<Map.Entry<Integer, LocalDate>> iterator = dateHashMap.entrySet().iterator(); Iterator<Map.Entry<Integer, LocalDate>> iterator = dateHashMap.entrySet().iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<Integer, LocalDate> entry = iterator.next(); Map.Entry<Integer, LocalDate> entry = iterator.next();
@ -269,8 +262,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
cookRecipeDateDTO.setDetailList(recipeDateDTO.getDetailList()); cookRecipeDateDTO.setDetailList(recipeDateDTO.getDetailList());
} }
} }
if (!CollectionUtils.isEmpty(cookRecipeDateDTO.getDetailList())) {
List<CookRecipeDetailDTO> detailList = cookRecipeDateDTO.getDetailList();
for (CookRecipeDetailDTO detail : detailList) {
if (!CollectionUtils.isEmpty(detail.getDishesList())) {
recipeDateListNew.add(cookRecipeDateDTO); recipeDateListNew.add(cookRecipeDateDTO);
} }
break;
}
}
}
} }
return recipeDateListNew; return recipeDateListNew;
} }
@ -335,8 +336,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
} }
// 循环周菜谱删掉指定周x模板数据 + 今日开始的周x的详情数据 // 循环周菜谱删掉指定周x模板数据 + 今日开始的周x的详情数据
if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) { if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) {
List<Long> weekDayList = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList()); List<Long> applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList());
cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4Weekly(cookRecipeDTO.getRecipeId()); HashMap<Integer, LocalDate> dateHashMap = DateUtil.getDaysInWeekMap();
List<LocalDate> 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)) { if (!CollectionUtils.isEmpty(cookRecipeDetailIds)) {
Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new); Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new);

View File

@ -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 where cr.recipe_id = #{recipeId} and cr.recipe_type = 2 and crd.detail_type = 2 and crd.apply_date >= NOW()-1
</select> </select>
<select id="getToDeleteCookRecipeDetailIds4Weekly" parameterType="Long" resultType="Long"> <select id="getToDeleteCookRecipeDetailIds4WeeklyTemplate" parameterType="Long" resultType="Long">
SELECT distinct(crd.recipe_detail_id) SELECT distinct(crd.recipe_detail_id)
FROM cook_recipe_detail crd FROM cook_recipe_detail crd
left join cook_recipe cr ON cr.recipe_id = crd.recipe_id 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 where cr.recipe_id = #{recipeId} and cr.recipe_type = 3 and crd.detail_type = 1 and crd.apply_week in
<foreach item="applyWeek" collection="applyWeeks" open="(" separator="," close=")">
UNION #{applyWeek}
</foreach>
</select>
<select id="getToDeleteCookRecipeDetailIds4WeeklyDetail" resultType="Long">
SELECT distinct(crd.recipe_detail_id) SELECT distinct(crd.recipe_detail_id)
FROM cook_recipe_detail crd FROM cook_recipe_detail crd
left join cook_recipe cr ON cr.recipe_id = crd.recipe_id 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 = 2 and crd.apply_date >= NOW()-1 where cr.recipe_id = #{recipeId} and cr.recipe_type = 3 and crd.detail_type = 2 and crd.apply_date in
<foreach item="applyDate" collection="dateList" open="(" separator="," close=")">
#{applyDate}
</foreach>
</select> </select>
<select id="getCookRecipeDetailLTemplate" resultMap="CookRecipeDetailResult"> <select id="getCookRecipeDetailLTemplate" resultMap="CookRecipeDetailResult">