diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ShopEatTypeInfoDTO.java b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ShopEatTypeInfoDTO.java index 72adc54b..4c7195e4 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ShopEatTypeInfoDTO.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/dto/shoptable/ShopEatTypeInfoDTO.java @@ -13,4 +13,6 @@ public class ShopEatTypeInfoDTO { private boolean isDineInBefore; private TbShopInfo shopInfo; private String useType; + private Object shopId; + private Object tableId; } diff --git a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java index f798d3a8..464f9b75 100644 --- a/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java +++ b/eladmin-system/src/main/java/cn/ysk/cashier/service/impl/shopimpl/TbShopTableServiceImpl.java @@ -113,7 +113,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { private final MpShopInfoMapper mpShopInfoMapper; private final MpOrderDetailService mpOrderDetailService; - private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO, String tableId, Object shopId) { + private TbOrderInfo getCurrentOrder(ShopEatTypeInfoDTO eatTypeInfoDTO) { // 获取当前台桌最新订单,先付款模式不获取 if (eatTypeInfoDTO.isDineInBefore()) { return null; @@ -121,13 +121,18 @@ public class TbShopTableServiceImpl implements TbShopTableService { List orderInfoList = orderInfoMapper.selectPage(new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(1, 1), new LambdaQueryWrapper() .eq(TbOrderInfo::getStatus, "unpaid") .eq(TbOrderInfo::getUseType, eatTypeInfoDTO.getUseType()) - .eq(TbOrderInfo::getShopId, shopId) - .eq(TbOrderInfo::getTableId, tableId) + .eq(TbOrderInfo::getShopId, eatTypeInfoDTO.getShopInfo().getId()) + .eq(TbOrderInfo::getTableId, eatTypeInfoDTO.getTableId()) .eq(TbOrderInfo::getTradeDay, DateUtils.getDay()) .orderByDesc(TbOrderInfo::getId)).getRecords(); return orderInfoList.isEmpty() ? null : orderInfoList.get(0); } + private Integer getCurrentOrderId(ShopEatTypeInfoDTO eatTypeInfoDTO) { + TbOrderInfo currentOrder = getCurrentOrder(eatTypeInfoDTO); + return currentOrder == null ? null : currentOrder.getId(); + } + private TbOrderInfo getCurrentOrder(boolean isDineInAfter, String tableId, Object shopId) { // 获取当前台桌最新订单,先付款模式不获取 String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, @@ -150,12 +155,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { * @param shopId 店铺id * @return 就餐类型信息 */ - public ShopEatTypeInfoDTO checkEatModel(Object tableId, Object shopId) { + public ShopEatTypeInfoDTO checkEatModel(Object shopId, Object tableId) { String eatModel = StrUtil.isBlank(tableId.toString()) ? ShopInfoEatModelEnum.TAKE_OUT.getValue() : ShopInfoEatModelEnum.DINE_IN.getValue(); - return getShopEatTypeInfoDTO(shopId, eatModel); + return getShopEatTypeInfoDTO(shopId, eatModel, tableId); } - private ShopEatTypeInfoDTO getShopEatTypeInfoDTO(Object shopId, String eatModel) { + private ShopEatTypeInfoDTO getShopEatTypeInfoDTO(Object shopId, String eatModel, Object tableId) { TbShopInfo shopInfo = mpShopInfoMapper.selectOne(new LambdaQueryWrapper() .eq(TbShopInfo::getId, shopId) .eq(TbShopInfo::getStatus, 1)); @@ -175,15 +180,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { boolean isDineInBefore = isMunchies && !isTakeout; return new ShopEatTypeInfoDTO(isTakeout, isMunchies, isDineInAfter, isDineInBefore, shopInfo, isTakeout ? OrderUseTypeEnum.TAKEOUT.getValue() : - isMunchies ? OrderUseTypeEnum.DINE_IN_BEFORE.getValue() : OrderUseTypeEnum.DINE_IN_AFTER.getValue()); + isMunchies ? OrderUseTypeEnum.DINE_IN_BEFORE.getValue() : OrderUseTypeEnum.DINE_IN_AFTER.getValue(), shopId, tableId); } - private ShopEatTypeInfoDTO checkEatModel(Integer shopId, String useType) { - String eatModel = OrderUseTypeEnum.TAKEOUT.getValue().equals(useType) ? ShopInfoEatModelEnum.TAKE_OUT.getValue() : ShopInfoEatModelEnum.DINE_IN.getValue(); - return getShopEatTypeInfoDTO(shopId, eatModel); - } - @Override public Map queryAll(TbShopTableQueryCriteria criteria, Pageable pageable) { @@ -235,8 +235,8 @@ public class TbShopTableServiceImpl implements TbShopTableService { itemMap.put("tableId", date.getQrcode()); } - String currentOrderId = getCurrentOrderId(date.getQrcode(), date.getShopId().toString()); - TbOrderInfo orderInfo = orderInfoMapper.selectById(currentOrderId); + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(criteria.getShopId(), criteria.getQrcode()); + TbOrderInfo orderInfo = getCurrentOrder(shopEatTypeInfoDTO); itemMap.put("orderId", orderInfo == null ? null : orderInfo.getId()); itemMap.put("useType", orderInfo == null ? null : orderInfo.getUseType()); infoList.add(itemMap); @@ -343,7 +343,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { } ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(updateCartDTO.getShopId(), tbCashierCart.getUseType()); - int currentPlaceNum = getCurrentPlaceNum(tbCashierCart.getTableId().toString(), tbCashierCart.getShopId(), shopEatTypeInfoDTO); + int currentPlaceNum = getCurrentPlaceNum(shopEatTypeInfoDTO); if (tbCashierCart.getPlaceNum() != null && !tbCashierCart.getPlaceNum().equals(currentPlaceNum)) { throw new BadRequestException("已下单商品仅支持退单操作"); @@ -409,13 +409,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { /** * 获取当前台桌当前下单次数 * - * @param tableId 台桌id - * @param shopId 店铺id * @param shopEatTypeInfoDTO 用餐类型 * @return 对应的次数,为order最后次数+1 */ - private int getCurrentPlaceNum(String tableId, Object shopId, ShopEatTypeInfoDTO shopEatTypeInfoDTO) { - TbOrderInfo orderInfo = getCurrentOrder(shopEatTypeInfoDTO, tableId, shopId); + private int getCurrentPlaceNum(ShopEatTypeInfoDTO shopEatTypeInfoDTO) { + TbOrderInfo orderInfo = getCurrentOrder(shopEatTypeInfoDTO); return orderInfo == null ? 1 : orderInfo.getPlaceNum() + 1; } @@ -559,9 +557,9 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public void removeCart(RemoveCartDTO removeCartDTO) { - ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(removeCartDTO.getTableId(), removeCartDTO.getShopId()); + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(removeCartDTO.getShopId(), removeCartDTO.getTableId()); - int currentPlaceNum = getCurrentPlaceNum(removeCartDTO.getTableId() == null ? "" : removeCartDTO.getTableId().toString(), removeCartDTO.getShopId().toString(), shopEatTypeInfoDTO); + int currentPlaceNum = getCurrentPlaceNum(shopEatTypeInfoDTO); // 会员点单 TbCashierCart cashierCart = cashierCartMapper.selectOne(new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, removeCartDTO.getShopId()) @@ -667,11 +665,12 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public void clearCart(ClearCartDTO clearCartDTO) { - String orderId; + Integer orderId; + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(clearCartDTO.getShopId(), clearCartDTO.getTableId()); if (clearCartDTO.getTableId() != null) { - orderId = getCurrentOrderId(clearCartDTO.getTableId().toString(), clearCartDTO.getShopId()); + orderId = getCurrentOrderId(shopEatTypeInfoDTO); } else { - orderId = ""; + orderId = null; } LambdaQueryWrapper query = new LambdaQueryWrapper() @@ -1053,7 +1052,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { // 传递orderId直接取否则取当前缓存id Integer orderId = shopEatTypeInfoDTO.isDineInAfter() ? - Integer.valueOf(getCurrentOrderId(createOrderDTO.getTableId(), createOrderDTO.getShopId())) : null; + getCurrentOrderId(shopEatTypeInfoDTO) : null; LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper() .eq(TbCashierCart::getShopId, createOrderDTO.getShopId()) @@ -1113,7 +1112,7 @@ public class TbShopTableServiceImpl implements TbShopTableService { BigDecimal feeAmount = BigDecimal.ZERO; BigDecimal saleAmount = BigDecimal.ZERO; // 当前下单次数 - int placeNum = getCurrentPlaceNum(createOrderDTO.getTableId(), String.valueOf(createOrderDTO.getShopId()), shopEatTypeInfoDTO); + int placeNum = getCurrentPlaceNum(shopEatTypeInfoDTO); List orderDetails = new ArrayList<>(); BigDecimal mealAmount = null; @@ -1624,10 +1623,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { return cashierCartMapper.update(null, queryWrapper); } - private String getCurrentOrderId(String tableId, Object shopId) { - String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId.toString()); - return redisTemplate.opsForValue().get(currentOrderKey); - } private void setCurrentOrderId(String tableId, Object shopId, String orderId) { String currentOrderKey = RedisConstant.getCurrentOrderKey(tableId, shopId.toString()); @@ -1644,8 +1639,6 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object choseTable(ChoseTableDTO choseTableDTO) { String masterId = getMasterId(choseTableDTO.getShopId(), Long.valueOf(choseTableDTO.getNewTableId()), null).getString("masterId"); - String currentOrderId = choseTableDTO.getOrderId() == null ? getCurrentOrderId(choseTableDTO.getOldTableId(), - choseTableDTO.getShopId().toString()) : choseTableDTO.getOrderId().toString(); TbShopTable shopTable = mpShopTableMapper.selectOne(new LambdaQueryWrapper() .eq(TbShopTable::getQrcode, choseTableDTO.getNewTableId()) @@ -1654,6 +1647,11 @@ public class TbShopTableServiceImpl implements TbShopTableService { throw new BadRequestException("台桌不存在或非空闲状态"); } + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(choseTableDTO.getShopId(), choseTableDTO.getNewTableId()); + TbOrderInfo currentOrder = getCurrentOrder(shopEatTypeInfoDTO); + Integer currentOrderId = currentOrder == null ? null : currentOrder.getId(); + + cashierCartMapper.update(null, new LambdaUpdateWrapper() .eq(TbCashierCart::getTableId, choseTableDTO.getOldTableId()) .in(TbCashierCart::getStatus, "create", "return") @@ -1748,10 +1746,10 @@ public class TbShopTableServiceImpl implements TbShopTableService { @Override public Object printOrder(BaseTableDTO baseTableDTO) { - checkTableState(baseTableDTO.getTableId()); + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(baseTableDTO.getTableId(), baseTableDTO.getTableId()); - String currentOrderId = getCurrentOrderId(baseTableDTO.getTableId(), baseTableDTO.getShopId().toString()); - if (StrUtil.isBlank(currentOrderId)) { + Integer currentOrderId = getCurrentOrderId(shopEatTypeInfoDTO); + if (currentOrderId == null) { throw new BadRequestException("当前台桌不存在订单"); } TbOrderInfo orderInfo = orderInfoMapper.selectById(currentOrderId); @@ -1810,23 +1808,13 @@ public class TbShopTableServiceImpl implements TbShopTableService { } return tbShopTable; } - - private TbOrderInfo getCurrentOrder(String tableId, String shopId) { - String currentOrderId = getCurrentOrderId(tableId, shopId); - if (StrUtil.isBlank(currentOrderId)) { - throw new BadRequestException("当前台桌不存在订单"); - } - TbOrderInfo orderInfo = orderInfoMapper.selectById(currentOrderId); - if (orderInfo == null) { - throw new BadRequestException("当前台桌不存在订单"); - } - return orderInfo; - } - @Override public Object printDishes(BaseTableDTO baseTableDTO) { - checkTableState(baseTableDTO.getTableId()); - TbOrderInfo currentOrder = getCurrentOrder(baseTableDTO.getTableId(), baseTableDTO.getShopId().toString()); + ShopEatTypeInfoDTO shopEatTypeInfoDTO = checkEatModel(baseTableDTO.getShopId(), baseTableDTO.getTableId()); + TbOrderInfo currentOrder = getCurrentOrder(shopEatTypeInfoDTO); + if (currentOrder == null) { + throw new BadRequestException("当前台桌不存在订单"); + } List detailList = orderDetailMapper.selectList(new LambdaQueryWrapper() .eq(TbOrderDetail::getOrderId, currentOrder.getId()) .eq(TbOrderDetail::getStatus, "unpaid")