From b018b321edb20719afb28eabf0da6ccd14a78a61 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, 26 Feb 2025 15:57:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/account/print/PrinterHandler.java | 56 ++++++++++--------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/print/PrinterHandler.java b/cash-service/account-service/src/main/java/com/czg/service/account/print/PrinterHandler.java index 4a7a9a551..07d73eee3 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/print/PrinterHandler.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/print/PrinterHandler.java @@ -1,5 +1,6 @@ package com.czg.service.account.print; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ArrayUtil; @@ -78,7 +79,7 @@ public abstract class PrinterHandler { @Accessors(chain = true) public static class PrintDetailInfo { private boolean isPrint; -// private boolean isReturn; + // private boolean isReturn; private long orderId; private long detailId; private BigDecimal printNum; @@ -145,31 +146,37 @@ public abstract class PrinterHandler { } protected List getCanPrintOrderDetails(boolean partPrint, Long orderId, List tbOrderDetailList, List categoryIds) { - List detailList = redisService.lGet(RedisCst.getPrintOrderDetailKey(orderId), 0, -1); - Map detailMap = detailList.stream().collect(Collectors.toMap(i -> { - if (i instanceof PrintDetailInfo i2) { - return i2.getDetailId(); - } - throw new RuntimeException("转换orderDetail失败"); - }, i -> (PrintDetailInfo) i)); - List productIds = tbOrderDetailList.stream().map(OrderDetail::getProductId).collect(Collectors.toList()); Map canPrintProMap = partPrint || categoryIds.isEmpty() ? new HashMap<>() : productService.list(new QueryWrapper().in(Product::getCategoryId, categoryIds).in(Product::getId, productIds)) - .stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true)); + .stream().collect(Collectors.toMap(com.czg.product.entity.Product::getId, i -> true)); ArrayList orderDetails = new ArrayList<>(); tbOrderDetailList.forEach(item -> { - PrintDetailInfo printDetailInfo = detailMap.get(item.getId()); - if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint) && - (printDetailInfo == null || item.getNum().subtract(printDetailInfo.getPrintNum()).compareTo(BigDecimal.ZERO) > 0)) { + Object o = redisService.get(RedisCst.getPrintOrderDetailKey(orderId, item.getId())); + + if (item.getIsPrint() != null && item.getIsPrint() == 1 && (canPrintProMap.get(item.getProductId()) != null || !partPrint)) { item.setReturnNum(item.getReturnNum() == null ? BigDecimal.ZERO : item.getReturnNum()); + PrintDetailInfo printDetailInfo = o != null ? JSONObject.parseObject((String) o, PrintDetailInfo.class) : null; if (printDetailInfo != null) { + if (item.getNum().compareTo(printDetailInfo.getPrintNum()) <= 0) { + log.info("此菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo); + } + + if (item.getReturnNum().compareTo(printDetailInfo.getPrintReturnNum()) <= 0) { + log.info("此退菜菜品已打印, {} {} {}", item.getProductName(), item.getSkuName(), printDetailInfo); + } item.setNum(item.getNum().subtract(printDetailInfo.getPrintNum())); - item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintNum())); + item.setReturnNum(item.getReturnNum().subtract(printDetailInfo.getPrintReturnNum())); + orderDetails.add(item); + }else { + orderDetails.add(item); } - orderDetails.add(item); + + + } else { + log.info("此菜品不在打印分类或属于免打, {} {} {}", item.getProductName(), item.getSkuName(), item.getId()); } }); @@ -200,7 +207,7 @@ public abstract class PrinterHandler { } default -> log.warn("未知打印类型: {}", printMethod); } - }else { + } else { log.info("准备开始打印叫号单"); if (StrUtil.isBlank(machine.getPrintType())) { return; @@ -241,10 +248,8 @@ public abstract class PrinterHandler { } // 已打印详情信息 - ArrayList printDetailInfos = new ArrayList<>(); - Map detailMap = tbOrderDetailList.stream().collect(Collectors.toMap(OrderDetail::getId, i -> i)); + Map detailMap = tbOrderDetailList.stream().map(item -> BeanUtil.copyProperties(item, OrderDetail.class)).collect(Collectors.toMap(OrderDetail::getId, i -> i)); tbOrderDetailList = getCanPrintOrderDetails("1".equals(machine.getClassifyPrint()), orderInfo.getId(), tbOrderDetailList, categoryIds); - String printKey = RedisCst.getPrintOrderDetailKey(orderInfo.getId()); tbOrderDetailList.parallelStream().filter(o -> ObjectUtil.defaultIfNull(o.getIsPrint(), 0) == 1).forEach(item -> { log.info("开始打印菜品,商品名:{}", item.getProductName()); Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0); @@ -291,8 +296,8 @@ public abstract class PrinterHandler { // 保存已打印信息 OrderDetail orderDetail = detailMap.get(item.getId()); - redisService.leftPush(printKey, new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId()) - .setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum())); + redisService.set(RedisCst.getPrintOrderDetailKey(orderInfo.getId(), item.getId()), JSONObject.toJSONString(new PrintDetailInfo().setPrint(item.getIsPrint() == 1).setDetailId(item.getId()) + .setPrintNum(orderDetail.getNum()).setPrintReturnNum(orderDetail.getReturnNum())), 3600 * 24); }); @@ -383,10 +388,10 @@ public abstract class PrinterHandler { CallTable tbCallTable = callTableService.getById(queue.getCallTableId()); ShopInfo shopInfo = shopInfoService.getById(queue.getShopId()); callNumPrint(machine, queue.getCallNum(), shopInfo.getShopName(), tbCallTable.getName(), tbCallTable.getNote(), String.valueOf(callQueueService.count(new QueryWrapper() - .eq(CallQueue::getShopId, queue.getShopId()) - .eq(CallQueue::getCallTableId, queue.getCallTableId()) - .lt(CallQueue::getId, queue.getId()) - .in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(), + .eq(CallQueue::getShopId, queue.getShopId()) + .eq(CallQueue::getCallTableId, queue.getCallTableId()) + .lt(CallQueue::getId, queue.getId()) + .in(CallQueue::getState, 0, 1))), callUrl == null ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(), StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum())); } @@ -399,6 +404,7 @@ public abstract class PrinterHandler { /** * 根据订单信息判断是否是退单 + * * @param orderInfo 顶动感信息 * @return 是否退款 */