订单管理

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 lombok.Data;
import java.time.LocalDate;
/** /**
* @author Bonus * @author Bonus
*/ */
@Data @Data
public class CookDishCheckDTO { public class CookDishCheckDTO {
/** 食堂id */
private Long canteenId;
/** 档口id */
private Long stallId;
/** 供应日期 */ /** 供应日期 */
private String applyDate; private LocalDate applyDate;
/** 适用类型 */
private Long recipeId; 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.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle; import org.apache.commons.lang3.builder.ToStringStyle;
import java.time.LocalDate;
import java.util.Date; import java.util.Date;
/** /**
@ -64,7 +65,7 @@ public class OrderCart extends BaseEntity
/** 订单日期 yyyy-MM-dd */ /** 订单日期 yyyy-MM-dd */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate; private LocalDate orderDate;
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */ /** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵") @Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")
@ -180,14 +181,12 @@ public class OrderCart extends BaseEntity
return detailType; return detailType;
} }
public void setOrderDate(Date orderDate) public LocalDate getOrderDate() {
{ return orderDate;
this.orderDate = orderDate;
} }
public Date getOrderDate() public void setOrderDate(LocalDate orderDate) {
{ this.orderDate = orderDate;
return orderDate;
} }
public void setMealtimeType(Integer mealtimeType) 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 com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data; import lombok.Data;
import java.time.LocalDate;
import java.util.Date; import java.util.Date;
/** /**
@ -63,7 +64,7 @@ public class OrderCartVO extends BaseEntity
/** 订单日期 yyyy-MM-dd */ /** 订单日期 yyyy-MM-dd */
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
@Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd") @Excel(name = "订单日期 yyyy-MM-dd", width = 30, dateFormat = "yyyy-MM-dd")
private Date orderDate; private LocalDate orderDate;
/** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */ /** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */
@Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵") @Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵")

View File

@ -18,27 +18,20 @@ import java.util.*;
@Component @Component
public class MenuModule { public class MenuModule {
@Autowired @Autowired
private ICookH5Service cookH5Service; private ICookRecipeService cookRecipeService;
public Map<Integer, List<CookH5ReserveRecipeDishesVO>> getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) { public AllocRecipeStallVO getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) {
CookH5ReserveRecipeDTO cookH5ReserveRecipeDTO = new CookH5ReserveRecipeDTO(); AllocRecipeStallDTO allocRecipeStallDTO = new AllocRecipeStallDTO();
cookH5ReserveRecipeDTO.setApplyDate(LocalDate.parse(cookDishCheckDTO.getApplyDate())); allocRecipeStallDTO.setApplyDate(cookDishCheckDTO.getApplyDate());
cookH5ReserveRecipeDTO.setRecipeId(cookDishCheckDTO.getRecipeId()); allocRecipeStallDTO.setCanteenId(cookDishCheckDTO.getCanteenId());
allocRecipeStallDTO.setStallId(cookDishCheckDTO.getStallId());
allocRecipeStallDTO.setKey(cookDishCheckDTO.getApplyType());
Map<Integer, List<CookH5ReserveRecipeDishesVO>> mealTimeTypeMap = new HashMap<>(); Map<Integer, List<CookH5ReserveRecipeDishesVO>> mealTimeTypeMap = new HashMap<>();
List<CookH5ReserveRecipeDetailsVO> cookRecipeList = cookH5Service.getReserveRecipeDetailList(cookH5ReserveRecipeDTO); List<AllocRecipeStallVO> cookRecipeList = cookRecipeService.selectCookRecipeList4Current(allocRecipeStallDTO);
if (CollUtil.isNotEmpty(cookRecipeList)) { if (CollUtil.isNotEmpty(cookRecipeList) && cookRecipeList.size() == 1) {
for (CookH5ReserveRecipeDetailsVO cookRecipeDetailVO : cookRecipeList) { return cookRecipeList.get(0);
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);
}
}
}else { }else {
throw new ServiceException("菜谱信息异常"); 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.collection.CollUtil;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum; import com.bonus.canteen.core.cook.enums.CookRecipeSortEnum;
import com.bonus.canteen.core.cook.vo.CookH5CurrentDishesDetailVO; import com.bonus.canteen.core.cook.vo.*;
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.order.domain.CookDishCheckDTO; import com.bonus.canteen.core.order.domain.CookDishCheckDTO;
import com.bonus.canteen.core.order.domain.OrderCart; import com.bonus.canteen.core.order.domain.OrderCart;
import com.bonus.canteen.core.order.domain.param.OrderCartQueryParam; 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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -70,62 +68,44 @@ public class OrderCartServiceImpl implements IOrderCartService
if (CollUtil.isEmpty(orderCartList)) { if (CollUtil.isEmpty(orderCartList)) {
return new ArrayList<>(); 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<>(); List<OrderCartVO> orderCartVOList = new ArrayList<>();
for (OrderCart orderCart : orderCartList) {
for (Map.Entry<String, List<OrderCart>> entry : groupedByOrderDate.entrySet()) { boolean filteredOrderDate = orderCartQueryParam.getMenuDateList().stream()
String orderDateStr = entry.getKey(); .anyMatch(menuDate -> LocalDate.parse(menuDate).equals(orderCart.getOrderDate()));
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) {
OrderCartVO orderCartVO = new OrderCartVO(); OrderCartVO orderCartVO = new OrderCartVO();
BeanUtils.copyProperties(orderCart, orderCartVO); BeanUtils.copyProperties(orderCart, orderCartVO);
orderCartVO.setIsValid(0); 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(Objects.isNull(allocRecipeStallVO) || Objects.isNull(allocRecipeStallVO.getDetail())
if (CollUtil.isNotEmpty(cookRecipeDishes)) { || CollUtil.isEmpty(allocRecipeStallVO.getDetail().getDetailList())) {
continue;
}
if(!allocRecipeStallVO.getRecipeId().equals(orderCart.getRecipeId())) {
continue;
}
List<CookRecipeDetailVO> cookRecipeDishList = allocRecipeStallVO.getDetail().getDetailList();
outerLoop: outerLoop:
for (CookH5ReserveRecipeDishesVO cookRecipeDishesVO : cookRecipeDishes) { for(CookRecipeDetailVO cookRecipeDish :cookRecipeDishList) {
if(CollUtil.isNotEmpty(cookRecipeDishesVO.getDishesDetailList())) { if(cookRecipeDish.getMealtimeType().equals(orderCart.getMealtimeType().longValue())) {
for (CookH5CurrentDishesDetailVO dishesDetailVO : cookRecipeDishesVO.getDishesDetailList()) { if(CollUtil.isNotEmpty(cookRecipeDish.getDishesList())) {
if (orderCart.getGoodsId().equals(dishesDetailVO.getDishesId()) for (CookRecipeDishesVO cookRecipeDishesVO : cookRecipeDish.getDishesList()) {
&& orderCart.getRecipeId().equals(recipeId)) { if(cookRecipeDishesVO.getDishesId().equals(orderCart.getGoodsId())) {
orderCartVO.setIsValid(1); orderCartVO.setIsValid(1);
break outerLoop; break outerLoop;
} }
@ -133,10 +113,9 @@ public class OrderCartServiceImpl implements IOrderCartService
} }
} }
} }
return orderCartVO;
} }
return orderCartVOList;
}
/** /**
* 新增订单购物车 * 新增订单购物车