循环菜谱详情

This commit is contained in:
sxu 2025-05-29 16:43:52 +08:00
parent d26e771078
commit 04eba0757c
6 changed files with 133 additions and 10 deletions

View File

@ -0,0 +1,30 @@
package com.bonus.canteen.core.common.utils;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;
public class DateUtil {
public static List<LocalDate> getLastWeekDate() {
List<LocalDate> objects = new ArrayList<>();
LocalDate sunday = LocalDate.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
LocalDate now = LocalDate.now();
for (LocalDate date = now; date.isBefore(sunday) || date.isEqual(sunday); date = date.plusDays(1L)) {
objects.add(date);
}
return objects;
}
public static List<LocalDate> getLastWeek() {
List<LocalDate> dates = new ArrayList<>();
LocalDate now = LocalDate.now();
for (int i = 0; i < 7; ++i) {
dates.add(now.plusDays(i));
}
return dates;
}
}

View File

@ -1,6 +1,9 @@
package com.bonus.canteen.core.cook.domain;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.bonus.common.core.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
@ -67,11 +70,16 @@ public class CookRecipe extends BaseEntity {
@Excel(name = "到期时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date expireDate;
private int dishesCount;
/**
* 删除标志0代表存在 2代表删除
*/
private String delFlag;
private int dishesCount;
@ApiModelProperty("已排菜日期")
private List<LocalDate> applyDateList;
@ApiModelProperty("已排菜日期(月-日)")
private List<String> applyDateStringList;
}

View File

@ -8,6 +8,7 @@ import com.bonus.canteen.core.cook.domain.CookRecipe;
import com.bonus.canteen.core.cook.dto.CookRecipeDTO;
import com.bonus.canteen.core.cook.dto.CookRecipeDetailDTO;
import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO;
import com.bonus.canteen.core.cook.vo.CookRecipeDishesCountVO;
import com.bonus.canteen.core.cook.vo.CookRecipeVO;
import com.bonus.canteen.core.cook.vo.StallAndRecipeBindVO;
import org.apache.ibatis.annotations.Param;
@ -41,6 +42,10 @@ public interface CookRecipeMapper {
public int getDishesCount4Recycle(Long recipeId);
List<CookRecipeDishesCountVO> getDishesCountByRecipeIds(@Param("recipeIds") List<Long> recipeIds);
List<CookRecipeDetailVO> selectApplyDateListByRecipeId(@Param("applyDate") LocalDate applyDate, @Param("recipeIds") List<Long> recipeIds);
List<CookRecipeDetailVO> selectRecipeDetailList(@Param("recipeId") Long recipeId, @Param("applyDate") LocalDate applyDate);
List<CookRecipeDetailVO> getRecipeDetail(@Param("params") CookRecipeDetailDTO dto);

View File

@ -1,13 +1,19 @@
package com.bonus.canteen.core.cook.service.impl;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.bonus.canteen.core.common.utils.DateUtil;
import com.bonus.canteen.core.common.utils.MqUtil;
import com.bonus.canteen.core.cook.domain.CookAppRecipe;
import com.bonus.canteen.core.cook.domain.CookRecipeDetail;
@ -23,10 +29,12 @@ import com.bonus.canteen.core.cook.vo.*;
import com.bonus.canteen.core.user.domain.DeviceMqPersonalUpdateMessageDTO;
import com.bonus.common.core.exception.ServiceException;
import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.houqin.constant.GlobalConstants;
import com.bonus.common.houqin.mq.constant.LeMqConstant;
import com.bonus.common.houqin.utils.LeBeanUtil;
import com.bonus.common.security.utils.SecurityUtils;
import com.google.common.collect.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -132,13 +140,44 @@ public class CookRecipeServiceImpl implements ICookRecipeService {
@Override
public List<CookRecipe> selectCookRecipeList(CookRecipe cookRecipe) {
List<CookRecipe> list = cookRecipeMapper.selectCookRecipeList(cookRecipe);
for (CookRecipe recipe : list) {
if (1 == recipe.getRecipeType()) {
recipe.setDishesCount(cookRecipeMapper.getDishesCount4PointDates(recipe.getRecipeId()));
} else {
recipe.setDishesCount(cookRecipeMapper.getDishesCount4Recycle(recipe.getRecipeId()));
}
// for (CookRecipe recipe : list) {
// if (1 == recipe.getRecipeType()) {
// recipe.setDishesCount(cookRecipeMapper.getDishesCount4PointDates(recipe.getRecipeId()));
// } else {
// recipe.setDishesCount(cookRecipeMapper.getDishesCount4Recycle(recipe.getRecipeId()));
// }
// }
List<LocalDate> lastWeekDate = DateUtil.getLastWeekDate();
List<Long> recipeIds = list.stream().map(CookRecipe::getRecipeId).collect(Collectors.toList());
List<CookRecipeDishesCountVO> dishesCountByRecipeIdsList = cookRecipeMapper.getDishesCountByRecipeIds(recipeIds);
Map<Long, Integer> dishesCountByRecipeIds = dishesCountByRecipeIdsList.stream().collect(Collectors.toMap(CookRecipeDishesCountVO::getRecipeId, CookRecipeDishesCountVO::getCount));
List<CookRecipeDetailVO> recipeDatesList = this.cookRecipeMapper.selectApplyDateListByRecipeId(LocalDate.now(), recipeIds);
Map<Long, TreeSet<LocalDate>> recipeDates = recipeDatesList.stream().collect(Collectors.groupingBy(CookRecipeDetailVO::getRecipeId, Collectors.mapping(CookRecipeDetailVO::getApplyDate, Collectors.toCollection(TreeSet::new))));
if (list.isEmpty()) {
return new ArrayList<>();
}
list.forEach(r -> {
Long recipeId = r.getRecipeId();
r.setDishesCount(dishesCountByRecipeIds.getOrDefault(recipeId, 0));
Set<LocalDate> applyDateList = recipeDates.getOrDefault(recipeId, new TreeSet<>());
Object finalDate;
if (ObjectUtil.equal(r.getRecipeType(), 3)) {
Stream<LocalDate> localDateStream = lastWeekDate.stream();
Objects.requireNonNull(applyDateList);
finalDate = localDateStream.filter(applyDateList::contains).collect(Collectors.toList());
} else if (ObjectUtil.equal(r.getRecipeType(), 2)) {
finalDate = DateUtil.getLastWeek();
} else {
finalDate = new ArrayList<>(applyDateList);
}
List<String> applyDateStringList = Lists.newArrayList();
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd");
((List) finalDate).forEach(d -> {
applyDateStringList.add(dateTimeFormatter.format((TemporalAccessor) d));
});
r.setApplyDateList((List) finalDate);
r.setApplyDateStringList(applyDateStringList);
});
return list;
}

View File

@ -0,0 +1,11 @@
package com.bonus.canteen.core.cook.vo;
import lombok.Data;
import lombok.ToString;
@Data
@ToString
public class CookRecipeDishesCountVO {
private Long recipeId;
private Integer count;
}

View File

@ -84,8 +84,38 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
(select recipe_detail_id from cook_recipe_detail where recipe_id = #{recipeId} and detail_type = 1)
</select>
<select id="getDishesCountByRecipeIds" resultType="com.bonus.canteen.core.cook.vo.CookRecipeDishesCountVO">
SELECT
mrd.recipe_id,count(DISTINCT(md.base_dishes_id)) as count
FROM
cook_recipe_detail mrd
LEFT JOIN cook_recipe_dishes mrdd ON mrd.recipe_detail_id = mrdd.recipe_detail_id
LEFT JOIN cook_dishes md ON md.dishes_id = mrdd.dishes_id
where
mrd.apply_date >= curdate()
<if test="recipeIds !=null and recipeIds.size()>0">
AND mrd.recipe_id in
<foreach collection="recipeIds" separator="," open="(" close=")" item="item">
#{item}
</foreach>
</if>
GROUP BY mrd.recipe_id
</select>
<select id="selectApplyDateListByRecipeId" resultType="com.bonus.canteen.core.cook.vo.CookRecipeDetailVO">
SELECT recipe_id as recipeId, apply_date as applyDate
FROM cook_recipe_detail
WHERE apply_date >= #{applyDate}
<if test="recipeIds !=null and recipeIds.size()>0">
AND recipe_id in
<foreach collection="recipeIds" open="(" close=")" item="item" separator=",">
#{item}
</foreach>
</if>
</select>
<!-- 获取指定日期菜谱详情 -->
<select id="selectRecipeDetailList" resultType="com.bonus.canteen.core.cook.vo.CookRecipeDetailVO">
<select id="selectRecipeDetailList" resultMap="cookRecipeDetailVO">
select crd.mealtime_type,
crd.recipe_detail_id,
cd.dishes_id,
@ -118,7 +148,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by crdd.dishes_id
</select>
<select id="getRecipeDetail" resultType="com.bonus.canteen.core.cook.vo.CookRecipeDetailVO">
<select id="getRecipeDetail" resultMap="cookRecipeDetailVO">
select DISTINCT
mrd.mealtime_type,
mrd.recipe_detail_id,