From a8d5a507e3a0077e97d5271d627b0017e6061a02 Mon Sep 17 00:00:00 2001 From: gaowdong Date: Mon, 14 Apr 2025 11:25:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B4=AD=E7=89=A9=E8=BD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/constants/OrderDetailTypeEnum.java | 31 ++++++ .../core/order/constants/OrderTypeEnum.java | 24 ++++ .../OrderShoppingCartController.java | 20 ++-- .../impl/OrderShoppingCartServiceImpl.java | 3 +- .../order/utils/ShoppingCartParamChecker.java | 103 ++++++++++++++++++ 5 files changed, 173 insertions(+), 8 deletions(-) create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderDetailTypeEnum.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderTypeEnum.java create mode 100644 bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderDetailTypeEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderDetailTypeEnum.java new file mode 100644 index 0000000..de058ca --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderDetailTypeEnum.java @@ -0,0 +1,31 @@ +package com.bonus.canteen.core.order.constants; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public enum OrderDetailTypeEnum { + DISHES(1, "菜品"), + PACKAGE(2, "套餐"), + PRODUCT(3, "商品"), + KEYAMOUNT(4, "按键金额"), + DEDUCT(5, "补扣"); + + private final Integer key; + private final String desc; + + private OrderDetailTypeEnum(Integer key, String desc) { + this.key = key; + this.desc = desc; + } + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } + +} diff --git a/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderTypeEnum.java b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderTypeEnum.java new file mode 100644 index 0000000..7979152 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/constants/OrderTypeEnum.java @@ -0,0 +1,24 @@ +package com.bonus.canteen.core.order.constants; + +public enum OrderTypeEnum { + CURR_MEAL(1, "当餐点餐"), + RESERVE_MEAL(2, "预订餐"), + ANDROID(3, "线下消费"), + DEDUCT(4, "补扣"); + + private final Integer key; + private final String desc; + + private OrderTypeEnum(Integer key, String desc) { + this.key = key; + this.desc = desc; + } + + public Integer getKey() { + return this.key; + } + + public String getDesc() { + return this.desc; + } +} 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 188da34..c876ec9 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 @@ -2,8 +2,11 @@ package com.bonus.canteen.core.order.controller; import java.util.List; +import cn.hutool.core.collection.CollUtil; import com.bonus.canteen.core.order.domain.OrderShoppingCart; import com.bonus.canteen.core.order.service.IOrderShoppingCartService; +import com.bonus.canteen.core.order.utils.ShoppingCartParamChecker; +import com.bonus.common.core.exception.ServiceException; import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; @@ -39,6 +42,7 @@ public class OrderShoppingCartController extends BaseController @ResponseBody public TableDataInfo list(OrderShoppingCart orderShoppingCart) { + ShoppingCartParamChecker.listCheck(orderShoppingCart); startPage(); List list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); return getDataTable(list); @@ -63,8 +67,9 @@ public class OrderShoppingCartController extends BaseController @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.INSERT) @PostMapping("/add") @ResponseBody - public AjaxResult addSave(OrderShoppingCart orderShoppingCart) + public AjaxResult addSave(@RequestBody OrderShoppingCart orderShoppingCart) { + ShoppingCartParamChecker.addCheck(orderShoppingCart); return toAjax(orderShoppingCartService.insertOrderShoppingCart(orderShoppingCart)); } @@ -72,11 +77,9 @@ public class OrderShoppingCartController extends BaseController * 修改订单购物车 */ @GetMapping("/edit/{shoppingCartId}") - public OrderShoppingCart edit(@PathVariable("shoppingCartId") Long shoppingCartId, ModelMap mmap) + public OrderShoppingCart edit(@PathVariable("shoppingCartId") Long shoppingCartId) { - OrderShoppingCart orderShoppingCart = orderShoppingCartService.selectOrderShoppingCartByShoppingCartId(shoppingCartId); - mmap.put("orderShoppingCart", orderShoppingCart); - return orderShoppingCart; + return orderShoppingCartService.selectOrderShoppingCartByShoppingCartId(shoppingCartId); } /** @@ -96,8 +99,11 @@ public class OrderShoppingCartController extends BaseController @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.DELETE) @PostMapping( "/remove") @ResponseBody - public AjaxResult remove(@RequestBody List ids) + public AjaxResult remove(@RequestBody List shoppingCartIds) { - return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(ids)); + if(CollUtil.isEmpty(shoppingCartIds)) { + throw new ServiceException("购物车餐品ID为空"); + } + return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(shoppingCartIds)); } } 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 002c355..211b346 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 @@ -6,6 +6,7 @@ import com.bonus.canteen.core.order.domain.OrderShoppingCart; import com.bonus.canteen.core.order.mapper.OrderShoppingCartMapper; 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.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -54,7 +55,7 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService @Override public int insertOrderShoppingCart(OrderShoppingCart orderShoppingCart) { - orderShoppingCart.setCreateTime(DateUtils.getNowDate()); + orderShoppingCart.setCreateBy(SecurityUtils.getUsername()); return orderShoppingCartMapper.insertOrderShoppingCart(orderShoppingCart); } 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 new file mode 100644 index 0000000..d509477 --- /dev/null +++ b/bonus-modules/bonus-smart-canteen/src/main/java/com/bonus/canteen/core/order/utils/ShoppingCartParamChecker.java @@ -0,0 +1,103 @@ +package com.bonus.canteen.core.order.utils; + +import com.bonus.canteen.core.order.domain.OrderShoppingCart; +import com.bonus.common.core.exception.ServiceException; + +public class ShoppingCartParamChecker { + public static void listCheck(OrderShoppingCart orderShoppingCart) { + checkOrderShoppingCart(orderShoppingCart); + checkUserId(orderShoppingCart); + checkCanteenId(orderShoppingCart); + checkStallId(orderShoppingCart); + checkOrderType(orderShoppingCart); + } + public static void addCheck(OrderShoppingCart orderShoppingCart) { + checkOrderShoppingCart(orderShoppingCart); + checkUserId(orderShoppingCart); + checkGoodsId(orderShoppingCart); + checkQuantity(orderShoppingCart); + checkCanteenId(orderShoppingCart); + checkStallId(orderShoppingCart); + checkOrderDate(orderShoppingCart); + checkMealtimeType(orderShoppingCart); + checkDetailType(orderShoppingCart); + checkMenuId(orderShoppingCart); + } + + public static void editCheck(OrderShoppingCart orderShoppingCart) { + checkOrderShoppingCart(orderShoppingCart); + checkShoppingCartId(orderShoppingCart); + checkQuantity(orderShoppingCart); + } + + private static void checkOrderShoppingCart(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart == null) { + throw new ServiceException("订单购物车对象为空"); + } + } + private static void checkShoppingCartId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getShoppingCartId() == null) { + throw new ServiceException("购车餐品ID为空"); + } + } + + private static void checkUserId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getUserId() == null) { + throw new ServiceException("用户ID为空"); + } + } + + private static void checkGoodsId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getGoodsId() == null) { + throw new ServiceException("餐品ID为空"); + } + } + + private static void checkQuantity(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getQuantity() == null) { + throw new ServiceException("餐品数量为空"); + } + } + + private static void checkCanteenId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getCanteenId() == null) { + throw new ServiceException("食堂ID为空"); + } + } + + private static void checkStallId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getStallId() == null) { + throw new ServiceException("档口ID为空"); + } + } + + private static void checkOrderDate(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getOrderDate() == null) { + throw new ServiceException("订单日期为空"); + } + } + + private static void checkMealtimeType(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getMealtimeType() == null) { + throw new ServiceException("餐次类型为空"); + } + } + + private static void checkDetailType(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getDetailType() == null) { + throw new ServiceException("订单明细类别为空"); + } + } + + private static void checkMenuId(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getMenuId() == null) { + throw new ServiceException("菜谱ID为空"); + } + } + private static void checkOrderType(OrderShoppingCart orderShoppingCart) { + if (orderShoppingCart.getOrderType() == null) { + throw new ServiceException("订单类型为空"); + } + } + +}