diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/CookDishCheckDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/CookDishCheckDTO.java index a33b168..3e55b5a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/CookDishCheckDTO.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/CookDishCheckDTO.java @@ -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; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderCart.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderCart.java index d7b6a28..df7dfc6 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderCart.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderCart.java @@ -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) diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderCartVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderCartVO.java index 719150a..1b28253 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderCartVO.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderCartVO.java @@ -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-夜宵") diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java index a5e1646..d3e7342 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java @@ -18,27 +18,20 @@ import java.util.*; @Component public class MenuModule { @Autowired - private ICookH5Service cookH5Service; + private ICookRecipeService cookRecipeService; - public Map> 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> mealTimeTypeMap = new HashMap<>(); - List cookRecipeList = cookH5Service.getReserveRecipeDetailList(cookH5ReserveRecipeDTO); - if (CollUtil.isNotEmpty(cookRecipeList)) { - for (CookH5ReserveRecipeDetailsVO cookRecipeDetailVO : cookRecipeList) { - if(Objects.nonNull(cookRecipeDetailVO.getMealtimeType()) && CollUtil.isNotEmpty(cookRecipeDetailVO.getTypeList())) { - List allDishesList = new ArrayList<>(); - for(CookH5ReserveRecipeTypeVO typeVO : cookRecipeDetailVO.getTypeList()) { - allDishesList.addAll(typeVO.getDishesList()); - } - mealTimeTypeMap.put(cookRecipeDetailVO.getMealtimeType(), allDishesList); - } - } + List cookRecipeList = cookRecipeService.selectCookRecipeList4Current(allocRecipeStallDTO); + if (CollUtil.isNotEmpty(cookRecipeList) && cookRecipeList.size() == 1) { + return cookRecipeList.get(0); }else { throw new ServiceException("菜谱信息异常"); } - return mealTimeTypeMap; } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderCartServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderCartServiceImpl.java index 2a9ae8d..4281289 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderCartServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderCartServiceImpl.java @@ -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,74 +68,55 @@ public class OrderCartServiceImpl implements IOrderCartService if (CollUtil.isEmpty(orderCartList)) { return new ArrayList<>(); } - - Map> groupedByOrderDate = orderCartList.stream() - .collect(Collectors.groupingBy(cart -> DateUtil.format(cart.getOrderDate(), "yyyy-MM-dd"))); - List orderCartVOList = new ArrayList<>(); - - for (Map.Entry> entry : groupedByOrderDate.entrySet()) { - String orderDateStr = entry.getKey(); - List carts = entry.getValue(); - String filteredOrderDate = orderCartQueryParam.getMenuDateList().stream().filter(orderDate -> orderDate.equals(orderDateStr)) - .findFirst().orElse(null); - CookDishCheckDTO cookDishCheckDTO = new CookDishCheckDTO(); - Optional maxRecipeId = carts.stream() - .sorted(Comparator.comparing(OrderCart::getCartId).reversed()) - .map(OrderCart::getRecipeId) - .findFirst(); - if (maxRecipeId.isPresent()) { - cookDishCheckDTO.setRecipeId(maxRecipeId.get()); - } else { + 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.setApplyDate(orderDateStr); - Map> cookRecipeDishMap = new HashMap<>(); + 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{ - cookRecipeDishMap = menuModule.getMenuRecipeDish(cookDishCheckDTO); + allocRecipeStallVO = menuModule.getMenuRecipeDish(cookDishCheckDTO); }catch (Exception ex) { - log.info("菜单数据获取失败:{}", ex.getMessage(), ex); + log.error("菜单数据获取失败:{}", ex.getMessage(), ex); + continue; } - for (OrderCart shoppingCart : carts) { - OrderCartVO shoppingCartVO = convertToOrderCartVO(shoppingCart, cookRecipeDishMap, cookDishCheckDTO.getRecipeId()); - if(filteredOrderDate == null) { - shoppingCartVO.setIsValid(0); - } - orderCartVOList.add(shoppingCartVO); + if(Objects.isNull(allocRecipeStallVO) || Objects.isNull(allocRecipeStallVO.getDetail()) + || CollUtil.isEmpty(allocRecipeStallVO.getDetail().getDetailList())) { + continue; } - } - - return orderCartVOList; - } - - private OrderCartVO convertToOrderCartVO(OrderCart orderCart, - Map> cookRecipeDishMap, - Long recipeId) { - OrderCartVO orderCartVO = new OrderCartVO(); - BeanUtils.copyProperties(orderCart, orderCartVO); - orderCartVO.setIsValid(0); - - List cookRecipeDishes = cookRecipeDishMap.get(orderCart.getMealtimeType()); - if (CollUtil.isNotEmpty(cookRecipeDishes)) { + if(!allocRecipeStallVO.getRecipeId().equals(orderCart.getRecipeId())) { + continue; + } + List 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)) { - orderCartVO.setIsValid(1); - break outerLoop; + 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; + } } } } } } - - return orderCartVO; + return orderCartVOList; } - /** * 新增订单购物车 *