From 021fd32228345836281ab44bd911c711261f4b8d Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Fri, 17 Apr 2026 10:21:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=92=E9=98=9F=E5=B0=8F=E7=A5=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/czg/config/RedisCst.java | 6 +-- .../java/com/czg/print/CallTablePrintDTO.java | 27 ++++++++++++ .../service/impl/CallTableServiceImpl.java | 16 +++++++ .../czg/service/order/print/FeiPrinter.java | 5 +-- .../czg/service/order/print/PrintConfig.java | 27 +++++------- .../service/order/print/PrinterHandler.java | 24 +++------- .../czg/service/order/print/PrinterImpl.java | 44 ++++++++++--------- .../czg/service/order/print/YxyPrinter.java | 5 +-- 8 files changed, 91 insertions(+), 63 deletions(-) create mode 100644 cash-common/cash-common-service/src/main/java/com/czg/print/CallTablePrintDTO.java diff --git a/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java index 165e5632e..68406fbc0 100644 --- a/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java +++ b/cash-common/cash-common-redis/src/main/java/com/czg/config/RedisCst.java @@ -57,7 +57,7 @@ public interface RedisCst { //后厨总单 public static final String ALL = "print:kitchen:all"; //菜品单 - public static final String NORMAL = "print:kitchen:normal"; + public static final String ONLY = "print:kitchen:only"; //退菜单 public static final String REFUND_ALL = "print:kitchen:refundAll"; } @@ -91,8 +91,8 @@ public interface RedisCst { * * @param machineId 打印机设备id */ - static String kitchenNormal(Long orderId, Long machineId, Long detailId) { - return kitchen.NORMAL + orderId + ":" + machineId + ":" + detailId; + static String kitchenOnly(Long orderId, Long machineId, Long detailId) { + return kitchen.ONLY + orderId + ":" + machineId + ":" + detailId; } /** diff --git a/cash-common/cash-common-service/src/main/java/com/czg/print/CallTablePrintDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/print/CallTablePrintDTO.java new file mode 100644 index 000000000..ec8b6b5c0 --- /dev/null +++ b/cash-common/cash-common-service/src/main/java/com/czg/print/CallTablePrintDTO.java @@ -0,0 +1,27 @@ +package com.czg.print; + +import com.czg.account.entity.CallQueue; +import com.czg.account.entity.CallTable; +import lombok.Data; + +import java.io.Serial; +import java.io.Serializable; + +/** + * @author ww + */ +@Data +public class CallTablePrintDTO implements Serializable { + + @Serial + private static final long serialVersionUID = 1L; + + private CallQueue callQueue; + + private CallTable callTable; + + //二维码地址 + private String callUrl; + + private Long preNum; +} diff --git a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/CallTableServiceImpl.java b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/CallTableServiceImpl.java index a7fd4636b..86bd04dd8 100644 --- a/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/CallTableServiceImpl.java +++ b/cash-service/account-service/src/main/java/com/czg/service/account/service/impl/CallTableServiceImpl.java @@ -13,6 +13,7 @@ import com.czg.config.RabbitPublisher; import com.czg.config.RedisCst; import com.czg.constants.ParamCodeCst; import com.czg.exception.CzgException; +import com.czg.print.CallTablePrintDTO; import com.czg.resp.CzgResult; import com.czg.service.RedisService; import com.czg.service.account.mapper.CallQueueMapper; @@ -220,6 +221,21 @@ public class CallTableServiceImpl extends ServiceImpl orderDetailList; }; + redisService.set("order:print:" + orderInfo.getId(), "", 180); for (PrintMachine machine : getPrintMachine(orderInfo.getShopId(), printTypeEnum)) { PrinterHandler printer = getPrinter(machine.getBrand()); - redisService.set("order:print:" + orderInfo.getId(), "", 180); switch (printTypeEnum) { case PrinterHandler.PrintTypeEnum.GUEST_ORDER: log.info("准备开始打印客看订单"); @@ -139,20 +138,20 @@ public class PrintConfig implements ApplicationRunner { log.info("准备开始打印菜品单"); //后厨单菜品 tbOrderDetailList.forEach(item -> { - Boolean b = redisService.hasKey(RedisCst.kitchenNormal(orderInfo.getId(), machine.getId(), item.getId())); - if (!b) { +// Boolean b = redisService.hasKey(RedisCst.kitchenOnly(orderInfo.getId(), machine.getId(), item.getId())); +// if (!b) { FunUtils.safeRunVoid(() -> printer.onlyKitchenPrint(orderInfo, item, machine), "订单id:{} ,后厨分单打印失败", orderInfo.getId()); // 保存已打印信息 - redisService.set(RedisCst.kitchenNormal(orderInfo.getId(), machine.getId(), item.getId()), "", 180); - } +// redisService.set(RedisCst.kitchenOnly(orderInfo.getId(), machine.getId(), item.getId()), "", 180); +// } }); break; case PrinterHandler.PrintTypeEnum.ALL_KITCHEN: - Boolean exit = redisService.hasKey(RedisCst.kitchenAll(orderInfo.getId(), machine.getId())); - if (exit) { - break; - } +// Boolean exit = redisService.hasKey(RedisCst.kitchenAll(orderInfo.getId(), machine.getId())); +// if (exit) { +// break; +// } // 判断订单是否是先付费或者已结算 if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) { log.warn("此订单未支付, 订单信息: {}", orderInfo.getId()); @@ -164,7 +163,7 @@ public class PrintConfig implements ApplicationRunner { } log.info("准备开始打印后厨整单"); printer.allKitchenPrint(orderInfo, allOrderDetailList, machine); - redisService.set(RedisCst.kitchenAll(orderInfo.getId(), machine.getId()), "", 180); +// redisService.set(RedisCst.kitchenAll(orderInfo.getId(), machine.getId()), "", 180); break; } } @@ -217,7 +216,7 @@ public class PrintConfig implements ApplicationRunner { log.info("准备开始打印叫号单"); getPrintMachine(shopId, printTypeEnum) .forEach(machine -> getPrinter(machine.getBrand()) - .callNumPrintBefore(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), CallQueue.class))); + .callNumPrintBefore(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), CallTablePrintDTO.class))); break; default: throw new CzgException("otherHandler 未知打印类型"); @@ -287,10 +286,6 @@ public class PrintConfig implements ApplicationRunner { if (item.getNum().compareTo(BigDecimal.ZERO) <= 0 || item.getProductId().equals(-999L)) { continue; } - Boolean isPrint = redisService.hasKey(RedisCst.kitchenNormal(orderId, machine.getId(), item.getId())); - if (isPrint) { - continue; - } if (item.getIsPrint() != null && item.getIsPrint() == 1 && (!partPrint || canPrintProSet.contains(item.getProductId()))) { orderDetails.add(item); } else { diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterHandler.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterHandler.java index f779ca5cf..7ec292feb 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterHandler.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterHandler.java @@ -5,9 +5,10 @@ import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.czg.account.dto.HandoverRecordDTO; import com.czg.account.dto.PrintOrderDetailDTO; -import com.czg.account.entity.*; +import com.czg.account.entity.PrintMachine; +import com.czg.account.entity.ShopInfo; +import com.czg.account.entity.ShopStaff; import com.czg.account.service.*; -import com.czg.constants.ParamCodeCst; import com.czg.market.service.OrderInfoService; import com.czg.order.entity.OrderDetail; import com.czg.order.entity.OrderInfo; @@ -29,7 +30,6 @@ import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; import java.math.RoundingMode; -import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; @@ -206,21 +206,12 @@ public abstract class PrinterHandler { /** * 打印排队小票 */ - public void callNumPrintBefore(PrintMachine machine, String shopName, CallQueue queue) { - if (queue == null) { + public void callNumPrintBefore(PrintMachine machine, String shopName, CallTablePrintDTO queue) { + if (queue == null || queue.getCallQueue() == null || queue.getCallTable() == null) { log.warn("叫号记录不存在"); return; } - String callUrl = sysParamsService.getSysParamValue(ParamCodeCst.System.CALL_PAGE_URL); - CallTable tbCallTable = callTableService.getById(queue.getCallTableId()); - long count = callQueueService.count(new QueryWrapper() - .eq(CallQueue::getShopId, queue.getShopId()) - .eq(CallQueue::getCallTableId, queue.getCallTableId()) - .lt(CallQueue::getId, queue.getId()) - .in(CallQueue::getState, 0, 1)); - callNumPrint(machine, queue.getCallNum(), shopName, tbCallTable.getName(), tbCallTable.getNote(), String.valueOf(count), - StrUtil.isEmpty(callUrl) ? "未配置页面" : StrUtil.format(callUrl, queue.getShopId(), queue.getId()), queue.getCreateTime(), - StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", tbCallTable.getPostponeNum(), tbCallTable.getPostponeNum())); + callNumPrint(machine, shopName, queue); } /** @@ -360,8 +351,7 @@ public abstract class PrinterHandler { /** * 叫号打印 */ - protected abstract void callNumPrint(PrintMachine machine, String callNum, String shopName, String tableName, String tableNote, String preNum, - String codeUrl, LocalDateTime takeTime, String shopNote); + protected abstract void callNumPrint(PrintMachine machine, String shopName, CallTablePrintDTO queue); /** * 出入库打印单 √ diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterImpl.java index 973f3e041..1a64afaaa 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/PrinterImpl.java @@ -9,6 +9,8 @@ import cn.hutool.json.JSONUtil; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.czg.account.dto.HandoverRecordDTO; +import com.czg.account.entity.CallQueue; +import com.czg.account.entity.CallTable; import com.czg.order.entity.OrderDetail; import com.czg.print.*; import lombok.Data; @@ -450,14 +452,18 @@ public interface PrinterImpl { }); } } - data.append(getFormatLabel(StrUtil.format(" 备注:{}", detail.getRemark()), signLabelInfo.s)).append(signLabelInfo.br); + if (StrUtil.isNotBlank(detail.getRemark()) && "null".equals(detail.getRemark())) { + data.append(getFormatLabel(StrUtil.format(" 备注:{}", detail.getRemark()), signLabelInfo.s)).append(signLabelInfo.br); + } } data.append(getDividingLine()) .append(signLabelInfo.br); } - data.append(getFormatLabel(StrUtil.format("备注: {}", orderPrintDTO.getRemark()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(getDividingLine()) - .append(signLabelInfo.br); + if (StrUtil.isNotBlank(orderPrintDTO.getRemark()) && "null".equals(orderPrintDTO.getRemark())) { + data.append(getFormatLabel(StrUtil.format("备注: {}", orderPrintDTO.getRemark()), signLabelInfo.s)).append(signLabelInfo.br); + data.append(getDividingLine()).append(signLabelInfo.br); + } + data.append(getFormatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); data.append(getFormatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); @@ -477,7 +483,7 @@ public interface PrinterImpl { StringBuilder builder = new StringBuilder(); builder.append(getFormatLabel(pickupNumber, signLabelInfo.centerBold)) .append(signLabelInfo.br); - builder.append(getFormatLabel(StrUtil.format("时间:{}", DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.f, signLabelInfo.center)) + builder.append(getFormatLabel(StrUtil.format("时间:{}", DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s, signLabelInfo.center)) .append(signLabelInfo.br); Integer isWaitCall = ObjectUtil.defaultIfNull(orderDetail.getIsWaitCall(), 0); if (isWaitCall == 1) { @@ -800,32 +806,28 @@ public interface PrinterImpl { /** * 构建叫号元数据 * - * @param shopName 店铺名称 - * @param tableName 表名 - * @param callNum 号码 - * @param preNum 前面还有几桌 - * @param codeUrl 二维码地址 - * @param shopNote 店铺备注 过号顺延{}桌 {}桌后需重新排号 谢谢理解! - * @param takeTime 取号时间 + * @param shopName 店铺名称 * @return 元数据 */ - default String buildCallTicketData(String shopName, String tableName, String callNum, String preNum, String codeUrl, String shopNote, LocalDateTime takeTime) { + default String buildCallTicketData(String shopName, CallTablePrintDTO printDTO) { PrintSignLabel signLabelInfo = getSignLabelInfo(); - return getFormatLabel(shopName, signLabelInfo.center, signLabelInfo.bold) + + CallTable callTable = printDTO.getCallTable(); + CallQueue callQueue = printDTO.getCallQueue(); + return getFormatLabel(shopName, signLabelInfo.center) + signLabelInfo.br + signLabelInfo.br + - getFormatLabel(StrUtil.format("{} {}", tableName, callNum), signLabelInfo.center, signLabelInfo.bold) + + getFormatLabel(StrUtil.format("{} {}", callTable.getName(), callQueue.getCallNum()), signLabelInfo.center, signLabelInfo.bold) + signLabelInfo.br + - getFormatLabel(StrUtil.format("前面有{}桌", preNum), signLabelInfo.center) + + getFormatLabel(StrUtil.format("前面有{}桌", printDTO.getPreNum()), signLabelInfo.center) + signLabelInfo.br + - getFormatLabel("怕过号,扫一扫", signLabelInfo.center, signLabelInfo.bold) + + getFormatLabel("怕过号,扫一扫", signLabelInfo.center, signLabelInfo.f) + signLabelInfo.br + - getFormatLabel(codeUrl, signLabelInfo.center, signLabelInfo.qr) + + getFormatLabel(printDTO.getCallUrl(), signLabelInfo.center, signLabelInfo.qr) + signLabelInfo.br + getDividingLine() + signLabelInfo.br + - getFormatLabel(shopNote, signLabelInfo.s) + - getFormatLabel(StrUtil.format("取号时间: {}", DateUtil.format(takeTime, "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s) + + getFormatLabel(StrUtil.format("过号顺延{}桌 {}桌后需重新排号 谢谢理解!", callTable.getPostponeNum(), callTable.getPostponeNum()), signLabelInfo.s) + + getFormatLabel(StrUtil.format("取号时间: {}", DateUtil.format(callQueue.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s) + signLabelInfo.br + - signLabelInfo.cut; + signLabelInfo.getOut(150) + signLabelInfo.cut; } diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java index 02d28c960..dfca6dde9 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/YxyPrinter.java @@ -15,7 +15,6 @@ import org.springframework.stereotype.Component; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import java.time.LocalDateTime; import java.util.*; /** @@ -130,8 +129,8 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { * 叫号单打印 */ @Override - protected void callNumPrint(PrintMachine machine, String callNum, String shopName, String tableName, String tableNote, String preNum, String codeUrl, LocalDateTime takeTime, String shopNote) { - String resp = buildCallTicketData(shopName, tableName, callNum, preNum, codeUrl, shopNote, takeTime); + protected void callNumPrint(PrintMachine machine, String shopName, CallTablePrintDTO printDTO) { + String resp = buildCallTicketData(shopName, printDTO); String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; if (1 == machine.getVolumeSwitch()) { voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一条新的排号记录\"}";