From a365c5b56eb054afcdfbafa36780cf64ff99ff1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=9D=BE?= <8605635+zhang3064194730@user.noreply.gitee.com> Date: Wed, 4 Dec 2024 11:42:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=82=B9=E5=8D=95=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E5=A5=97=E9=A4=90=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bean/constant/TableConstant.java | 17 ++++++ .../controller/OrderController.java | 2 +- .../cashierservice/entity/TbCashierCart.java | 1 + .../cashierservice/entity/TbOrderDetail.java | 3 +- .../cashierservice/entity/vo/CartVo.java | 4 ++ .../cashierservice/service/OrderService.java | 61 ++++++++++++++++++- 6 files changed, 83 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java b/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java index d55aa34..33f77d9 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/bean/constant/TableConstant.java @@ -20,6 +20,23 @@ public interface TableConstant { } } + class Product { + @Getter + public enum Type { + NORMAL("normal"), PACKAGE("package"); + private final String value; + + Type(String value) { + this.value = value; + } + + public boolean equalsVals(String value) { + return this.value.equals(value); + } + + } + } + class ShopTable { @Getter public enum State { diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java index 0085da8..436b46c 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -42,7 +42,7 @@ public class OrderController { String userId = jsonObject.getString("accountId"); return orderService.createCart(cartVo.getMasterId(), cartVo.getProductId(), cartVo.getShopId(), cartVo.getSkuId(), cartVo.getNumber(), userId, clientType, cartVo.getCartId(), cartVo.getIsGift(), - cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId(), cartVo.getIsPrint()); + cartVo.getIsPack(), cartVo.getUuid(), cartVo.getType(), cartVo.getTableId(), cartVo.getIsPrint(), cartVo.getGroupProductIdList()); } @PutMapping("/print") diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java index d6f05c0..0aeb5b3 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbCashierCart.java @@ -86,6 +86,7 @@ public class TbCashierCart implements Serializable { private Integer isPrint; private String useCouponInfo; private int isThirdCoupon; + private String proGroupInfo; public void copy(TbCashierCart source) { BeanUtil.copyProperties(source, this, CopyOptions.create().setIgnoreNullValue(true)); diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java index 489000d..52589da 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/TbOrderDetail.java @@ -62,7 +62,6 @@ public class TbOrderDetail implements Serializable { private BigDecimal discountSaleAmount; private String discountSaleNote; - - + private String proGroupInfo; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java index 0d754bc..849d793 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/vo/CartVo.java @@ -7,6 +7,7 @@ import javax.validation.constraints.Min; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import java.math.BigDecimal; +import java.util.List; @Data public class CartVo { @@ -27,4 +28,7 @@ public class CartVo { private String tableId; private Integer orderId; private Integer isPrint; + + // 套餐商品选择的id信息 + private List groupProductIdList; } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java index 06f1370..a879947 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -23,6 +23,7 @@ import com.chaozhanggui.system.cashierservice.entity.po.OrderPo; import com.chaozhanggui.system.cashierservice.entity.po.QueryCartPo; import com.chaozhanggui.system.cashierservice.entity.po.SkuInfoPo; import com.chaozhanggui.system.cashierservice.entity.vo.CartVo; +import com.chaozhanggui.system.cashierservice.entity.vo.ProductGroupVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.exception.NotPrintException; import com.chaozhanggui.system.cashierservice.mybatis.*; @@ -31,7 +32,6 @@ import com.chaozhanggui.system.cashierservice.rabbit.RabbitProducer; import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import com.chaozhanggui.system.cashierservice.util.*; -import com.fasterxml.jackson.core.io.BigDecimalParser; import com.github.pagehelper.PageInfo; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; @@ -215,9 +215,56 @@ public class OrderService { shopId, tableId, isTakeout ? OrderSendTypeEnums.TAKE_SELF.getValue() : OrderSendTypeEnums.TABLE.getValue()); } + + /** + * 重置购物车套餐商品信息 + */ + private void resetGroupProductCart(List productIds, TbProduct product, TbCashierCart cashierCart) { + boolean isChoseGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 1; + boolean isFixGroup = TableConstant.Product.Type.PACKAGE.equalsVals(product.getType()) && product.getGroupType() == 0; + if (isChoseGroup && productIds != null && !productIds.isEmpty()) { + String groupSnap = product.getGroupSnap(); + if (StrUtil.isNotBlank(groupSnap)) { + ArrayList foods = new ArrayList<>(); + HashMap groupVoHashMap = new HashMap<>(); + JSONObject.parseArray(groupSnap).forEach(item -> { + ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class); + productGroupVo.getGoods().forEach(goods -> { + groupVoHashMap.put(goods.getProId().toString(), goods); + }); + }); + + productIds.forEach(item -> { + ProductGroupVo.Food food = groupVoHashMap.get(item.toString()); + if (food == null) { + throw new MsgException("存在无效套餐商品"); + } + foods.add(food); + }); + + cashierCart.setProGroupInfo(JSONObject.toJSONString(foods)); + } + }else if (isFixGroup) { + String groupSnap = product.getGroupSnap(); + if (StrUtil.isNotBlank(groupSnap)) { + ArrayList foods = new ArrayList<>(); + HashMap groupVoHashMap = new HashMap<>(); + JSONObject.parseArray(groupSnap).forEach(item -> { + ProductGroupVo productGroupVo = ((JSONObject) item).toJavaObject(ProductGroupVo.class); + productGroupVo.getGoods().forEach(goods -> { + groupVoHashMap.put(goods.getProId().toString(), goods); + }); + }); + + cashierCart.setProGroupInfo(JSONObject.toJSONString(groupVoHashMap.values())); + } + } + } + @Transactional(rollbackFor = Exception.class) public Result createCart(String masterId, Integer productId, Integer shopId, Integer skuId, BigDecimal number, - String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, String type, String tableId, Integer isPrint) { + String userId, String clientType, Integer cartId, String isGift, String isPack, String uuid, + String type, String tableId, Integer isPrint, List groupProductIdList) { if (number == null) { return Result.fail(CodeEnum.PARAM); } @@ -353,6 +400,9 @@ public class OrderService { cart.resetTotalAmount(); cart.setUuid(uuid); cart.setIsPrint(isPrint); + if (product != null) { + resetGroupProductCart(groupProductIdList, product, cart); + } cashierCartMapper.updateByPrimaryKeySelective(cart); } else { List list = cashierCartMapper.selectALlByMasterId(masterId, "create"); @@ -409,6 +459,9 @@ public class OrderService { cashierCart.setUuid(uuid); cashierCart.setTableId(tableId); cashierCart.setPlatformType(OrderPlatformTypeEnum.CASH.getValue()); + if (product != null) { + resetGroupProductCart(groupProductIdList, product, cashierCart); + } list.add(cashierCart); mpCashierCartMapper.insert(cashierCart); } else { @@ -417,6 +470,9 @@ public class OrderService { } else { cashierCart.setNumber(number); } + if (product != null) { + resetGroupProductCart(groupProductIdList, product, cashierCart); + } cashierCart.setIsPrint(isPrint); cashierCart.resetTotalAmount(); mpCashierCartMapper.updateById(cashierCart); @@ -943,6 +999,7 @@ public class OrderService { saleAmount = saleAmount.add(shopInfo.getTableFee()); } + orderDetail.setProGroupInfo(cashierCart.getProGroupInfo()); orderDetail.setIsTemporary(cashierCart.getIsTemporary()); orderDetail.setDiscountSaleNote(cashierCart.getDiscountSaleNote()); orderDetail.setDiscountSaleAmount(cashierCart.getDiscountSaleAmount());