购物车

This commit is contained in:
gaowdong 2025-04-14 11:25:41 +08:00
parent dd1a88b704
commit a8d5a507e3
5 changed files with 173 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -2,8 +2,11 @@ package com.bonus.canteen.core.order.controller;
import java.util.List; import java.util.List;
import cn.hutool.core.collection.CollUtil;
import com.bonus.canteen.core.order.domain.OrderShoppingCart; import com.bonus.canteen.core.order.domain.OrderShoppingCart;
import com.bonus.canteen.core.order.service.IOrderShoppingCartService; 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.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.domain.AjaxResult;
@ -39,6 +42,7 @@ public class OrderShoppingCartController extends BaseController
@ResponseBody @ResponseBody
public TableDataInfo list(OrderShoppingCart orderShoppingCart) public TableDataInfo list(OrderShoppingCart orderShoppingCart)
{ {
ShoppingCartParamChecker.listCheck(orderShoppingCart);
startPage(); startPage();
List<OrderShoppingCart> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart); List<OrderShoppingCart> list = orderShoppingCartService.selectOrderShoppingCartList(orderShoppingCart);
return getDataTable(list); return getDataTable(list);
@ -63,8 +67,9 @@ public class OrderShoppingCartController extends BaseController
@SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.INSERT) @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.INSERT)
@PostMapping("/add") @PostMapping("/add")
@ResponseBody @ResponseBody
public AjaxResult addSave(OrderShoppingCart orderShoppingCart) public AjaxResult addSave(@RequestBody OrderShoppingCart orderShoppingCart)
{ {
ShoppingCartParamChecker.addCheck(orderShoppingCart);
return toAjax(orderShoppingCartService.insertOrderShoppingCart(orderShoppingCart)); return toAjax(orderShoppingCartService.insertOrderShoppingCart(orderShoppingCart));
} }
@ -72,11 +77,9 @@ public class OrderShoppingCartController extends BaseController
* 修改订单购物车 * 修改订单购物车
*/ */
@GetMapping("/edit/{shoppingCartId}") @GetMapping("/edit/{shoppingCartId}")
public OrderShoppingCart edit(@PathVariable("shoppingCartId") Long shoppingCartId, ModelMap mmap) public OrderShoppingCart edit(@PathVariable("shoppingCartId") Long shoppingCartId)
{ {
OrderShoppingCart orderShoppingCart = orderShoppingCartService.selectOrderShoppingCartByShoppingCartId(shoppingCartId); return orderShoppingCartService.selectOrderShoppingCartByShoppingCartId(shoppingCartId);
mmap.put("orderShoppingCart", orderShoppingCart);
return orderShoppingCart;
} }
/** /**
@ -96,8 +99,11 @@ public class OrderShoppingCartController extends BaseController
@SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.DELETE) @SysLog(title = "订单购物车", module = "订单-订单详情", businessType = OperaType.DELETE)
@PostMapping( "/remove") @PostMapping( "/remove")
@ResponseBody @ResponseBody
public AjaxResult remove(@RequestBody List<Long> ids) public AjaxResult remove(@RequestBody List<Long> shoppingCartIds)
{ {
return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(ids)); if(CollUtil.isEmpty(shoppingCartIds)) {
throw new ServiceException("购物车餐品ID为空");
}
return toAjax(orderShoppingCartService.deleteOrderShoppingCartByShoppingCartIds(shoppingCartIds));
} }
} }

View File

@ -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.mapper.OrderShoppingCartMapper;
import com.bonus.canteen.core.order.service.IOrderShoppingCartService; import com.bonus.canteen.core.order.service.IOrderShoppingCartService;
import com.bonus.common.core.utils.DateUtils; import com.bonus.common.core.utils.DateUtils;
import com.bonus.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -54,7 +55,7 @@ public class OrderShoppingCartServiceImpl implements IOrderShoppingCartService
@Override @Override
public int insertOrderShoppingCart(OrderShoppingCart orderShoppingCart) public int insertOrderShoppingCart(OrderShoppingCart orderShoppingCart)
{ {
orderShoppingCart.setCreateTime(DateUtils.getNowDate()); orderShoppingCart.setCreateBy(SecurityUtils.getUsername());
return orderShoppingCartMapper.insertOrderShoppingCart(orderShoppingCart); return orderShoppingCartMapper.insertOrderShoppingCart(orderShoppingCart);
} }

View File

@ -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("订单类型为空");
}
}
}