From 04eba0757cbbb422c52b4ae4d78f8e1bc82d2ffc Mon Sep 17 00:00:00 2001 From: sxu <602087911@qq.com> Date: Thu, 29 May 2025 16:43:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AA=E7=8E=AF=E8=8F=9C=E8=B0=B1=E8=AF=A6?= =?UTF-8?q?=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../canteen/core/common/utils/DateUtil.java | 30 +++++++++++ .../canteen/core/cook/domain/CookRecipe.java | 12 ++++- .../core/cook/mapper/CookRecipeMapper.java | 5 ++ .../service/impl/CookRecipeServiceImpl.java | 51 ++++++++++++++++--- .../core/cook/vo/CookRecipeDishesCountVO.java | 11 ++++ .../mapper/cook/CookRecipeMapper.xml | 34 ++++++++++++- 6 files changed, 133 insertions(+), 10 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDishesCountVO.java 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 new file mode 100644 index 0000000..05af1b2 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/common/utils/DateUtil.java @@ -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 getLastWeekDate() { + List 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 getLastWeek() { + List dates = new ArrayList<>(); + LocalDate now = LocalDate.now(); + for (int i = 0; i < 7; ++i) { + dates.add(now.plusDays(i)); + } + return dates; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookRecipe.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookRecipe.java index a946f1a..750ed13 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookRecipe.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/domain/CookRecipe.java @@ -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 applyDateList; + + @ApiModelProperty("已排菜日期(月-日)") + private List applyDateStringList; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java index 84a6ff5..2ad71dc 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/mapper/CookRecipeMapper.java @@ -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 getDishesCountByRecipeIds(@Param("recipeIds") List recipeIds); + + List selectApplyDateListByRecipeId(@Param("applyDate") LocalDate applyDate, @Param("recipeIds") List recipeIds); + List selectRecipeDetailList(@Param("recipeId") Long recipeId, @Param("applyDate") LocalDate applyDate); List getRecipeDetail(@Param("params") CookRecipeDetailDTO dto); 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 62887f6..8d8c659 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 @@ -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 selectCookRecipeList(CookRecipe cookRecipe) { List 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 lastWeekDate = DateUtil.getLastWeekDate(); + List recipeIds = list.stream().map(CookRecipe::getRecipeId).collect(Collectors.toList()); + List dishesCountByRecipeIdsList = cookRecipeMapper.getDishesCountByRecipeIds(recipeIds); + Map dishesCountByRecipeIds = dishesCountByRecipeIdsList.stream().collect(Collectors.toMap(CookRecipeDishesCountVO::getRecipeId, CookRecipeDishesCountVO::getCount)); + List recipeDatesList = this.cookRecipeMapper.selectApplyDateListByRecipeId(LocalDate.now(), recipeIds); + Map> 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 applyDateList = recipeDates.getOrDefault(recipeId, new TreeSet<>()); + Object finalDate; + if (ObjectUtil.equal(r.getRecipeType(), 3)) { + Stream 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 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; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDishesCountVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDishesCountVO.java new file mode 100644 index 0000000..c19b05a --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/cook/vo/CookRecipeDishesCountVO.java @@ -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; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml index af9438f..fe76f09 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/cook/CookRecipeMapper.xml @@ -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 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 DISTINCT mrd.mealtime_type, mrd.recipe_detail_id,