订单管理

This commit is contained in:
gaowdong 2025-06-04 15:07:48 +08:00
parent cd6ec9e759
commit a3c6f9d218
5 changed files with 62 additions and 84 deletions

View File

@ -2,13 +2,19 @@ package com.bonus.canteen.core.order.domain;
import lombok.Data;
import java.time.LocalDate;
/**
* @author Bonus
*/
@Data
public class CookDishCheckDTO {
/** 食堂id */
private Long canteenId;
/** 档口id */
private Long stallId;
/** 供应日期 */
private String applyDate;
private Long recipeId;
private LocalDate applyDate;
/** 适用类型 */
private Integer applyType;
}

View File

@ -6,6 +6,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.time.LocalDate;
import java.util.Date;
/**
@ -64,7 +65,7 @@ public class OrderCart extends BaseEntity
/** 订单日期 yyyy-MM-dd */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate;
private LocalDate orderDate;
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")
@ -180,14 +181,12 @@ public class OrderCart extends BaseEntity
return detailType;
}
public void setOrderDate(Date orderDate)
{
this.orderDate = orderDate;
public LocalDate getOrderDate() {
return orderDate;
}
public Date getOrderDate()
{
return orderDate;
public void setOrderDate(LocalDate orderDate) {
this.orderDate = orderDate;
}
public void setMealtimeType(Integer mealtimeType)

View File

@ -5,6 +5,7 @@ import com.bonus.common.core.web.domain.BaseEntity;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.LocalDate;
import java.util.Date;
/**
@ -63,7 +64,7 @@ public class OrderCartVO extends BaseEntity
/** 订单日期 yyyy-MM-dd */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate;
private LocalDate orderDate;
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")

View File

@ -18,27 +18,20 @@ import java.util.*;
@Component
public class MenuModule {
@Autowired
private ICookH5Service cookH5Service;
private ICookRecipeService cookRecipeService;
public Map<Integer, List<CookH5ReserveRecipeDishesVO>> getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) {
CookH5ReserveRecipeDTO cookH5ReserveRecipeDTO = new CookH5ReserveRecipeDTO();
cookH5ReserveRecipeDTO.setApplyDate(LocalDate.parse(cookDishCheckDTO.getApplyDate()));
cookH5ReserveRecipeDTO.setRecipeId(cookDishCheckDTO.getRecipeId());
public AllocRecipeStallVO getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) {
AllocRecipeStallDTO allocRecipeStallDTO = new AllocRecipeStallDTO();
allocRecipeStallDTO.setApplyDate(cookDishCheckDTO.getApplyDate());
allocRecipeStallDTO.setCanteenId(cookDishCheckDTO.getCanteenId());
allocRecipeStallDTO.setStallId(cookDishCheckDTO.getStallId());
allocRecipeStallDTO.setKey(cookDishCheckDTO.getApplyType());
Map<Integer, List<CookH5ReserveRecipeDishesVO>> mealTimeTypeMap = new HashMap<>();
List<CookH5ReserveRecipeDetailsVO> cookRecipeList = cookH5Service.getReserveRecipeDetailList(cookH5ReserveRecipeDTO);
if (CollUtil.isNotEmpty(cookRecipeList)) {
for (CookH5ReserveRecipeDetailsVO cookRecipeDetailVO : cookRecipeList) {
if(Objects.nonNull(cookRecipeDetailVO.getMealtimeType()) && CollUtil.isNotEmpty(cookRecipeDetailVO.getTypeList())) {
List<CookH5ReserveRecipeDishesVO> allDishesList = new ArrayList<>();
for(CookH5ReserveRecipeTypeVO typeVO : cookRecipeDetailVO.getTypeList()) {
allDishesList.addAll(typeVO.getDishesList());
}
mealTimeTypeMap.put(cookRecipeDetailVO.getMealtimeType(), allDishesList);
}
}
List<AllocRecipeStallVO> cookRecipeList = cookRecipeService.selectCookRecipeList4Current(allocRecipeStallDTO);
if (CollUtil.isNotEmpty(cookRecipeList) && cookRecipeList.size() == 1) {
return cookRecipeList.get(0);
}else {
throw new ServiceException("菜谱信息异常");
}
return mealTimeTypeMap;
}
}

View File

@ -3,10 +3,7 @@ package com.bonus.canteen.core.order.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum;
import com.bonus.canteen.core.cook.vo.CookH5CurrentDishesDetailVO;
import com.bonus.canteen.core.cook.vo.CookH5ReserveRecipeDishesVO;
import com.bonus.canteen.core.cook.vo.CookH5ReserveRecipeTypeVO;
import com.bonus.canteen.core.cook.vo.CookRecipeDishesVO;
import com.bonus.canteen.core.cook.vo.*;
import com.bonus.canteen.core.order.domain.CookDishCheckDTO;
import com.bonus.canteen.core.order.domain.OrderCart;
import com.bonus.canteen.core.order.domain.param.OrderCartQueryParam;
@ -22,6 +19,7 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.*;
import java.util.stream.Collectors;
@ -70,62 +68,44 @@ public class OrderCartServiceImpl implements IOrderCartService
if (CollUtil.isEmpty(orderCartList)) {
return new ArrayList<>();
}
Map<String, List<OrderCart>> groupedByOrderDate = orderCartList.stream()
.collect(Collectors.groupingBy(cart -> DateUtil.format(cart.getOrderDate(), "yyyy-MM-dd")));
List<OrderCartVO> orderCartVOList = new ArrayList<>();
for (Map.Entry<String, List<OrderCart>> entry : groupedByOrderDate.entrySet()) {
String orderDateStr = entry.getKey();
List<OrderCart> carts = entry.getValue();
String filteredOrderDate = orderCartQueryParam.getMenuDateList().stream().filter(orderDate -> orderDate.equals(orderDateStr))
.findFirst().orElse(null);
CookDishCheckDTO cookDishCheckDTO = new CookDishCheckDTO();
Optional<Long> maxRecipeId = carts.stream()
.sorted(Comparator.comparing(OrderCart::getCartId).reversed())
.map(OrderCart::getRecipeId)
.findFirst();
if (maxRecipeId.isPresent()) {
cookDishCheckDTO.setRecipeId(maxRecipeId.get());
} else {
continue;
}
cookDishCheckDTO.setApplyDate(orderDateStr);
Map<Integer, List<CookH5ReserveRecipeDishesVO>> cookRecipeDishMap = new HashMap<>();
try{
cookRecipeDishMap = menuModule.getMenuRecipeDish(cookDishCheckDTO);
}catch (Exception ex) {
log.info("菜单数据获取失败:{}", ex.getMessage(), ex);
}
for (OrderCart shoppingCart : carts) {
OrderCartVO shoppingCartVO = convertToOrderCartVO(shoppingCart, cookRecipeDishMap, cookDishCheckDTO.getRecipeId());
if(filteredOrderDate == null) {
shoppingCartVO.setIsValid(0);
}
orderCartVOList.add(shoppingCartVO);
}
}
return orderCartVOList;
}
private OrderCartVO convertToOrderCartVO(OrderCart orderCart,
Map<Integer, List<CookH5ReserveRecipeDishesVO>> cookRecipeDishMap,
Long recipeId) {
for (OrderCart orderCart : orderCartList) {
boolean filteredOrderDate = orderCartQueryParam.getMenuDateList().stream()
.anyMatch(menuDate -> LocalDate.parse(menuDate).equals(orderCart.getOrderDate()));
OrderCartVO orderCartVO = new OrderCartVO();
BeanUtils.copyProperties(orderCart, orderCartVO);
orderCartVO.setIsValid(0);
orderCartVOList.add(orderCartVO);
if(!filteredOrderDate) {
continue;
}
CookDishCheckDTO cookDishCheckDTO = new CookDishCheckDTO();
cookDishCheckDTO.setApplyDate(orderCart.getOrderDate());
cookDishCheckDTO.setCanteenId(orderCart.getCanteenId());
cookDishCheckDTO.setStallId(orderCart.getStallId());
cookDishCheckDTO.setApplyType(CookRecipeSortEnum.MOBILE_RESERVE.getKey());
AllocRecipeStallVO allocRecipeStallVO = null;
try{
allocRecipeStallVO = menuModule.getMenuRecipeDish(cookDishCheckDTO);
}catch (Exception ex) {
log.error("菜单数据获取失败:{}", ex.getMessage(), ex);
continue;
}
List<CookH5ReserveRecipeDishesVO> cookRecipeDishes = cookRecipeDishMap.get(orderCart.getMealtimeType());
if (CollUtil.isNotEmpty(cookRecipeDishes)) {
if(Objects.isNull(allocRecipeStallVO) || Objects.isNull(allocRecipeStallVO.getDetail())
|| CollUtil.isEmpty(allocRecipeStallVO.getDetail().getDetailList())) {
continue;
}
if(!allocRecipeStallVO.getRecipeId().equals(orderCart.getRecipeId())) {
continue;
}
List<CookRecipeDetailVO> cookRecipeDishList = allocRecipeStallVO.getDetail().getDetailList();
outerLoop:
for (CookH5ReserveRecipeDishesVO cookRecipeDishesVO : cookRecipeDishes) {
if(CollUtil.isNotEmpty(cookRecipeDishesVO.getDishesDetailList())) {
for (CookH5CurrentDishesDetailVO dishesDetailVO : cookRecipeDishesVO.getDishesDetailList()) {
if (orderCart.getGoodsId().equals(dishesDetailVO.getDishesId())
&& orderCart.getRecipeId().equals(recipeId)) {
for(CookRecipeDetailVO cookRecipeDish :cookRecipeDishList) {
if(cookRecipeDish.getMealtimeType().equals(orderCart.getMealtimeType().longValue())) {
if(CollUtil.isNotEmpty(cookRecipeDish.getDishesList())) {
for (CookRecipeDishesVO cookRecipeDishesVO : cookRecipeDish.getDishesList()) {
if(cookRecipeDishesVO.getDishesId().equals(orderCart.getGoodsId())) {
orderCartVO.setIsValid(1);
break outerLoop;
}
@ -133,10 +113,9 @@ public class OrderCartServiceImpl implements IOrderCartService
}
}
}
return orderCartVO;
}
return orderCartVOList;
}
/**
* 新增订单购物车