From a9ebf37fc54e5a7e069edde2852603adab430f41 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, 11 Dec 2024 11:10:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=BD=AC=E5=8F=B0=E5=B9=B6=E5=8F=B0?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 8 ++ .../entity/dto/SwitchTableDTO.java | 23 ++++ .../service/MpCashierCartService.java | 12 ++ .../service/MpShopTableService.java | 7 ++ .../cashierservice/service/OrderService.java | 116 ++++++++++++++++++ .../impl/MpCashierCartServiceImpl.java | 98 ++++++++++++++- .../service/impl/MpShopTableServiceImpl.java | 7 ++ 7 files changed, 268 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SwitchTableDTO.java 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 436b46c..8f9eee5 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/OrderController.java @@ -143,6 +143,14 @@ public class OrderController { return orderService.createOrder(orderVo, clientType, token, null); } + /** + * 转台并台 + */ + @PutMapping("/switch") + public ResponseEntity switchTable(@Validated @RequestBody SwitchTableDTO switchTableDTO, @RequestHeader("token") String token) { + return ResponseEntity.ok(orderService.switchTable(switchTableDTO, token)); + } + @PostMapping("/createBackOrder") public Result createBackOrder(@RequestHeader("token") String token, @RequestHeader("loginName") String loginName, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SwitchTableDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SwitchTableDTO.java new file mode 100644 index 0000000..833fd76 --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/SwitchTableDTO.java @@ -0,0 +1,23 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotEmpty; +import javax.validation.constraints.NotNull; +import java.util.List; + +@Data +public class SwitchTableDTO { + @NotNull + private Integer shopId; + @NotEmpty(message = "取餐码不为空") + private String masterId; + private Integer orderId; + private List cartIds; + private Boolean isFull; + @NotEmpty(message = "当前台桌id不为空") + private String currentTableId; + @NotEmpty(message = "目标台桌id不为空") + private String targetTableId; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java index 683107b..b207ab4 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpCashierCartService.java @@ -61,5 +61,17 @@ public interface MpCashierCartService extends IService { * @param statuses 状态 */ List selectByIds(Integer shopId, Integer orderId, List ids, TableConstant.OrderInfo.Status... statuses); + + /** + * 根据就餐模式查询购物车信息 + * @param shopEatTypeInfoDTO 就餐模式 + * @param masterId 取餐码 + * @param orderId 订单id + * @param onlySearchPc 只查询pc + * @param statuses 状态 + */ + List selectByShopEatTypeAndOrderId(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses); + + Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpShopTableService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpShopTableService.java index 5300157..7ec5c66 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/MpShopTableService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/MpShopTableService.java @@ -15,5 +15,12 @@ import java.util.List; */ public interface MpShopTableService extends IService { + /** + * 查询台桌信息 + * @param tableId 台桌id + * @param shopId 店铺id + * @return 台桌信息 + */ + TbShopTable selectByTableId(String tableId, Integer shopId); } 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 f9e1b49..e276727 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/OrderService.java @@ -2392,4 +2392,120 @@ public class OrderService { return Result.success(CodeEnum.SUCCESS); } + + @Transactional(rollbackFor = Exception.class) + public Object switchTable(SwitchTableDTO switchTableDTO, String token) { + // 查询当前台桌信息 + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(switchTableDTO.getShopId(), switchTableDTO.getCurrentTableId()); + ShopEatTypeInfoDTO targetShopEatTypeInfoDTO = checkEatModel(switchTableDTO.getShopId(), switchTableDTO.getTargetTableId()); + if (!shopEatTypeInfoDTO.isDineInAfter()) { + throw new MsgException("仅后付费模式支持转台"); + } + TbShopTable shopTable = mpShopTableService.selectByTableId(switchTableDTO.getTargetTableId(), switchTableDTO.getShopId()); + if (shopTable == null) { + throw new MsgException("目标台桌信息不存在"); + } + + if (TableConstant.ShopTable.State.CLEANING.getValue().equals(shopTable.getStatus())) { + throw new MsgException("当前台桌清理中,不能转台"); + } + + List cashierCarts; + long totalSize = 99999; + if (switchTableDTO.getIsFull() != null && switchTableDTO.getIsFull()) { + cashierCarts = mpCashierCartService.selectByShopEatTypeAndOrderId(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(), + true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); + }else { + if (switchTableDTO.getCartIds().isEmpty()) { + throw new MsgException("请选择转单商品"); + } + + totalSize = mpCashierCartService.countByShopEatType(shopEatTypeInfoDTO, switchTableDTO.getMasterId(), switchTableDTO.getOrderId(), + true, TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); + cashierCarts = mpCashierCartService.selectByIds(switchTableDTO.getShopId(), null, switchTableDTO.getCartIds(), + TableConstant.OrderInfo.Status.CREATE, TableConstant.OrderInfo.Status.RETURN); + } + + if (cashierCarts.isEmpty()) { + throw new MsgException("当前台桌购物车为空"); + } + + String masterId = ((JSONObject)createCode(switchTableDTO.getShopId().toString(), "pc", "", "0", switchTableDTO.getTargetTableId()).getData()).getString("code"); +// String masterId = getMasterId(switchTableDTO.getShopId(), switchTableDTO.getTargetTableId(), null).getString("masterId"); + // 查询目标购物车 + List targetCarts = mpCashierCartService.selectByShopEatTypeAndOrderId(targetShopEatTypeInfoDTO, masterId, null, false); + TbCashierCart targetSeatFee = null; + Integer targetOrderId = null; + for (TbCashierCart targetCart : targetCarts) { + if (TableConstant.CART_SEAT_ID.equals(targetCart.getProductId())) { + targetSeatFee = targetCart; + } + + if (targetCart.getOrderId() != null) { + targetOrderId = targetCart.getOrderId(); + } + } + + // 修改原有购物车数据 + ArrayList cartIds = new ArrayList<>(); + Integer orderId = switchTableDTO.getOrderId(); + TbCashierCart currentSeatFee = null; + ArrayList updateCartInfos = new ArrayList<>(); + for (TbCashierCart item : cashierCarts) { + if (targetSeatFee == null || !TableConstant.CART_SEAT_ID.equals(item.getProductId())) { + item.setTableId(switchTableDTO.getTargetTableId()); + item.setMasterId(masterId); + updateCartInfos.add(item); + } + cartIds.add(item.getId()); + + if (item.getOrderId() != null) { + orderId = item.getOrderId(); + } + + if (TableConstant.CART_SEAT_ID.equals(item.getProductId())) { + currentSeatFee = item; + } + } + + if (currentSeatFee != null && targetSeatFee != null) { + targetSeatFee.setNumber(currentSeatFee.getNumber().add(targetSeatFee.getNumber())); + targetSeatFee.setTotalNumber(currentSeatFee.getTotalNumber().add(targetSeatFee.getTotalNumber())); + targetSeatFee.setTotalAmount(targetSeatFee.getSalePrice().multiply(targetSeatFee.getTotalNumber())); + mpCashierCartService.updateById(targetSeatFee); + mpCashierCartService.removeById(currentSeatFee.getId()); + } + mpCashierCartService.updateBatchById(updateCartInfos); + mpCashierCartService.update(new LambdaUpdateWrapper() + .in(TbCashierCart::getId, cartIds) + .set(TbCashierCart::getOrderId, null) + .set(TbCashierCart::getPlaceNum, null)); + mpOrderDetailService.removeByCartIds(cartIds); + + // 删除原有台桌detail和order信息 + if (orderId != null && ((switchTableDTO.getIsFull() != null && switchTableDTO.getIsFull()) || switchTableDTO.getCartIds().size() == totalSize)) { + mpOrderInfoService.removeById(orderId); + } + + if (switchTableDTO.getIsFull() != null && !switchTableDTO.getIsFull() && switchTableDTO.getCartIds().size() != totalSize){ + // 重新创建订单数据 + OrderVo createOrderDTO = new OrderVo(); + createOrderDTO.setMasterId(switchTableDTO.getMasterId()); + createOrderDTO.setShopId(switchTableDTO.getShopId()); + createOrderDTO.setTableId(switchTableDTO.getCurrentTableId()); + createOrder(createOrderDTO, "pc", token, switchTableDTO.getOrderId()); + } + + if (targetOrderId != null) { + // 重新创建订单数据 + OrderVo createOrderDTO = new OrderVo(); + createOrderDTO.setMasterId(masterId); + createOrderDTO.setShopId(switchTableDTO.getShopId()); + createOrderDTO.setTableId(switchTableDTO.getTargetTableId()); + createOrder(createOrderDTO, "pc", token, targetOrderId); + } + + return true; + + } } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java index dc5d153..119a319 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpCashierCartServiceImpl.java @@ -4,9 +4,11 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.chaozhanggui.system.cashierservice.bean.OrderPlatformTypeEnum; import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant; import com.chaozhanggui.system.cashierservice.entity.TbCashierCart; import com.chaozhanggui.system.cashierservice.entity.TbOrderDetail; @@ -17,8 +19,10 @@ import com.chaozhanggui.system.cashierservice.service.MpCashierCartService; import com.chaozhanggui.system.cashierservice.service.MpOrderDetailService; import org.springframework.stereotype.Service; +import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /** * (TbShopPermission)表服务实现类 @@ -96,7 +100,9 @@ public class MpCashierCartServiceImpl extends ServiceImpl selectByIds(Integer shopId, Integer orderId, List ids, TableConstant.OrderInfo.Status... statuses) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, shopId) - .eq(TbCashierCart::getOrderId, orderId) .in(TbCashierCart::getId, ids); + if (orderId != null) { + queryWrapper.eq(TbCashierCart::getOrderId, orderId); + } if (statuses.length != 0) { - queryWrapper.in(TbCashierCart::getStatus, CollUtil.newArrayList(statuses)); + queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses) + .map(TableConstant.OrderInfo.Status::getValue) + .collect(Collectors.toList())); } return list(queryWrapper); } + @Override + public List selectByShopEatTypeAndOrderId(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, + Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) + .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) + .and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId)); + + if (statuses.length == 0) { + queryWrapper.in(TbCashierCart::getStatus, "create", "return"); + } else { + queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses) + .map(TableConstant.OrderInfo.Status::getValue) + .collect(Collectors.toList())); + } + + if (orderId != null) { + queryWrapper.and(q -> q.eq(TbCashierCart::getOrderId, orderId) + .or().isNull(TbCashierCart::getOrderId)); + } + + if (onlySearchPc) { + queryWrapper.ne(TbCashierCart::getPlatformType, "mimiapp"); + } + + // 非堂食校验台桌状态 + if (shopEatTypeInfoDTO.isTakeout()) { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) + .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); + } else { + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId()); + } else { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")); + } + + } + return list(queryWrapper); + } + + @Override + public Long countByShopEatType(ShopEatTypeInfoDTO shopEatTypeInfoDTO, String masterId, + Integer orderId, boolean onlySearchPc, TableConstant.OrderInfo.Status... statuses) { + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() + .eq(TbCashierCart::getShopId, shopEatTypeInfoDTO.getShopId()) + .eq(TbCashierCart::getUseType, shopEatTypeInfoDTO.getUseType()) + .gt(TbCashierCart::getCreatedAt, DateUtil.offsetDay(DateUtil.date(), -1).getTime()) + .and(q -> q.eq(TbCashierCart::getMasterId, masterId).or().isNull(TbCashierCart::getMasterId)); + + if (statuses.length == 0) { + queryWrapper.in(TbCashierCart::getStatus, "create", "return"); + } else { + queryWrapper.in(TbCashierCart::getStatus, Arrays.stream(statuses) + .map(TableConstant.OrderInfo.Status::getValue) + .collect(Collectors.toList())); + } + + if (orderId != null) { + queryWrapper.and(q -> q.eq(TbCashierCart::getOrderId, orderId) + .or().isNull(TbCashierCart::getOrderId)); + } + + if (onlySearchPc) { + queryWrapper.ne(TbCashierCart::getPlatformType, "mimiapp"); + } + + // 非堂食校验台桌状态 + if (shopEatTypeInfoDTO.isTakeout()) { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")) + .in(TbCashierCart::getPlatformType, OrderPlatformTypeEnum.PC.getValue(), OrderPlatformTypeEnum.CASH.getValue()); + } else { + if (StrUtil.isNotBlank(shopEatTypeInfoDTO.getTableId())) { + queryWrapper.eq(TbCashierCart::getTableId, shopEatTypeInfoDTO.getTableId()); + } else { + queryWrapper.and(q -> q.isNull(TbCashierCart::getTableId).or().eq(TbCashierCart::getTableId, "")); + } + + } + return (long) count(queryWrapper); + } + } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpShopTableServiceImpl.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpShopTableServiceImpl.java index 42a912c..3bf31e6 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpShopTableServiceImpl.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/impl/MpShopTableServiceImpl.java @@ -1,5 +1,6 @@ package com.chaozhanggui.system.cashierservice.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.chaozhanggui.system.cashierservice.bean.constant.TableConstant; @@ -22,6 +23,12 @@ import java.util.List; @Service public class MpShopTableServiceImpl extends ServiceImpl implements MpShopTableService { + @Override + public TbShopTable selectByTableId(String tableId, Integer shopId) { + return getOne(new LambdaQueryWrapper() + .eq(TbShopTable::getShopId, shopId) + .eq(TbShopTable::getQrcode, tableId)); + } }