菜谱管理
This commit is contained in:
parent
8f1dc34334
commit
33373d50f9
|
|
@ -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<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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,9 +65,11 @@ public interface CookRecipeDetailMapper {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
|||
|
|
@ -242,7 +242,6 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
|||
List<CookRecipeDateDTO> recipeDateListNew = new ArrayList<>();
|
||||
if (RecipeTypeEnum.DAILY.key().equals(cookRecipeDTO.getRecipeType()) && Objects.nonNull(recipeDateList.get(0))) { //每日循环
|
||||
List<CookRecipeDetailDTO> 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<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);
|
||||
}
|
||||
//新增详情
|
||||
HashMap<Integer, LocalDate> dateHashMap = DateUtil.getDaysInWeekMap();
|
||||
Iterator<Map.Entry<Integer, LocalDate>> iterator = dateHashMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<Integer, LocalDate> entry = iterator.next();
|
||||
|
|
@ -269,8 +262,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
|||
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);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return recipeDateListNew;
|
||||
}
|
||||
|
|
@ -335,8 +336,16 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
|
|||
}
|
||||
// 循环周菜谱,删掉指定周x模板数据 + 今日开始的周x的详情数据
|
||||
if (RecipeTypeEnum.WEEKLY.key().equals(cookRecipeDTO.getRecipeType())) {
|
||||
List<Long> weekDayList = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList());
|
||||
cookRecipeDetailIds = cookRecipeDetailMapper.getToDeleteCookRecipeDetailIds4Weekly(cookRecipeDTO.getRecipeId());
|
||||
List<Long> applyWeeks = cookRecipeDTO.getRecipeDateList().stream().map(CookRecipeDateDTO::getApplyWeek).collect(Collectors.toList());
|
||||
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)) {
|
||||
Long[] cookRecipeDetailArray = cookRecipeDetailIds.stream().toArray(Long[]::new);
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
||||
<select id="getToDeleteCookRecipeDetailIds4Weekly" parameterType="Long" resultType="Long">
|
||||
<select id="getToDeleteCookRecipeDetailIds4WeeklyTemplate" parameterType="Long" resultType="Long">
|
||||
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
|
||||
<foreach item="applyWeek" collection="applyWeeks" open="(" separator="," close=")">
|
||||
#{applyWeek}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<select id="getToDeleteCookRecipeDetailIds4WeeklyDetail" resultType="Long">
|
||||
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 = 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 id="getCookRecipeDetailLTemplate" resultMap="CookRecipeDetailResult">
|
||||
|
|
|
|||
Loading…
Reference in New Issue