From d39356eddba092d4dd3787a1e85610deb394794b Mon Sep 17 00:00:00 2001 From: gaowdong Date: Wed, 16 Apr 2025 17:57:24 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../menu/mapper/MenuRecipeDishesMapper.java | 5 ++ .../service/IMenuRecipeDishesService.java | 11 +++ .../impl/MenuRecipeDishesServiceImpl.java | 64 +++++++++++++++ .../core/order/business/OrderBusiness.java | 24 ++++++ .../order/controller/OrderInfoController.java | 11 ++- .../OrderShoppingCartController.java | 23 +++--- .../core/order/domain/MenuDishCheckDTO.java | 18 +++++ .../core/order/domain/OrderShoppingCart.java | 6 +- .../param/OrderShoppingCartQueryParam.java | 34 ++++++++ .../domain/param/ShoppingCartDelParam.java | 10 +++ .../order/domain/vo/OrderShoppingCartVO.java | 76 ++++++++++++++++++ .../canteen/core/order/module/MenuModule.java | 58 ++++++++++++++ .../core/order/service/IOrderInfoService.java | 1 + .../service/IOrderShoppingCartService.java | 4 +- .../service/impl/OrderInfoServiceImpl.java | 41 +++++++++- .../impl/OrderShoppingCartServiceImpl.java | 78 ++++++++++++++++++- .../order/utils/ShoppingCartParamChecker.java | 39 ++++++---- .../core/pay/constants/PayStateEnum.java | 3 + .../mapper/menu/MenuRecipeDishesMapper.xml | 22 +++++- 19 files changed, 490 insertions(+), 38 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/MenuDishCheckDTO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/OrderShoppingCartQueryParam.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/ShoppingCartDelParam.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderShoppingCartVO.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuRecipeDishesMapper.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuRecipeDishesMapper.java index 90454b9..6e867b4 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuRecipeDishesMapper.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/mapper/MenuRecipeDishesMapper.java @@ -3,6 +3,7 @@ package com.bonus.canteen.core.menu.mapper; import java.util.List; import com.bonus.canteen.core.menu.domain.MenuRecipeDishes; +import org.apache.ibatis.annotations.Param; /** * 菜品计划菜品关联Mapper接口 @@ -43,6 +44,10 @@ public interface MenuRecipeDishesMapper { */ public int updateMenuRecipeDishes(MenuRecipeDishes menuRecipeDishes); + public int reduceMenuRecipeDishesSupplyNum(@Param("dish") MenuRecipeDishes menuRecipeDishes, @Param("quantity") Integer quantity); + + public int addMenuRecipeDishesSupplyNum(@Param("dish")MenuRecipeDishes menuRecipeDishes, @Param("quantity") Integer quantity); + /** * 删除菜品计划菜品关联 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/IMenuRecipeDishesService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/IMenuRecipeDishesService.java index a07155c..6197417 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/IMenuRecipeDishesService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/IMenuRecipeDishesService.java @@ -42,6 +42,17 @@ public interface IMenuRecipeDishesService { */ public int updateMenuRecipeDishes(MenuRecipeDishes menuRecipeDishes); + /** + * 修改菜品计划菜品关联供应量 + * + * @param menuRecipeDishes 菜品计划菜品关联 + * @return 结果 + */ + public int reduceMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity); + + public int addMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity); + + /** * 批量删除菜品计划菜品关联 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuRecipeDishesServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuRecipeDishesServiceImpl.java index 9b61232..e8f377a 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuRecipeDishesServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/menu/service/impl/MenuRecipeDishesServiceImpl.java @@ -2,8 +2,14 @@ package com.bonus.canteen.core.menu.service.impl; import java.time.LocalDateTime; import java.util.List; + +import com.bonus.canteen.core.account.service.impl.AccSubServiceImpl; +import com.bonus.canteen.core.common.utils.RedisUtil; import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.DateUtils; +import com.bonus.common.houqin.constant.GlobalConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.bonus.canteen.core.menu.mapper.MenuRecipeDishesMapper; @@ -18,6 +24,8 @@ import com.bonus.canteen.core.menu.service.IMenuRecipeDishesService; */ @Service public class MenuRecipeDishesServiceImpl implements IMenuRecipeDishesService { + private static final Logger log = LoggerFactory.getLogger(MenuRecipeDishesServiceImpl.class); + @Autowired private MenuRecipeDishesMapper menuRecipeDishesMapper; @@ -75,6 +83,62 @@ public class MenuRecipeDishesServiceImpl implements IMenuRecipeDishesService { } } + @Override + public int reduceMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity) { + if(menuRecipeDishes == null || menuRecipeDishes.getDetailId() == null || menuRecipeDishes.getDishesId() == null) { + throw new ServiceException("参数错误"); + } + String lockKey = String.format("sc:menu_recipe_dishes_supply_num_tenant_%s_detailed_%s_dishes_id_%s", + GlobalConstants.TENANT_ID, menuRecipeDishes.getDetailId(), menuRecipeDishes.getDishesId()); + try { + if (!RedisUtil.tryLock(lockKey, 10, 15)) { + throw new ServiceException("修改库存失败"); + } + List menuRecipeDishesList = selectMenuRecipeDishesList(menuRecipeDishes); + if (menuRecipeDishesList == null || menuRecipeDishesList.isEmpty()) { + throw new ServiceException("菜品计划菜品关联不存在"); + } + menuRecipeDishes = menuRecipeDishesList.get(0); + if(menuRecipeDishes.getSurplusNum() < quantity) { + throw new ServiceException("菜品供应量不足"); + } + return menuRecipeDishesMapper.reduceMenuRecipeDishesSupplyNum(menuRecipeDishes, quantity); + } catch (Exception e) { + log.error("修改菜谱菜品供应量失败", e); + throw new ServiceException("修改菜谱菜品供应量失败"); + }finally { + try { + RedisUtil.safeUnLock(lockKey); + } catch (Exception ex) { + log.error("账户操作解锁异常", ex); + } + } + } + + @Override + public int addMenuRecipeDishesSupplyNum(MenuRecipeDishes menuRecipeDishes, Integer quantity) { + if(menuRecipeDishes == null || menuRecipeDishes.getDetailId() == null || menuRecipeDishes.getDishesId() == null) { + throw new ServiceException("参数错误"); + } + String lockKey = String.format("sc:menu_recipe_dishes_supply_num_tenant_%s_detailed_%s_dishes_id_%s", + GlobalConstants.TENANT_ID, menuRecipeDishes.getDetailId(), menuRecipeDishes.getDishesId()); + try { + if (!RedisUtil.tryLock(lockKey, 10, 15)) { + throw new ServiceException("账户有交易正在进行中"); + } + return menuRecipeDishesMapper.addMenuRecipeDishesSupplyNum(menuRecipeDishes, quantity); + } catch (Exception e) { + log.error("修改菜谱菜品供应量失败", e); + throw new ServiceException("修改菜谱菜品供应量失败"); + }finally { + try { + RedisUtil.safeUnLock(lockKey); + } catch (Exception ex) { + log.error("账户操作解锁异常", ex); + } + } + } + /** * 批量删除菜品计划菜品关联 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/business/OrderBusiness.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/business/OrderBusiness.java index 80e7405..1e568da 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/business/OrderBusiness.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/business/OrderBusiness.java @@ -3,6 +3,8 @@ package com.bonus.canteen.core.order.business; import cn.hutool.core.collection.CollUtil; import com.bonus.canteen.core.account.domain.vo.AccInfoDetailsVO; import com.bonus.canteen.core.account.service.IAccInfoService; +import com.bonus.canteen.core.menu.domain.MenuRecipeDishes; +import com.bonus.canteen.core.menu.service.IMenuRecipeDishesService; import com.bonus.canteen.core.order.domain.OrderDetail; import com.bonus.canteen.core.order.domain.OrderInfo; import com.bonus.canteen.core.order.domain.param.OrderAddParam; @@ -23,6 +25,9 @@ public class OrderBusiness { private IOrderDetailService orderDetailService; @Autowired private OrderInfoMapper orderInfoMapper; + @Autowired + private IMenuRecipeDishesService menuRecipeDishesService; + @Transactional(rollbackFor = Exception.class) public List orderPlaceHandler(OrderAddParam orderAddParam) { AccInfoDetailsVO accInfoVO = this.accInfoService.queryAccInfoByUserId(orderAddParam.getUserId()); @@ -35,7 +40,26 @@ public class OrderBusiness { orderInfoList.forEach(orderInfo -> { List orderDetailList = orderInfo.getOrderDetailList(); orderDetailService.batchInsertOrderDetail(orderDetailList); + reduceMenuDishSupplyNum(orderDetailList); }); return orderInfoList; } + + public void reduceMenuDishSupplyNum(List orderDetailList) { + for(OrderDetail orderDetail : orderDetailList) { + MenuRecipeDishes menuRecipeDishes = new MenuRecipeDishes(); + menuRecipeDishes.setDetailId(orderDetail.getDetailId()); + menuRecipeDishes.setDishesId(orderDetail.getGoodsId()); + menuRecipeDishesService.reduceMenuRecipeDishesSupplyNum(menuRecipeDishes, orderDetail.getQuantity()); + } + } + + public void addMenuDishSupplyNum(List orderDetailList) { + for(OrderDetail orderDetail : orderDetailList) { + MenuRecipeDishes menuRecipeDishes = new MenuRecipeDishes(); + menuRecipeDishes.setDetailId(orderDetail.getDetailId()); + menuRecipeDishes.setDishesId(orderDetail.getGoodsId()); + menuRecipeDishesService.addMenuRecipeDishesSupplyNum(menuRecipeDishes, orderDetail.getQuantity()); + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderInfoController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderInfoController.java index e3f6e73..366e73b 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderInfoController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderInfoController.java @@ -77,7 +77,7 @@ public class OrderInfoController extends BaseController /** * 新增保存订单 */ - @SysLog(title = "订单", module = "订单", businessType = OperaType.INSERT) + @SysLog(title = "下单", module = "订单", businessType = OperaType.INSERT) @PostMapping("/add") @ResponseBody public AjaxResult addSave(OrderAddParam orderAddParam) @@ -94,6 +94,15 @@ public class OrderInfoController extends BaseController return AjaxResult.success(); } + @SysLog(title = "付款", module = "订单", businessType = OperaType.INSERT) + @PostMapping("/pay/{orderId}") + @ResponseBody + public AjaxResult pay(@PathVariable Long orderId) + { + orderInfoService.pay(orderId); + return AjaxResult.success(); + } + /** * 修改订单 */ diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderShoppingCartController.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderShoppingCartController.java index 8f60276..9cf632c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderShoppingCartController.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/controller/OrderShoppingCartController.java @@ -1,9 +1,13 @@ package com.bonus.canteen.core.order.controller; import java.util.List; +import java.util.Objects; import cn.hutool.core.collection.CollUtil; import com.bonus.canteen.core.order.domain.OrderShoppingCart; +import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam; +import com.bonus.canteen.core.order.domain.param.ShoppingCartDelParam; +import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO; import com.bonus.canteen.core.order.service.IOrderShoppingCartService; import com.bonus.canteen.core.order.utils.ShoppingCartParamChecker; import com.bonus.common.core.exception.ServiceException; @@ -21,6 +25,7 @@ import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; +import javax.validation.constraints.NotNull; /** * 订单购物车Controller @@ -40,11 +45,11 @@ public class OrderShoppingCartController extends BaseController */ @PostMapping("/list") @ResponseBody - public TableDataInfo list(@RequestBody OrderShoppingCart orderShoppingCart) + public TableDataInfo list(@RequestBody OrderShoppingCartQueryParam orderShoppingCart) { ShoppingCartParamChecker.listCheck(orderShoppingCart); startPage(); - List list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); + List list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); return getDataTable(list); } @@ -54,10 +59,10 @@ public class OrderShoppingCartController extends BaseController @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.EXPORT) @PostMapping("/export") @ResponseBody - public void export(OrderShoppingCart orderShoppingCart, HttpServletResponse response) + public void export(OrderShoppingCartQueryParam orderShoppingCart, HttpServletResponse response) { - List list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); - ExcelUtil util = new ExcelUtil(OrderShoppingCart.class); + List list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); + ExcelUtil util = new ExcelUtil(OrderShoppingCartVO.class); util.exportExcel(response, list, "订单购物车数据"); } @@ -97,14 +102,14 @@ public class OrderShoppingCartController extends BaseController /** * 删除订单购物车 */ - @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.DELETE) + @SysLog(title = "订单购物车删除", module = "订单-订单详情", businessType = OperaType.DELETE) @PostMapping( "/remove") @ResponseBody - public AjaxResult remove(@RequestBody List shoppingCartIds) + public AjaxResult remove(@RequestBody ShoppingCartDelParam param) { - if(CollUtil.isEmpty(shoppingCartIds)) { + if(Objects.isNull(param) || CollUtil.isEmpty(param.getShoppingCartIds())) { throw new ServiceException("购物车餐品ID为空"); } - return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(shoppingCartIds)); + return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(param.getShoppingCartIds())); } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/MenuDishCheckDTO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/MenuDishCheckDTO.java new file mode 100644 index 0000000..83416d4 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/MenuDishCheckDTO.java @@ -0,0 +1,18 @@ +package com.bonus.canteen.core.order.domain; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class MenuDishCheckDTO { + /** 食堂id */ + private Long canteenId; + /** 档口id */ + private Long stallId; + /** 供应日期 */ + private String applyDate; + /** 适用类型 */ + private String applyType; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderShoppingCart.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderShoppingCart.java index 4ff87e1..ebe5878 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderShoppingCart.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/OrderShoppingCart.java @@ -68,7 +68,7 @@ public class OrderShoppingCart extends BaseEntity /** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */ @Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵") - private Long mealtimeType; + private Integer mealtimeType; public void setShoppingCartId(Long shoppingCartId) { @@ -190,12 +190,12 @@ public class OrderShoppingCart extends BaseEntity return orderDate; } - public void setMealtimeType(Long mealtimeType) + public void setMealtimeType(Integer mealtimeType) { this.mealtimeType = mealtimeType; } - public Long getMealtimeType() + public Integer getMealtimeType() { return mealtimeType; } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/OrderShoppingCartQueryParam.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/OrderShoppingCartQueryParam.java new file mode 100644 index 0000000..8aa36a8 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/OrderShoppingCartQueryParam.java @@ -0,0 +1,34 @@ +package com.bonus.canteen.core.order.domain.param; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; +import java.util.List; + +/** + * 订单购物车对象 order_shopping_cart + * + * @author ruoyi + * @date 2025-04-14 + */ +@Data +public class OrderShoppingCartQueryParam +{ + + /** 食堂id */ + private Long canteenId; + + /** 档口id */ + private Long stallId; + + /** 订单类型 */ + private Integer orderType; + + /** 菜谱日期 yyyy-MM-dd */ + private List menuDateList; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/ShoppingCartDelParam.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/ShoppingCartDelParam.java new file mode 100644 index 0000000..877f315 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/param/ShoppingCartDelParam.java @@ -0,0 +1,10 @@ +package com.bonus.canteen.core.order.domain.param; + +import lombok.Data; + +import java.util.List; + +@Data +public class ShoppingCartDelParam { + private List shoppingCartIds; +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderShoppingCartVO.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderShoppingCartVO.java new file mode 100644 index 0000000..55fa16c --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/domain/vo/OrderShoppingCartVO.java @@ -0,0 +1,76 @@ +package com.bonus.canteen.core.order.domain.vo; + +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +import java.util.Date; + +/** + * 订单购物车对象 order_shopping_cart + * + * @author ruoyi + * @date 2025-04-14 + */ +@Data +public class OrderShoppingCartVO extends BaseEntity +{ + + /** 主键 */ + private Long shoppingCartId; + + /** 人员id */ + @Excel(name = "人员id") + private Long userId; + + /** 菜谱id */ + @Excel(name = "菜谱id") + private Long menuId; + + /** 食堂id */ + @Excel(name = "食堂id") + private Long canteenId; + + /** 档口id */ + @Excel(name = "档口id") + private Long stallId; + + /** 商品菜品id */ + @Excel(name = "商品菜品id") + private Long goodsId; + + /** 商品菜品名称 */ + @Excel(name = "商品菜品名称") + private String goodsName; + + /** 商品菜品图片路径 */ + @Excel(name = "商品菜品图片路径") + private String goodsImgUrl; + + /** 数量/重量 */ + @Excel(name = "数量/重量") + private Integer quantity; + + /** 订单类型 */ + @Excel(name = "订单类型") + private Integer orderType; + + /** 明细类别 1 菜品 2 套餐 3 商品 4 按键 5 补扣 6 报餐 */ + @Excel(name = "明细类别 1 菜品 2 套餐 3 商品 4 按键 5 补扣 6 报餐") + private Integer detailType; + + /** 订单日期 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; + + /** 餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵 */ + @Excel(name = "餐次类型 1-早餐 2-午餐 3-晚餐 4-下午茶 5-夜宵") + private Integer mealtimeType; + + @Excel(name = "餐次类型 0-已失效 1-未失效") + private Integer isValid; +} 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 new file mode 100644 index 0000000..2fcbe73 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/module/MenuModule.java @@ -0,0 +1,58 @@ +package com.bonus.canteen.core.order.module; + +import cn.hutool.core.collection.CollUtil; +import com.bonus.canteen.core.menu.domain.MenuRecipe; +import com.bonus.canteen.core.menu.enums.MenuRecipeSortEnum; +import com.bonus.canteen.core.menu.service.IMenuRecipeService; +import com.bonus.canteen.core.menu.vo.MenuRecipeDetailsVO; +import com.bonus.canteen.core.menu.vo.MenuRecipeDishesVO; +import com.bonus.canteen.core.menu.vo.MenuRecipeMealtimeTypeVO; +import com.bonus.canteen.core.menu.vo.MenuRecipeVO; +import com.bonus.canteen.core.order.domain.MenuDishCheckDTO; +import com.bonus.common.core.exception.ServiceException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.*; + +@Component +public class MenuModule { + @Autowired + private IMenuRecipeService menuRecipeService; + + public Map> getMenuRecipeDish(MenuDishCheckDTO menuDishCheckDTO) { + MenuRecipe menuRecipe = new MenuRecipe(); + menuRecipe.setApplyDate(menuDishCheckDTO.getApplyDate()); + menuRecipe.setCanteenId(menuDishCheckDTO.getCanteenId()); + menuRecipe.setStallId(menuDishCheckDTO.getStallId()); + menuRecipe.setKey(menuDishCheckDTO.getApplyType()); + Map> mealTimeTypeMap = new HashMap<>(); + List menuRecipeList = menuRecipeService.selectMenuRecipeList(menuRecipe); + if (CollUtil.isNotEmpty(menuRecipeList) && menuRecipeList.size() == 1) { + List menuRecipeDetailsVOList = menuRecipeList.get(0).getDetail(); + if(CollUtil.isNotEmpty(menuRecipeDetailsVOList) && menuRecipeDetailsVOList.size() == 1) { + List menuRecipeMealtimeTypeVOS = menuRecipeDetailsVOList.get(0).getDetails(); + if(CollUtil.isNotEmpty(menuRecipeMealtimeTypeVOS)) { + Integer mealType = null; + List dishsIdList = new ArrayList<>(); + for (MenuRecipeMealtimeTypeVO menuRecipeMealtimeTypeVO : menuRecipeMealtimeTypeVOS) { + mealType = menuRecipeMealtimeTypeVO.getMealtimeType(); + if(CollUtil.isNotEmpty(menuRecipeMealtimeTypeVO.getDishesList())) { + dishsIdList.addAll(menuRecipeMealtimeTypeVO.getDishesList()); + } + } + if(Objects.nonNull(mealType)) { + mealTimeTypeMap.put(mealType, dishsIdList); + } + }else { + throw new ServiceException("菜谱信息异常"); + } + }else { + throw new ServiceException("菜谱信息异常"); + } + }else { + throw new ServiceException("菜谱信息异常"); + } + return mealTimeTypeMap; + } +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderInfoService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderInfoService.java index 3596fd4..bdf44c9 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderInfoService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderInfoService.java @@ -63,4 +63,5 @@ public interface IOrderInfoService public int deleteOrderInfoByOrderId(Long orderId); public void refund(Long orderId); + public void pay(Long orderId); } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderShoppingCartService.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderShoppingCartService.java index d55b27e..7f566d1 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderShoppingCartService.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/IOrderShoppingCartService.java @@ -1,6 +1,8 @@ package com.bonus.canteen.core.order.service; import com.bonus.canteen.core.order.domain.OrderShoppingCart; +import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam; +import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO; import java.util.List; @@ -26,7 +28,7 @@ public interface IOrderShoppingCartService * @param orderShoppingCart 订单购物车 * @return 订单购物车集合 */ - public List selectOrderShoppingCartList(OrderShoppingCart orderShoppingCart); + public List selectOrderShoppingCartList(OrderShoppingCartQueryParam orderShoppingCart); /** * 新增订单购物车 diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderInfoServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderInfoServiceImpl.java index 997eed9..326a43c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderInfoServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderInfoServiceImpl.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -108,6 +109,33 @@ public class OrderInfoServiceImpl implements IOrderInfoService throw new ServiceException("请勿重复提交订单"); } List orderInfoList = orderBusiness.orderPlaceHandler(orderAddParam); + orderPay(orderInfoList); + return 1; + } + @Override + public void pay(Long orderId) { + if(Objects.isNull(orderId) || orderId <= 0) { + throw new ServiceException("订单ID不能为空"); + } + OrderInfo orderInfo = selectOrderInfoByOrderId(orderId); + if(Objects.isNull(orderInfo)) { + throw new ServiceException("订单不存在"); + } + String payOrderKey = String.format("sc:order_pay_orderId_%s", orderId); + if (!RedisUtil.setNx(payOrderKey, 1, 2)) { + log.info("退单处理中:{}", payOrderKey); + throw new ServiceException("退单处理中"); + } + if(orderInfo.getOrderState().equals(OrderRefundStateEnum.FINISH.getKey())) { + throw new ServiceException("订单已退"); + } + if(PayStateEnum.isUnPay(orderInfo.getPayState())) { + List orderInfoList = new ArrayList<>(); + orderInfoList.add(orderInfo); + orderPay(orderInfoList); + } + } + private void orderPay(List orderInfoList) { OrderPayDTO orderPayDTO = buildOrderPayDTO(orderInfoList); try { List walletInfoList = accWalletInfoService.selectAccWalletInfoByUserId(orderPayDTO.getUserId()); @@ -140,14 +168,13 @@ public class OrderInfoServiceImpl implements IOrderInfoService orderPayResultDTO.setUpdateBy(SecurityUtils.getUsername()); orderInfoMapper.updateOrderPayResult(orderPayResultDTO); try { - DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderAddParam.getUserId()),"update"); + DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderInfoList.get(0).getUserId()),"update"); String jsonString = JacksonUtil.writeValueAsString(bean); log.info("账户变动发送mq内容:{}", jsonString); MqUtil.pushToTenantAllDevice(bean, LeMqConstant.Topic.DEVICE_UPDATE_PERSONAL_CONFIG_V4); } catch (Exception e) { log.error("发送MQ消息失败", e); } - return 1; } private BigDecimal getWalletBalance(List walletInfoList, AccWalletIdEnum walletIdEnum) { @@ -233,6 +260,7 @@ public class OrderInfoServiceImpl implements IOrderInfoService } @Override + @Transactional(rollbackFor = {Exception.class}) public void refund(Long orderId) { if(Objects.isNull(orderId) || orderId <= 0) { throw new ServiceException("订单ID不能为空"); @@ -287,6 +315,7 @@ public class OrderInfoServiceImpl implements IOrderInfoService orderDetail.setDetailState(OrderDetailStateEnum.REFUNDED.getKey()); orderDetailService.updateOrderDetail(orderDetail); } + orderBusiness.addMenuDishSupplyNum(orderDetailList); try { DeviceMqPersonalUpdateMessageDTO bean = new DeviceMqPersonalUpdateMessageDTO().setUpdatePerson(Math.toIntExact(orderInfo.getUserId()),"update"); String jsonString = JacksonUtil.writeValueAsString(bean); @@ -295,6 +324,14 @@ public class OrderInfoServiceImpl implements IOrderInfoService } catch (Exception e) { log.error("发送MQ消息失败", e); } + }else { + OrderInfo refundOrderInfo = new OrderInfo(); + refundOrderInfo.setOrderId(orderId); + refundOrderInfo.setOrderRefundState(OrderRefundStateEnum.FINISH.getKey()); + refundOrderInfo.setOrderState(OrderStateEnum.CANCEL.getKey()); + refundOrderInfo.setUpdateBy(SecurityUtils.getUsername()); + refundOrderInfo.setUpdateTime(DateUtils.getNowDate()); + orderInfoMapper.updateOrderInfo(refundOrderInfo); } } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderShoppingCartServiceImpl.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderShoppingCartServiceImpl.java index 211b346..594e40c 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderShoppingCartServiceImpl.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/service/impl/OrderShoppingCartServiceImpl.java @@ -1,12 +1,25 @@ package com.bonus.canteen.core.order.service.impl; +import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; +import com.bonus.canteen.core.menu.enums.MenuRecipeSortEnum; +import com.bonus.canteen.core.menu.service.IMenuRecipeService; +import com.bonus.canteen.core.menu.vo.MenuRecipeDishesVO; +import com.bonus.canteen.core.order.domain.MenuDishCheckDTO; import com.bonus.canteen.core.order.domain.OrderShoppingCart; +import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam; +import com.bonus.canteen.core.order.domain.vo.OrderShoppingCartVO; import com.bonus.canteen.core.order.mapper.OrderShoppingCartMapper; +import com.bonus.canteen.core.order.module.MenuModule; import com.bonus.canteen.core.order.service.IOrderShoppingCartService; import com.bonus.common.core.utils.DateUtils; import com.bonus.common.security.utils.SecurityUtils; +import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -21,6 +34,8 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService { @Autowired private OrderShoppingCartMapper orderShoppingCartMapper; + @Autowired + private MenuModule menuModule; /** * 查询订单购物车 @@ -41,11 +56,68 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService * @return 订单购物车 */ @Override - public List selectOrderShoppingCartList(OrderShoppingCart orderShoppingCart) - { - return orderShoppingCartMapper.selectOrderShoppingCartList(orderShoppingCart); + public List selectOrderShoppingCartList(OrderShoppingCartQueryParam orderShoppingCart) { + OrderShoppingCart orderShoppingCartQuery = new OrderShoppingCart(); + orderShoppingCartQuery.setCanteenId(orderShoppingCart.getCanteenId()); + orderShoppingCartQuery.setStallId(orderShoppingCart.getStallId()); + orderShoppingCartQuery.setOrderType(orderShoppingCart.getOrderType()); + orderShoppingCartQuery.setUserId(SecurityUtils.getUserId()); + List orderShoppingCartList = orderShoppingCartMapper.selectOrderShoppingCartList(orderShoppingCartQuery); + if (CollUtil.isEmpty(orderShoppingCartList)) { + return new ArrayList<>(); + } + + MenuDishCheckDTO menuDishCheckDTO = new MenuDishCheckDTO(); + menuDishCheckDTO.setCanteenId(orderShoppingCart.getCanteenId()); + menuDishCheckDTO.setStallId(orderShoppingCart.getStallId()); + menuDishCheckDTO.setApplyType(MenuRecipeSortEnum.MOBILE_RESERVE.getKey().toString()); + + Map> groupedByOrderDate = orderShoppingCartList.stream() + .collect(Collectors.groupingBy(cart -> DateUtil.format(cart.getOrderDate(), "yyyy-MM-dd"))); + + List orderShoppingCartVOList = new ArrayList<>(); + + for (Map.Entry> entry : groupedByOrderDate.entrySet()) { + String orderDateStr = entry.getKey(); + List carts = entry.getValue(); + String filteredOrderDate = orderShoppingCart.getMenuDateList().stream().filter(orderDate -> orderDate.equals(orderDateStr)) + .findFirst().orElse(null); + + menuDishCheckDTO.setApplyDate(orderDateStr); + Map> menuRecipeDishMap = menuModule.getMenuRecipeDish(menuDishCheckDTO); + + for (OrderShoppingCart shoppingCart : carts) { + OrderShoppingCartVO shoppingCartVO = convertToOrderShoppingCartVO(shoppingCart, menuRecipeDishMap); + if(filteredOrderDate == null) { + shoppingCartVO.setIsValid(0); + } + orderShoppingCartVOList.add(shoppingCartVO); + } + } + + return orderShoppingCartVOList; } + private OrderShoppingCartVO convertToOrderShoppingCartVO(OrderShoppingCart shoppingCart, + Map> menuRecipeDishMap) { + OrderShoppingCartVO shoppingCartVO = new OrderShoppingCartVO(); + BeanUtils.copyProperties(shoppingCart, shoppingCartVO); + shoppingCartVO.setIsValid(0); + + List menuRecipeDishes = menuRecipeDishMap.get(shoppingCart.getMealtimeType()); + if (CollUtil.isNotEmpty(menuRecipeDishes)) { + for (MenuRecipeDishesVO menuRecipeDishesVO : menuRecipeDishes) { + if (shoppingCart.getGoodsId().toString().equals(menuRecipeDishesVO.getDishesId())) { + shoppingCartVO.setIsValid(1); + break; + } + } + } + + return shoppingCartVO; + } + + /** * 新增订单购物车 * diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java index 6db0766..a5911c7 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java @@ -1,25 +1,29 @@ package com.bonus.canteen.core.order.utils; +import cn.hutool.core.collection.CollUtil; import com.bonus.canteen.core.order.constants.OrderDetailTypeEnum; import com.bonus.canteen.core.order.constants.OrderTypeEnum; import com.bonus.canteen.core.order.domain.OrderShoppingCart; +import com.bonus.canteen.core.order.domain.param.OrderShoppingCartQueryParam; import com.bonus.common.core.exception.ServiceException; +import java.util.List; + public class ShoppingCartParamChecker { - public static void listCheck(OrderShoppingCart orderShoppingCart) { + public static void listCheck(OrderShoppingCartQueryParam orderShoppingCart) { checkOrderShoppingCart(orderShoppingCart); - checkUserId(orderShoppingCart); - checkCanteenId(orderShoppingCart); - checkStallId(orderShoppingCart); - checkOrderType(orderShoppingCart); + checkCanteenId(orderShoppingCart.getCanteenId()); + checkStallId(orderShoppingCart.getStallId()); + checkOrderType(orderShoppingCart.getOrderType()); + checkMenuDateList(orderShoppingCart.getMenuDateList()); } public static void addCheck(OrderShoppingCart orderShoppingCart) { checkOrderShoppingCart(orderShoppingCart); checkUserId(orderShoppingCart); checkGoodsId(orderShoppingCart); checkQuantity(orderShoppingCart); - checkCanteenId(orderShoppingCart); - checkStallId(orderShoppingCart); + checkCanteenId(orderShoppingCart.getCanteenId()); + checkStallId(orderShoppingCart.getStallId()); checkOrderDate(orderShoppingCart); checkMealtimeType(orderShoppingCart); checkDetailType(orderShoppingCart); @@ -32,7 +36,7 @@ public class ShoppingCartParamChecker { checkQuantity(orderShoppingCart); } - private static void checkOrderShoppingCart(OrderShoppingCart orderShoppingCart) { + private static void checkOrderShoppingCart(Object orderShoppingCart) { if (orderShoppingCart == null) { throw new ServiceException("订单购物车对象为空"); } @@ -61,14 +65,14 @@ public class ShoppingCartParamChecker { } } - private static void checkCanteenId(OrderShoppingCart orderShoppingCart) { - if (orderShoppingCart.getCanteenId() == null) { + private static void checkCanteenId(Long canteenId) { + if (canteenId == null) { throw new ServiceException("食堂ID为空"); } } - private static void checkStallId(OrderShoppingCart orderShoppingCart) { - if (orderShoppingCart.getStallId() == null) { + private static void checkStallId(Long stallId) { + if (stallId == null) { throw new ServiceException("档口ID为空"); } } @@ -99,13 +103,18 @@ public class ShoppingCartParamChecker { throw new ServiceException("菜谱ID为空"); } } - private static void checkOrderType(OrderShoppingCart orderShoppingCart) { - if (orderShoppingCart.getOrderType() == null) { + private static void checkOrderType(Integer orderType) { + if (orderType == null) { throw new ServiceException("订单类型为空"); } - if(OrderTypeEnum.isValidKey(orderShoppingCart.getOrderType())) { + if(OrderTypeEnum.isValidKey(orderType)) { throw new ServiceException("订单类型错误"); } } + private static void checkMenuDateList(List menuDateList) { + if (CollUtil.isEmpty(menuDateList)) { + throw new ServiceException("菜谱日期列表为空"); + } + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/pay/constants/PayStateEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/pay/constants/PayStateEnum.java index 2490acc..350b0c8 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/pay/constants/PayStateEnum.java +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/pay/constants/PayStateEnum.java @@ -24,5 +24,8 @@ public enum PayStateEnum { public String getDesc() { return this.desc; } + public static boolean isUnPay(Integer key) { + return !UN_PAY.getKey().equals(key); + } } diff --git a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuRecipeDishesMapper.xml b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuRecipeDishesMapper.xml index 6f11451..d702cda 100644 --- a/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuRecipeDishesMapper.xml +++ b/bonus-modules/bonus-smart-canteen/src/main/resources/mapper/menu/MenuRecipeDishesMapper.xml @@ -14,9 +14,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - + + + @@ -24,7 +24,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + @@ -132,6 +132,20 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" where id = #{id} + + update menu_recipe_dishes set + sale_num = sale_num + #{quantity}, + surplus_num = surplus_num - #{quantity} + where detail_id = #{dish.detailId} and dishes_id = #{dish.dishesId} + + + + update menu_recipe_dishes set + sale_num = sale_num - #{quantity}, + surplus_num = surplus_num + #{quantity} + where detail_id = #{dish.detailId} and dishes_id = #{dish.dishesId} + + delete from menu_recipe_dishes where id = #{id}