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 9391876..a33b168 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 @@ -7,12 +7,8 @@ import lombok.Data; */ @Data public class CookDishCheckDTO { - /** 食堂id */ - private Long canteenId; - /** 档口id */ - private Long stallId; /** 供应日期 */ private String applyDate; - /** 适用类型 */ - private Integer applyType; + + private Long recipeId; } 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 9452e93..a5e1646 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 @@ -1,12 +1,12 @@ package com.bonus.canteen.core.order.module; import cn.hutool.core.collection.CollUtil; +import com.bonus.canteen.core.cook.dto.AllocRecipeStallDTO; +import com.bonus.canteen.core.cook.dto.CookH5ReserveRecipeDTO; import com.bonus.canteen.core.cook.dto.CookRecipeDTO; +import com.bonus.canteen.core.cook.service.ICookH5Service; import com.bonus.canteen.core.cook.service.ICookRecipeService; -import com.bonus.canteen.core.cook.vo.CookRecipeDateVO; -import com.bonus.canteen.core.cook.vo.CookRecipeDetailVO; -import com.bonus.canteen.core.cook.vo.CookRecipeDishesVO; -import com.bonus.canteen.core.cook.vo.CookRecipeVO; +import com.bonus.canteen.core.cook.vo.*; import com.bonus.canteen.core.order.domain.CookDishCheckDTO; import com.bonus.common.core.exception.ServiceException; import org.springframework.beans.factory.annotation.Autowired; @@ -18,37 +18,23 @@ import java.util.*; @Component public class MenuModule { @Autowired - private ICookRecipeService cookRecipeService; + private ICookH5Service cookH5Service; - public Map> getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) { - CookRecipeDTO menurecipe = new CookRecipeDTO(); - menurecipe.setApplyDate(LocalDate.parse(cookDishCheckDTO.getApplyDate())); - menurecipe.setCanteenId(cookDishCheckDTO.getCanteenId()); - menurecipe.setStallId(cookDishCheckDTO.getStallId()); - menurecipe.setKey(cookDishCheckDTO.getApplyType()); - Map> mealTimeTypeMap = new HashMap<>(); - List menuRecipeList = cookRecipeService.selectCookRecipeList4Current(menurecipe); - if (CollUtil.isNotEmpty(menuRecipeList) && menuRecipeList.size() == 1) { - List recipeDateList = menuRecipeList.get(0).getRecipeDateList(); - if(CollUtil.isNotEmpty(recipeDateList) && recipeDateList.size() == 1) { - List cookRecipeDetail = recipeDateList.get(0).getDetailList(); - if(CollUtil.isNotEmpty(cookRecipeDetail)) { - Long mealType = null; - List dishsIdList = new ArrayList<>(); - for (CookRecipeDetailVO cookRecipeDetailVO : cookRecipeDetail) { - mealType = cookRecipeDetailVO.getMealtimeType(); - if(CollUtil.isNotEmpty(cookRecipeDetailVO.getDishesList())) { - dishsIdList.addAll(cookRecipeDetailVO.getDishesList()); - } + public Map> getMenuRecipeDish(CookDishCheckDTO cookDishCheckDTO) { + CookH5ReserveRecipeDTO cookH5ReserveRecipeDTO = new CookH5ReserveRecipeDTO(); + cookH5ReserveRecipeDTO.setApplyDate(LocalDate.parse(cookDishCheckDTO.getApplyDate())); + cookH5ReserveRecipeDTO.setRecipeId(cookDishCheckDTO.getRecipeId()); + 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()); } - if(Objects.nonNull(mealType)) { - mealTimeTypeMap.put(mealType, dishsIdList); - } - }else { - throw new ServiceException("菜谱信息异常"); + mealTimeTypeMap.put(cookRecipeDetailVO.getMealtimeType(), allDishesList); } - }else { - throw new ServiceException("菜谱信息异常"); } }else { throw new ServiceException("菜谱信息异常"); 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 bccd673..2a9ae8d 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,6 +3,9 @@ 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.order.domain.CookDishCheckDTO; import com.bonus.canteen.core.order.domain.OrderCart; @@ -68,11 +71,6 @@ public class OrderCartServiceImpl implements IOrderCartService return new ArrayList<>(); } - CookDishCheckDTO cookDishCheckDTO = new CookDishCheckDTO(); - cookDishCheckDTO.setCanteenId(orderCartQueryParam.getCanteenId()); - cookDishCheckDTO.setStallId(orderCartQueryParam.getStallId()); - cookDishCheckDTO.setApplyType(CookRecipeSortEnum.MOBILE_RESERVE.getKey()); - Map> groupedByOrderDate = orderCartList.stream() .collect(Collectors.groupingBy(cart -> DateUtil.format(cart.getOrderDate(), "yyyy-MM-dd"))); @@ -83,9 +81,18 @@ public class OrderCartServiceImpl implements IOrderCartService 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 { + continue; + } cookDishCheckDTO.setApplyDate(orderDateStr); - Map> cookRecipeDishMap = new HashMap<>(); + Map> cookRecipeDishMap = new HashMap<>(); try{ cookRecipeDishMap = menuModule.getMenuRecipeDish(cookDishCheckDTO); }catch (Exception ex) { @@ -93,7 +100,7 @@ public class OrderCartServiceImpl implements IOrderCartService } for (OrderCart shoppingCart : carts) { - OrderCartVO shoppingCartVO = convertToOrderCartVO(shoppingCart, cookRecipeDishMap); + OrderCartVO shoppingCartVO = convertToOrderCartVO(shoppingCart, cookRecipeDishMap, cookDishCheckDTO.getRecipeId()); if(filteredOrderDate == null) { shoppingCartVO.setIsValid(0); } @@ -105,17 +112,24 @@ public class OrderCartServiceImpl implements IOrderCartService } private OrderCartVO convertToOrderCartVO(OrderCart orderCart, - Map> cookRecipeDishMap) { + Map> cookRecipeDishMap, + Long recipeId) { OrderCartVO orderCartVO = new OrderCartVO(); BeanUtils.copyProperties(orderCart, orderCartVO); orderCartVO.setIsValid(0); - List cookRecipeDishes = cookRecipeDishMap.get(orderCart.getMealtimeType().longValue()); + List cookRecipeDishes = cookRecipeDishMap.get(orderCart.getMealtimeType()); if (CollUtil.isNotEmpty(cookRecipeDishes)) { - for (CookRecipeDishesVO cookRecipeDishesVO : cookRecipeDishes) { - if (orderCart.getGoodsId().equals(cookRecipeDishesVO.getDishesId())) { - orderCartVO.setIsValid(1); - break; + 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; + } + } } } }