diff --git a/cash-api/order-server/src/main/java/com/czg/mq/PrintMqListener.java b/cash-api/order-server/src/main/java/com/czg/mq/PrintMqListener.java index 9cbaf0972..bfa6f7dd1 100644 --- a/cash-api/order-server/src/main/java/com/czg/mq/PrintMqListener.java +++ b/cash-api/order-server/src/main/java/com/czg/mq/PrintMqListener.java @@ -59,7 +59,7 @@ public class PrintMqListener { } Boolean printOrder = jsonObject.getBoolean("printOrder"); redisService.runFunAndCheckKey(() -> { - printerHandler.handler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER); + printerHandler.orderHandler(orderId, printOrder != null && !printOrder ? PrinterHandler.PrintTypeEnum.ONE : PrinterHandler.PrintTypeEnum.ONE_AND_ORDER, null); return null; }, RedisCst.getLockKey("orderPrint", orderId)); }); @@ -71,7 +71,7 @@ public class PrintMqListener { @RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE}) public void handoverPrint(String id) { invokeFun(RabbitConstants.Queue.ORDER_HANDOVER_PRINT_QUEUE, "handoverPrint", "java.order", id, (data) -> - printerHandler.handler(data, PrinterHandler.PrintTypeEnum.HANDOVER)); + printerHandler.handoverHandler(data)); } /** @@ -80,6 +80,6 @@ public class PrintMqListener { @RabbitListener(queues = {"${spring.profiles.active}-" + RabbitConstants.Queue.CALL_TABLE_QUEUE}) public void callTablePrint(String id) { invokeFun(RabbitConstants.Queue.CALL_TABLE_QUEUE, "callTable", "java.order", id, (data) -> - printerHandler.handler(data, PrinterHandler.PrintTypeEnum.CALL)); + printerHandler.callHandler(data)); } } diff --git a/cash-common/cash-common-service/src/main/java/com/czg/order/dto/OrderInfoPrintDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/order/dto/OrderInfoPrintDTO.java index 51afbc2ce..171c10242 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/order/dto/OrderInfoPrintDTO.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/order/dto/OrderInfoPrintDTO.java @@ -20,7 +20,11 @@ public class OrderInfoPrintDTO implements Serializable { @NotNull(message = "id不为空") private Long id; /** - * 0结算单 1退款单 + * 0 菜品和结算单同时打印 + * 1 预结算单 + * 2 结算单 + * 3 退菜/退款 + * 4 交班 */ @NotNull(message = "打印类型不为空") private Integer type; diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java b/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java index ee1cff72f..27f8ba57f 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/print/FeiPrinter.java @@ -66,94 +66,60 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { } @Override - protected void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { - String remark = orderDetail.getRemark(); - String content = buildDishPrintData(false, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), - orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), remark, orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); - String o = sendPrintRequest(machine.getAddress(), content, null, "1"); - printMachineLogService.save(orderInfo.getId(), machine, "新订单", content, o); - } - - - @Override - protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { - String remark = orderDetail.getRemark(); - String content = buildDishPrintData(true, getPickupNum(orderInfo), orderInfo.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), - orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getReturnNum(), remark, orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); - String o = sendPrintRequest(machine.getAddress(), content, null, "1"); - printMachineLogService.save(orderInfo.getId(), machine, "退款单", content, o); + protected void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { + String buildDishPrintData = buildDishPrintData(false, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), + orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); + String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; + if (1 == machine.getVolumeSwitch()) { + voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; + } + String resp = sendPrintRequest(machine.getAddress(), buildDishPrintData, voiceJson, "1"); + printMachineLogService.save(orderInfo.getId(), machine, "新订单", buildDishPrintData, resp); } @Override - protected void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List detailList) { - ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); - String printerNum = "1"; - if (StrUtil.isNotBlank(machine.getPrintQty())) { - printerNum = machine.getPrintQty().split("\\^")[1]; - } - - PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()) - .setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) - .setOrderNo(orderInfo.getOrderNo()) - .setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")) - .setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString()) - .setOriginalAmount((orderInfo.getOriginAmount().add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()) - .setReturn(isReturn(orderInfo)) - .setBalance(balance) - .setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())) - .setIntegral("0") - .setOutNumber(orderInfo.getTakeCode()) - .setPrintTitle("结算单") - .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算 - .setDiscountAmount(calculateDiscountAmount(orderInfo)); - - if (orderInfo.getPayAmount() != null && orderInfo.getPayAmount().compareTo(BigDecimal.ZERO) == 0) { - // 设置支付金额为 订单原价-订单优惠金额 - printInfoDTO.setPayAmount((new BigDecimal(printInfoDTO.getOriginalAmount()).subtract(new BigDecimal(printInfoDTO.getDiscountAmount()))).toPlainString()); - } - String string = buildOrderPrintData(printInfoDTO, detailList); - String o = sendPrintRequest(machine.getAddress(), string, null, printerNum); - printMachineLogService.save(orderInfo.getId(), machine, "结算单", string, o); + protected void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { + String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), + orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); + String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; + String resp = sendPrintRequest(machine.getAddress(), buildDishPrintData, voiceJson, "1"); + printMachineLogService.save(orderInfo.getId(), machine, "厨房退菜", buildDishPrintData, resp); } @Override - protected void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List detailList) { - ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); - long count = orderInfoService.queryChain() - .eq(OrderInfo::getTradeDay, orderInfo.getTradeDay()) - .eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()) - .eq(OrderInfo::getShopId, orderInfo.getShopId()) - .le(OrderInfo::getCreateTime, orderInfo.getCreateTime()).count(); - String printerNum = "1"; - if (StrUtil.isNotBlank(machine.getPrintQty())) { - printerNum = machine.getPrintQty().split("\\^")[1]; - } + public PrintInfoDTO returnOrderPrint(String printTitle,String operator, String refundAmount, String refundReason, String refundType, + OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.returnOrderPrint(printTitle,operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList); + String data = buildRefundOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "退款单"); + return null; + } - PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()) - .setCount(count) - .setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) - .setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")).setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString()) - .setOriginalAmount((orderInfo.getOriginAmount().add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()).setReturn(isReturn(orderInfo)) - .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") - .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("结算单") - .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,如果为 null 则用原价减去实付计算 - .setDiscountAmount(calculateDiscountAmount(orderInfo)); - printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle()); - if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { - printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); - printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().toPlainString()); - } - if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) { - printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString()); - } + @Override + public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.guestOrderPrint(operator, orderInfo, machine, detailList); + String data = buildGuestOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "客看单"); + return null; + } - String string = buildOrderPrintData(printInfoDTO, detailList); - String resp = sendPrintRequest(machine.getAddress(), string, null, printerNum); - printMachineLogService.save(orderInfo.getId(), machine, "结算单", string, resp); + @Override + public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.preOrderPrint(operator, orderInfo, machine, detailList); + String data = buildOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "预结算单"); + return null; + } + + @Override + public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.orderPrint(operator, orderInfo, machine, detailList); + String data = buildOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "结算单"); + + return null; } @Override @@ -181,6 +147,19 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { return DigestUtils.sha1Hex(FeiPrinter.USER + FeiPrinter.UKEY + timeStamp); } + private void sendOrderPrint(String data, Long orderId, PrintMachine machine, String bizType) { + String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; + if (1 == machine.getVolumeSwitch()) { + voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; + } + String printerNum = "1"; + if (StrUtil.isNotBlank(machine.getPrintQty())) { + printerNum = machine.getPrintQty().split("\\^")[1]; + } + String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum); + printMachineLogService.save(orderId, machine, bizType, data, resp); + } + @Override public String sendPrintRequest(String address, String metaPrintData, String voiceData, String printerNum) { log.info("飞蛾打印机开始发送打印请求, 设备地址: {}, 元数据: {}", address, metaPrintData); 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 9af2c670a..dca6528b3 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 @@ -1,7 +1,7 @@ package com.czg.service.order.print; import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.util.ArrayUtil; +import cn.hutool.core.date.DateUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson2.JSONObject; @@ -37,6 +37,7 @@ import org.apache.dubbo.config.annotation.DubboReference; import org.springframework.web.client.RestTemplate; import java.math.BigDecimal; +import java.math.RoundingMode; import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -84,11 +85,17 @@ public abstract class PrinterHandler { @Getter public enum PrintTypeEnum { HANDOVER("交班", "handover"), - ORDER("订单", "order"), - ONE("菜品", "one"), - CALL("叫号", "call"), + ONE_AND_ORDER("菜品和结算单同时打印", "oneAndOrder"), - PRE_ORDER("预结算单", "preOrder"); + PRE_ORDER("预结算单", "preOrder"), + ORDER("订单结算单", "order"), + GUEST_ORDER("客看单", "guestOrder"), + + RETURN_FOOD("退菜", "returnFood"), + RETURN_ORDER("退单", "returnOrder"), + + ONE("菜品", "one"), + CALL("叫号", "call"); private final String name; private final String code; @@ -113,29 +120,40 @@ public abstract class PrinterHandler { @Accessors(chain = true) public static class PrintInfoDTO { private long count; - // 打印标题 退款单/结算单 + // 打印标题 结算单/客看单/预结算单 退菜单/退款单 private String printTitle; private String shopName; + //打印类型 收银-堂食 private String printType; + //台桌区域-台桌号 private String pickupNum; private String orderNo; + //结账时间 private String tradeDate; + //操作人名称 private String operator; private String payAmount; private String originalAmount; - private String balance; + //余额 +// private String balance; private String payType; - private String integral; private String remark; + //取餐码 private String outNumber; private String discountAmount; - private String discountRadio; - private String orderNum; + // private String discountRadio; +// private String orderNum; private String seatNum; private String seatAmount; private String packFee; // 是否退款单 private boolean isReturn; + //退款单用 + private String refundAmount; + //退款方式 现金退款/原路退回 + private String refundType; + //退款原因 + private String refundReason; } @@ -187,96 +205,109 @@ public abstract class PrinterHandler { } /** - * 处理打印 + * 处理订单打印 * * @param data 传递的数据 - * @param printTypeEnum order returnOrder preOrder one call handover + * @param printTypeEnum order preOrder one */ - public void handler(String data, PrintTypeEnum printTypeEnum) { - Long shopId; - String printMethod = ""; - String printType = ""; - Object obj; - OrderInfo orderInfo; + public void orderHandler(String data, PrintTypeEnum printTypeEnum, Integer placeNum) { + String printMethod; + OrderInfo orderInfo = orderInfoService.getById(data); + if (orderInfo == null) { + throw new RuntimeException("订单打印失败,订单不存在"); + } switch (printTypeEnum) { - case PrintTypeEnum.HANDOVER: - HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data)); - if (record == null) { - throw new RuntimeException("交班票打印失败,交班记录不存在"); - } - obj = record; - shopId = record.getShopId(); - printType = "handover"; - break; + case PrintTypeEnum.GUEST_ORDER: + case PrintTypeEnum.PRE_ORDER: case PrintTypeEnum.ORDER: - orderInfo = orderInfoService.getById(data); - if (orderInfo == null) { - throw new RuntimeException("订单打印失败,订单不存在"); - } - obj = orderInfo; - shopId = orderInfo.getShopId(); printMethod = "normal"; break; case PrintTypeEnum.ONE: - orderInfo = orderInfoService.getById(data); - if (orderInfo == null) { - throw new RuntimeException("订单打印失败,订单不存在"); - } - shopId = orderInfo.getShopId(); - obj = orderInfo; printMethod = "one"; break; - case PrintTypeEnum.PRE_ORDER: - orderInfo = orderInfoService.getById(data); - if (orderInfo == null) { - throw new RuntimeException("订单打印失败,订单不存在"); - } - shopId = orderInfo.getShopId(); - obj = orderInfo; - printMethod = "normal"; - break; case PrintTypeEnum.ONE_AND_ORDER: - orderInfo = orderInfoService.getById(data); - if (orderInfo == null) { - throw new RuntimeException("订单打印失败,订单不存在"); - } - shopId = orderInfo.getShopId(); - obj = orderInfo; printMethod = "all"; break; - - case PrintTypeEnum.CALL: - CallQueue queue = callQueueService.getById(data); - if (queue == null) { - throw new RuntimeException("叫号信息不存在: " + data); - } - shopId = queue.getShopId(); - obj = queue; - printType = "queue"; - break; default: throw new RuntimeException("未知打印类型"); - } - if (shopId == null) { - throw new RuntimeException("店铺不存在, id:" + shopId); - } - - Object finalObj = obj; - getPrintMachine(shopId, "cash", printMethod, printType).forEach(machine -> { - handleRequest(machine, finalObj, printTypeEnum); -// printPlaceTicket(isReturn, machine, orderInfo, shopInfo); + getPrintMachine(orderInfo.getShopId(), "cash", printMethod, "").forEach(machine -> { + handleRequest(machine, placeNum, orderInfo, printTypeEnum); }); } - private void handleRequest(PrintMachine machine, Object data, PrintTypeEnum printTypeEnum) { + /** + * 处理退菜退款订单打印 + * @param printTitle 退菜单 / 退款单 + * @param operator 操作人 + * @param refundAmount 退款金额 + * @param refundReason 退款原因 + * @param refundType 退款方式 + * @param orderInfo 订单信息 + * @param detailList 退菜/退款 列表 + */ + public void refundOrderHandler(String printTitle, String operator, String refundAmount, String refundReason, String refundType, + OrderInfo orderInfo, List detailList) { + getPrintMachine(orderInfo.getShopId(), "cash", "normal", "").forEach(machine -> { + refundHandleRequest(machine, printTitle, operator, refundAmount, refundReason, refundType, orderInfo, detailList); + }); + } + /** + * 叫号打印 + * + * @param data 传递的数据 + */ + public void callHandler(String data) { + + CallQueue queue = callQueueService.getById(data); + if (queue == null) { + throw new RuntimeException("叫号信息不存在: " + data); + } + Long shopId = queue.getShopId(); + if (shopId == null) { + throw new RuntimeException("店铺不存在, id:" + shopId); + } + getPrintMachine(shopId, "cash", "", "queue").forEach(machine -> handleRequest(machine, null, queue, PrintTypeEnum.CALL)); + } + + /** + * 交班打印 + * + * @param data 传递的数据 + */ + public void handoverHandler(String data) { + HandoverRecordDTO record = handoverRecordService.getHandoverRecordById(Long.parseLong(data)); + if (record == null) { + throw new RuntimeException("交班票打印失败,交班记录不存在"); + } + Long shopId = record.getShopId(); + if (shopId == null) { + throw new RuntimeException("店铺不存在, id:" + shopId); + } + getPrintMachine(shopId, "cash", "", "handover").forEach(machine -> handleRequest(machine, null, record, PrintTypeEnum.HANDOVER)); + } + + private void handleRequest(PrintMachine machine, Integer placeNum, Object data, PrintTypeEnum printTypeEnum) { if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) { log.info("打印机: {}, 传递信息: {}", machine.getName(), data); - print(machine, data, printTypeEnum); + print(machine, placeNum, data, printTypeEnum); } else if (nextPrinter != null) { log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this.printerBrand, nextPrinter.printerBrand); - nextPrinter.handleRequest(machine, data, printTypeEnum); + nextPrinter.handleRequest(machine, placeNum, data, printTypeEnum); + } else { + log.warn("未找到匹配打印机"); + } + } + + private void refundHandleRequest(PrintMachine machine, String printTitle, String operator, String refundAmount, String refundReason, String refundType, + OrderInfo orderInfo, List detailList) { + if (canHandleRequest(machine.getContentType(), machine.getConnectionType())) { + log.info("退款打印机: {}, 传递信息: {}", machine.getName(), orderInfo.getId()); + returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList); + } else if (nextPrinter != null) { + log.info("当前打印机无法处理: {},将请求传递给下一个打印机:{}...", this.printerBrand, nextPrinter.printerBrand); + nextPrinter.refundHandleRequest(machine, printTitle, operator, refundAmount, refundReason, refundType, orderInfo, detailList); } else { log.warn("未找到匹配打印机"); } @@ -329,7 +360,7 @@ public abstract class PrinterHandler { } - protected void print(PrintMachine machine, Object data, PrintTypeEnum printTypeEnum) { + protected void print(PrintMachine machine, Integer placeNum, Object data, PrintTypeEnum printTypeEnum) { switch (printTypeEnum) { case PrintTypeEnum.HANDOVER: log.info("准备开始打印交班"); @@ -339,12 +370,22 @@ public abstract class PrinterHandler { throw new RuntimeException("传递数据类型有误"); } break; + case PrintTypeEnum.GUEST_ORDER: + log.info("准备开始打印客看订单"); + if (data instanceof OrderInfo orderInfo) { + redisService.set("order:print:" + orderInfo.getId(), "", 180); + List orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId()).eq(OrderDetail::getPackNumber, placeNum)); + guestOrderPrint("", orderInfo, machine, orderDetailList); + } else { + throw new RuntimeException("传递数据类型有误"); + } + break; case PrintTypeEnum.ORDER: log.info("准备开始打印订单"); if (data instanceof OrderInfo orderInfo) { - redisService.set("order:print:" + orderInfo.getId(),"", 180); + redisService.set("order:print:" + orderInfo.getId(), "", 180); List orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); - onlyFrontDesk(machine, false, orderInfo, orderDetailList); + orderPrint(machine, orderInfo, orderDetailList); } else { throw new RuntimeException("传递数据类型有误"); } @@ -352,9 +393,9 @@ public abstract class PrinterHandler { case PrintTypeEnum.PRE_ORDER: log.info("准备开始打印预结算订单"); if (data instanceof OrderInfo orderInfo) { - redisService.set("order:print:" + orderInfo.getId(),"", 180); + redisService.set("order:print:" + orderInfo.getId(), "", 180); List orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); - onlyFrontDesk(machine, true, orderInfo, orderDetailList); + preOrderPrint(machine, orderInfo, orderDetailList); } else { throw new RuntimeException("传递数据类型有误"); } @@ -362,7 +403,7 @@ public abstract class PrinterHandler { case PrintTypeEnum.ONE: log.info("准备开始打印菜品单"); if (data instanceof OrderInfo orderInfo) { - redisService.set("order:print:" + orderInfo.getId(),"", 180); + redisService.set("order:print:" + orderInfo.getId(), "", 180); List orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); onlyKitchen(machine, orderInfo, orderDetailList); } else { @@ -380,11 +421,11 @@ public abstract class PrinterHandler { case PrintTypeEnum.ONE_AND_ORDER: log.info("准备开始打印菜品以及结算单"); if (data instanceof OrderInfo orderInfo) { - redisService.set("order:print:" + orderInfo.getId(),"", 180); + redisService.set("order:print:" + orderInfo.getId(), "", 180); List orderDetailList = orderDetailService.list(new QueryWrapper().eq(OrderDetail::getOrderId, orderInfo.getId())); switch (machine.getPrintMethod()) { case "all": - onlyFrontDesk(machine, false, orderInfo, orderDetailList); + orderPrint(machine, orderInfo, orderDetailList); onlyKitchen(machine, orderInfo, orderDetailList); break; case "one": @@ -393,7 +434,7 @@ public abstract class PrinterHandler { break; case "normal": log.info("打印机仅打印normal"); - onlyFrontDesk(machine, false, orderInfo, orderDetailList); + orderPrint(machine, orderInfo, orderDetailList); break; default: throw new RuntimeException("打印方法有误"); @@ -413,7 +454,6 @@ public abstract class PrinterHandler { // 判断订单是否是先付费或者已结算 if (!"after-pay".equals(orderInfo.getPayMode()) && (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus()))) { log.warn("此订单未支付, 订单信息: {}", orderInfo); -// return; } List categoryIds = JSONObject.parseObject(StrUtil.emptyToDefault(machine.getCategoryIds(), "[]"), List.class); @@ -429,7 +469,6 @@ public abstract class PrinterHandler { if (item.getNum().compareTo(BigDecimal.ZERO) <= 0 && item.getReturnNum().compareTo(BigDecimal.ZERO) <= 0) { return; } - log.info("开始打印菜品,商品名:{}", item.getProductName()); Integer isWaitCall = ObjectUtil.defaultIfNull(item.getIsWaitCall(), 0); if (isWaitCall == 1) { if (!item.getProductName().contains("【等叫】")) { @@ -455,11 +494,11 @@ public abstract class PrinterHandler { } if (item.getReturnNum().compareTo(BigDecimal.ZERO) > 0) { - returnDishesPrint(orderInfo, item, machine); + returnDishesPrint("操作人名称", orderInfo, item, machine); } if (item.getNum().compareTo(BigDecimal.ZERO) > 0) { - normalDishesPrint(orderInfo, item, machine); + normalDishesPrint("操作人名称", orderInfo, item, machine); } // 保存已打印信息 @@ -472,10 +511,60 @@ public abstract class PrinterHandler { } + /** + * 打印预结算单「前台」 + */ + private void preOrderPrint(PrintMachine machine, OrderInfo orderInfo, List orderDetail) { + // 判断订单是否是先付费或者已结算 + if (OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) { + log.warn("已取消, 订单信息: {}", orderInfo); + } + + if (orderDetail.isEmpty()) { + log.info("待打印列表为空"); + return; + } + List detailList = new ArrayList<>(); + orderDetail.forEach(it -> { + Integer isTemporary = ObjectUtil.defaultIfNull(it.getIsTemporary(), 0); + String remark = ""; + if (isTemporary == 0) { + ProdSku prodSku = prodSkuService.getById(it.getSkuId()); + if (ObjectUtil.isNotEmpty(prodSku) && ObjectUtil.isNotEmpty(prodSku.getSpecInfo())) { + remark = prodSku.getSpecInfo(); + } + } + Integer isWaitCall = ObjectUtil.defaultIfNull(it.getIsWaitCall(), 0); + if (isWaitCall == 1) { + it.setProductName("【等叫】%s".formatted(it.getProductName())); + } + if (isTemporary == 1) { + it.setProductName("【临】%s".formatted(it.getProductName())); + } + it.setPackAmount(it.getPackAmount() == null ? BigDecimal.ZERO : it.getPackAmount()); + boolean isGift = it.getIsGift() != null && it.getIsGift() == 1; + if (isGift) { + it.setProductName("【赠】%s".formatted(it.getProductName())); + } + BigDecimal unitPrice = it.getPrice(); + if (isGift) { + unitPrice = BigDecimal.ZERO; + } + PrintOrderDetailDTO detail = new PrintOrderDetailDTO(it.getProductName(), it.getNum().toString(), unitPrice.stripTrailingZeros().toPlainString(), remark, it.getProGroupInfo()); + detailList.add(detail); + + }); + + if (!detailList.isEmpty()) { + preOrderPrint("操作人名称", orderInfo, machine, orderDetail); + } + } + + /** * 仅打印结算单「前台」 */ - private void onlyFrontDesk(PrintMachine machine, boolean isPre, OrderInfo orderInfo, List tbOrderDetailList) { + private void orderPrint(PrintMachine machine, OrderInfo orderInfo, List tbOrderDetailList) { // 判断订单是否是先付费或者已结算 if (OrderStatusEnums.UNPAID.getCode().equals(orderInfo.getStatus()) || OrderStatusEnums.CANCELLED.getCode().equals(orderInfo.getStatus())) { log.warn("此订单未支付或已取消, 订单信息: {}", orderInfo); @@ -514,23 +603,9 @@ public abstract class PrinterHandler { } PrintOrderDetailDTO detail = new PrintOrderDetailDTO(it.getProductName(), it.getNum().toString(), unitPrice.stripTrailingZeros().toPlainString(), remark, it.getProGroupInfo()); detailList.add(detail); - }); - String balance = "0"; - - if ("deposit".equals(orderInfo.getPayType())) { - ShopUser user = shopUserService.getOne(new QueryWrapper().eq(ShopUser::getSourceShopId, orderInfo.getShopId()).eq(ShopUser::getUserId, orderInfo.getUserId())); - if (ObjectUtil.isNotEmpty(user) && ObjectUtil.isNotEmpty(user.getAmount())) { - balance = user.getAmount().toPlainString(); - } - } - if (!detailList.isEmpty()) { - if (isReturn(orderInfo)) { - returnOrderPrint(orderInfo, machine, balance, tbOrderDetailList); - } else { - normalOrderPrint(orderInfo, isPre, machine, balance, tbOrderDetailList); - } + orderPrint("操作人名称", orderInfo, machine, tbOrderDetailList); } } @@ -567,36 +642,136 @@ public abstract class PrinterHandler { return StrUtil.isBlank(orderInfo.getTableName()) ? orderInfo.getTakeCode() : orderInfo.getTableName(); } - /** - * 根据订单信息判断是否是退单 - * - * @param orderInfo 顶动感信息 - * @return 是否退款 - */ - protected static boolean isReturn(OrderInfo orderInfo) { - return ArrayUtil.contains(new String[]{"refunding", "part_refund", "refund"}, orderInfo.getStatus()); + + public PrintInfoDTO returnOrderPrint(String printTitle, String operator, String refundAmount, String refundReason, String refundType, + OrderInfo orderInfo, PrintMachine machine, List detailList) { + ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); + PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("收银-堂食") + .setPickupNum(orderInfo.getTableName()) + .setOrderNo(orderInfo.getOrderNo()) + .setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")) + .setOperator(operator) + .setReturn(true) + .setPrintTitle(printTitle); + printInfoDTO.setRefundAmount(refundAmount); + printInfoDTO.setRefundReason(refundReason); + printInfoDTO.setRefundType("cash".equals(refundType) ? "现金退款" : "原路退回"); + return printInfoDTO; } + public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "客看单"); + + BigDecimal originalAmount = BigDecimal.ZERO; + for (OrderDetail orderDetail : detailList) { + if (orderDetail.getIsGift() == 1) { + continue; + } else if (orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { + originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice())); + } else { + originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice())); + } + } + printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()); + printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee()) + .subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString()); + + if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); + printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString()); + } + if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString()); + } + return printInfoDTO; + } + + public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "预结算单"); + + BigDecimal originalAmount = BigDecimal.ZERO; + for (OrderDetail orderDetail : detailList) { + if (orderDetail.getIsGift() == 1) { + continue; + } else if (orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) { + originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice())); + } else { + originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice())); + } + } + printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()); + printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee()) + .subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString()); + + if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); + printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString()); + } + if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString()); + } + return printInfoDTO; + } + + public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = getPrintInfoDTO(operator, orderInfo, "结算单"); + + BigDecimal originalAmount = orderInfo.getOriginAmount() == null ? BigDecimal.ZERO : orderInfo.getOriginAmount(); + printInfoDTO.setOriginalAmount(originalAmount.toPlainString()); + printInfoDTO.setPayAmount(originalAmount.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString()); + if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); + printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString()); + } + if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) { + printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString()); + } + return printInfoDTO; + } + + private PrintInfoDTO getPrintInfoDTO(String operator, OrderInfo orderInfo, String printTitle) { + ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); + long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getTradeDay, orderInfo.getTradeDay()) + .eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()) + .eq(OrderInfo::getShopId, orderInfo.getShopId()) + .le(OrderInfo::getCreateTime, orderInfo.getCreateTime())); + PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()) + .setPrintTitle(printTitle).setPrintType("收银-堂食").setPickupNum(getPickupNum(orderInfo)) + .setOrderNo(orderInfo.getOrderNo()) + .setOperator(operator).setPayAmount(orderInfo.getPayAmount().toPlainString()).setReturn(false) + .setOutNumber(orderInfo.getTakeCode()).setCount(count).setRemark(orderInfo.getRemark()) + // 使用累计的总优惠金额,null 表示没有优惠 + .setDiscountAmount(orderInfo.getDiscountAllAmount() != null + ? orderInfo.getDiscountAllAmount().toPlainString() + : "0.00"); + if ("结算单".equals(printTitle)) { + if (StrUtil.isNotBlank(orderInfo.getPayType())) { + switch (orderInfo.getPayType()) { + case "main_scan" -> printInfoDTO.setPayType("二维码收款"); + case "back_scan" -> printInfoDTO.setPayType("扫码收款"); + case "wechat_mini" -> printInfoDTO.setPayType("微信小程序"); + case "alipay_mini" -> printInfoDTO.setPayType("支付宝小程序"); + case "vip_pay" -> printInfoDTO.setPayType("会员支付"); + case "cash_pay" -> printInfoDTO.setPayType("现金支付"); + case "credit_pay" -> printInfoDTO.setPayType("挂账支付"); + case "free_pay" -> printInfoDTO.setPayType("霸王餐支付"); + } + } + printInfoDTO.setTradeDate(DateUtil.format(orderInfo.getPaidTime(), "yyyy-MM-dd HH:mm:ss")); + } + return printInfoDTO; + } + /** * 菜品打印 */ - protected abstract void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); + protected abstract void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); /** * 菜品 退菜打印 */ - protected abstract void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); - - /** - * 退单打印 - */ - protected abstract void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List detailList); - - /** - * 订单打印 - */ - protected abstract void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List detailList); + protected abstract void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine); /** * 叫号打印 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 daca744e3..f0e1a6e4d 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 @@ -127,11 +127,11 @@ public interface PrinterImpl { // 剩余的行单独换行输出 for (int i = 1; i < lines.size(); i++) { - if (i+1 != lines.size()) { + if (i + 1 != lines.size()) { // sb.append(signLabelInfo.getRs(1)); sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s)); sb.append(signLabelInfo.br); - }else { + } else { sb.append(getFormatLabel(titleAddSpace(lines.get(i), b1), signLabelInfo.s)); } // sb.append(startSplitSign).append(lines.get(i)).append(endSplitSign).append("BR>"); @@ -158,7 +158,7 @@ public interface PrinterImpl { PrintSignLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder() .append(getFormatLabel(handoverRecord.getShopName(), signLabelInfo.center, signLabelInfo.f)).append(signLabelInfo.br) - .append(getFormatLabel("交班小票", signLabelInfo.l,signLabelInfo.center)).append(signLabelInfo.br) + .append(getFormatLabel("交班小票", signLabelInfo.l, signLabelInfo.center)).append(signLabelInfo.br) .append("交班时间: ").append(DateUtil.format(handoverRecord.getHandoverTime(), "yyyy-MM-dd HH:mm:ss")).append(signLabelInfo.br) .append("收银员: ").append(handoverRecord.getStaffName()).append(signLabelInfo.br) .append("当班总收入: ").append(handoverRecord.getHandAmount()).append(signLabelInfo.br) @@ -222,7 +222,7 @@ public interface PrinterImpl { } /** - * 构建订单打印元数据 + * 构建结算单 预结算单订单打印元数据 * * @param printInfoDTO 打印信息 * @param detailList 订单详情 @@ -231,51 +231,24 @@ public interface PrinterImpl { default String buildOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List detailList) { PrintSignLabel signLabelInfo = getSignLabelInfo(); StringBuilder data = new StringBuilder(); - data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.center, signLabelInfo.f)).append(signLabelInfo.br); -// data.append(StrUtil.format("{}
", printInfoDTO.getShopName())); -// data.append("
"); -// data.append(""); - data.append(getFormatLabel(StrUtil.format("{} #{}", printInfoDTO.getPrintTitle(), printInfoDTO.getCount()), signLabelInfo.l, signLabelInfo.center)) - .append(signLabelInfo.br); - data.append(getFormatLabel(StrUtil.format("桌号: {}", printInfoDTO.getPickupNum()), signLabelInfo.l, signLabelInfo.center)) - .append(signLabelInfo.br); + data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel(printInfoDTO.getPrintTitle(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br); + data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br); + if (StrUtil.isNotBlank(printInfoDTO.getTradeDate())) { + data.append(getFormatLabel(StrUtil.format("结账时间:{}", printInfoDTO.getTradeDate()), signLabelInfo.s)).append(signLabelInfo.br); + } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel("品名 单价 数量 ", signLabelInfo.s)).append(signLabelInfo.br); -// data.append(StrUtil.format("{}【{}】
", printInfoDTO.getPrintTitle(), printInfoDTO.getPickupNum())); - //if (Objects.nonNull(printInfoDTO.getOutNumber())) { - // data.append(StrUtil.format("{}",printInfoDTO.getOutNumber())); - //} -// data.append(""); -// data.append("
"); - data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("订单号:{}
", printInfoDTO.getOrderNo())); - data.append(getFormatLabel(StrUtil.format("交易时间:{}", printInfoDTO.getTradeDate()), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("交易时间:{}
", printInfoDTO.getTradeDate())); - data.append(getFormatLabel(StrUtil.format("收银员:{}", printInfoDTO.getOperator()), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("收银员:{}
", printInfoDTO.getOperator())); - data.append(signLabelInfo.br); - data.append(signLabelInfo.br); -// data.append(""); -// data.append("
"); - // 18个空格 12 - data.append(getFormatLabel("品名 数量 单价 ", signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append("品名 数量 小计
"); - data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append("--------------------------------
"); for (OrderDetail detail : detailList) { String number = detail.getNum().stripTrailingZeros().toPlainString(); - String row = getRow(detail.getProductName(), "", StrUtil.format("{}{}", number, detail.getReturnNum().compareTo(BigDecimal.ZERO) > 0 ? - "(退" + detail.getReturnNum().stripTrailingZeros().toPlainString() + ")" : ""), - toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString()), 21, 0, 5, 6); + String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString()) + , 21, 0, 5, 6); data.append(row); if (StrUtil.isNotBlank(detail.getSkuName())) { data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) .append(signLabelInfo.br); -// data.append("规格:").append(detail.getSkuName()).append("
"); } String proGroupInfo = detail.getProGroupInfo(); if (StrUtil.isBlank(proGroupInfo)) { @@ -295,79 +268,196 @@ public interface PrinterImpl { }); } } - if(StrUtil.isNotBlank(printInfoDTO.getSeatAmount())){ - String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(),""), + if (StrUtil.isNotBlank(printInfoDTO.getSeatAmount())) { + String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(), ""), toPlainStr(printInfoDTO.getSeatAmount()), 21, 0, 5, 6); data.append(row); } - if(StrUtil.isNotBlank(printInfoDTO.getPackFee())){ + if (StrUtil.isNotBlank(printInfoDTO.getPackFee())) { String row = getRow("打包费", "", "", toPlainStr(printInfoDTO.getPackFee()), 21, 0, 5, 6); data.append(row); } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("原价: {}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s)) + .append(signLabelInfo.br); if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) { - data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append("--------------------------------
"); - data.append(getFormatLabel(StrUtil.format("原价:{}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("原价:{}
", toPlainStr(printInfoDTO.getOriginalAmount()))); - data.append(getFormatLabel(StrUtil.format("优惠:-{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("折扣:-{}
", toPlainStr(printInfoDTO.getDiscountAmount()))); - } - data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append("--------------------------------
"); - String t = "¥" + printInfoDTO.getPayAmount(); - if (printInfoDTO.isReturn()) { - data.append(getFormatLabel(StrUtil.format("应退:{}", t), signLabelInfo.f)) - .append(signLabelInfo.br); -// data.append("应退").append(t).append("
"); - } else { - data.append(getFormatLabel(StrUtil.format("应收:{}", t), signLabelInfo.f)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("应收:{}
", t)); - } - data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append("--------------------------------
"); - if (ObjectUtil.isNotEmpty(printInfoDTO.getPayType()) && ObjectUtil.isNotNull(printInfoDTO.getPayType()) && "deposit".equals(printInfoDTO.getPayType())) { - data.append(getFormatLabel(StrUtil.format("储值:{}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("储值:{}
", toPlainStr(printInfoDTO.getOriginalAmount()))); - data.append(getFormatLabel(StrUtil.format("积分:{}", printInfoDTO.getIntegral()), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("积分:{}
", printInfoDTO.getIntegral())); - data.append(getFormatLabel(StrUtil.format("余额:{}", toPlainStr(printInfoDTO.getBalance())), signLabelInfo.s)) - .append(signLabelInfo.br); -// data.append(StrUtil.format("余额:{}
", toPlainStr(printInfoDTO.getBalance()))); - data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + data.append(getFormatLabel(StrUtil.format("优惠金额: -{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s)) .append(signLabelInfo.br); } - -// data.append("--------------------------------
"); if (StrUtil.isNotBlank(printInfoDTO.getRemark())) { data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold)) .append(signLabelInfo.br); -// data.append(StrUtil.format("备注:{}
", printInfoDTO.getRemark())); } -// if (Objects.nonNull(printInfoDTO.getOutNumber())) { -// data.append(getFormatLabel(printInfoDTO.getOutNumber(), signLabelInfo.center, signLabelInfo.qr)) -// .append(signLabelInfo.br); -//// data.append("".concat(printInfoDTO.getOutNumber()).concat("
")); -// } - data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)) - .append(signLabelInfo.br) + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("应付金额: {}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br); + if (StrUtil.isNotBlank(printInfoDTO.getPrintTitle())) { + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("已付金额: {}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("支付方式: {}", printInfoDTO.getPayType()), signLabelInfo.s)).append(signLabelInfo.br); + } + + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) .append(signLabelInfo.br); -// data.append("打印时间:").append(DateUtil.date().toDateStr()).append("
"); -// data.append(""); + data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); data.append(signLabelInfo.getOut(180)); data.append(signLabelInfo.cut); -// data.append(""); return data.toString(); } + /** + * 构建客看单订单打印元数据 + * + * @param printInfoDTO 打印信息 + * @param detailList 订单详情 + * @return 订单打印元数据 + */ + default String buildGuestOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List detailList) { + PrintSignLabel signLabelInfo = getSignLabelInfo(); + StringBuilder data = new StringBuilder(); + data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel("客看单", signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br); + data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel("品名 单价 数量 ", signLabelInfo.s)).append(signLabelInfo.br); + + for (OrderDetail detail : detailList) { + String number = detail.getNum().stripTrailingZeros().toPlainString(); + String row = getRow(detail.getProductName(), toPlainStr(detail.getUnitPrice().toPlainString()), number, toPlainStr(detail.getPayAmount().toPlainString()) + , 21, 0, 5, 6); + data.append(row); + if (StrUtil.isNotBlank(detail.getSkuName())) { + data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) + .append(signLabelInfo.br); + } + String proGroupInfo = detail.getProGroupInfo(); + if (StrUtil.isBlank(proGroupInfo)) { + continue; + } + if (!JSONUtil.isTypeJSONArray(proGroupInfo)) { + continue; + } + JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo); + for (Object subItem : subItems) { + JSONObject jsonObject = (JSONObject) subItem; + jsonObject.getJSONArray("goods").forEach(item -> { + String proName = ((JSONObject) item).getString("proName"); + String qty = ((JSONObject) item).getString("number"); + String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6); + data.append(subRow); + }); + } + } + if (StrUtil.isNotBlank(printInfoDTO.getSeatAmount())) { + String row = getRow("餐位费", "", StrUtil.format("{}{}", printInfoDTO.getSeatNum(), ""), + toPlainStr(printInfoDTO.getSeatAmount()), 21, 0, 5, 6); + data.append(row); + } + if (StrUtil.isNotBlank(printInfoDTO.getPackFee())) { + String row = getRow("打包费", "", "", + toPlainStr(printInfoDTO.getPackFee()), 21, 0, 5, 6); + data.append(row); + } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("原价: {}", toPlainStr(printInfoDTO.getOriginalAmount())), signLabelInfo.s)) + .append(signLabelInfo.br); + if (ObjectUtil.isNotNull(printInfoDTO.getDiscountAmount())) { + data.append(getFormatLabel(StrUtil.format("优惠金额: -{}", toPlainStr(printInfoDTO.getDiscountAmount())), signLabelInfo.s)) + .append(signLabelInfo.br); + } + if (StrUtil.isNotBlank(printInfoDTO.getRemark())) { + data.append(getFormatLabel(StrUtil.format("备注:{}", printInfoDTO.getRemark()), signLabelInfo.l, signLabelInfo.bold)) + .append(signLabelInfo.br); + } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("应付金额:{}", printInfoDTO.getPayAmount()), signLabelInfo.f, signLabelInfo.bold)).append(signLabelInfo.br); + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); + data.append(signLabelInfo.getOut(180)); + data.append(signLabelInfo.cut); + return data.toString(); + } + + /** + * 构建结算单 预结算单订单打印元数据 + * + * @param printInfoDTO 打印信息 + * @param detailList 订单详情 + * @return 订单打印元数据 + */ + default String buildRefundOrderPrintData(PrinterHandler.PrintInfoDTO printInfoDTO, List detailList) { + PrintSignLabel signLabelInfo = getSignLabelInfo(); + StringBuilder data = new StringBuilder(); + data.append(getFormatLabel(printInfoDTO.getShopName(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel(printInfoDTO.getPrintTitle(), signLabelInfo.s, signLabelInfo.center)).append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("桌台号: {}", printInfoDTO.getPickupNum()), signLabelInfo.f)).append(signLabelInfo.br); + data.append(getFormatLabel(getFormatLabel(StrUtil.format("{} {}人", printInfoDTO.getPrintType(), printInfoDTO.getSeatNum())), signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br); + data.append(getFormatLabel("退款明细 数量 小计 ", signLabelInfo.s)).append(signLabelInfo.br); + + for (OrderDetail detail : detailList) { + String number = detail.getNum().stripTrailingZeros().toPlainString(); + String amount = ""; + if ("退款单".equals(printInfoDTO.getPrintTitle())) { + amount = detail.getReturnAmount().stripTrailingZeros().toPlainString(); + } + String row = getRow(detail.getProductName(), "", number, amount + , 21, 0, 5, 6); + data.append(row); + if (StrUtil.isNotBlank(detail.getSkuName())) { + data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) + .append(signLabelInfo.br); + } + String proGroupInfo = detail.getProGroupInfo(); + if (StrUtil.isBlank(proGroupInfo)) { + continue; + } + if (!JSONUtil.isTypeJSONArray(proGroupInfo)) { + continue; + } + JSONArray subItems = com.alibaba.fastjson2.JSONArray.parseArray(proGroupInfo); + for (Object subItem : subItems) { + JSONObject jsonObject = (JSONObject) subItem; + jsonObject.getJSONArray("goods").forEach(item -> { + String proName = ((JSONObject) item).getString("proName"); + String qty = ((JSONObject) item).getString("number"); + String subRow = getRow(" - " + proName, "", qty, "0.00", 21, 0, 5, 6); + data.append(subRow); + }); + } + } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + .append(signLabelInfo.br); + if ("退款单".equals(printInfoDTO.getPrintTitle())) { + data.append(getFormatLabel(StrUtil.format("退款总计 {}", toPlainStr(printInfoDTO.getRefundAmount())), signLabelInfo.f, signLabelInfo.bold)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("退款方式:{}", toPlainStr(printInfoDTO.getRefundType())), signLabelInfo.s)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("退款原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold)) + .append(signLabelInfo.br); + } else { + data.append(getFormatLabel(StrUtil.format("退菜原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold)) + .append(signLabelInfo.br); + } + data.append(getFormatLabel("--------------------------------", signLabelInfo.s)) + .append(signLabelInfo.br); + data.append(getFormatLabel(StrUtil.format("操作员:{}", printInfoDTO.getOperator()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)); + data.append(getFormatLabel(StrUtil.format("订单号:{}", printInfoDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); + data.append(signLabelInfo.getOut(180)); + data.append(signLabelInfo.cut); + return data.toString(); + } + + /** * 构建菜品单打印数据 * 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 4fc2a41a1..4b5b18367 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 @@ -28,6 +28,7 @@ import java.util.*; /** * 博实结-云享印打印机 * 接口文档 + * * @author Administrator */ @Slf4j @@ -103,7 +104,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { } @Override - protected void normalDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { + protected void normalDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { String buildDishPrintData = buildDishPrintData(false, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; @@ -116,7 +117,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { } @Override - protected void returnDishesPrint(OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { + protected void returnDishesPrint(String operator, OrderInfo orderInfo, OrderDetail orderDetail, PrintMachine machine) { String buildDishPrintData = buildDishPrintData(true, getPickupNum(orderInfo), DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss"), orderDetail.getProductName(), orderDetail.getSkuName(), orderDetail.getReturnNum(), orderDetail.getRemark(), orderDetail.getProGroupInfo(), orderDetail.getId(), orderDetail.isUrgent()); String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; @@ -126,98 +127,36 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { } @Override - protected void returnOrderPrint(OrderInfo orderInfo, PrintMachine machine, String balance, List detailList) { - ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); - PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()).setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) - .setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")) - .setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString()) - .setOriginalAmount(orderInfo.getOriginAmount().toPlainString()).setReturn(isReturn(orderInfo)) - .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") - .setOutNumber(orderInfo.getTakeCode()).setPrintTitle("退款单") - .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,null 表示没有优惠 - .setDiscountAmount(orderInfo.getDiscountAllAmount() != null - ? orderInfo.getDiscountAllAmount().toPlainString() - : "0.00"); - + public PrintInfoDTO returnOrderPrint(String printTitle, String operator, String refundAmount, String refundReason, String refundType, + OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.returnOrderPrint(printTitle, operator, refundAmount, refundReason, refundType, orderInfo, machine, detailList); String data = buildOrderPrintData(printInfoDTO, detailList); - String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; - if (1 == machine.getVolumeSwitch()) { - voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; - } - String printerNum = "1"; - if (StrUtil.isNotBlank(machine.getPrintQty())) { - printerNum = machine.getPrintQty().split("\\^")[1]; - } - String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum); - printMachineLogService.save(orderInfo.getId(), machine, "退款单", data, resp); - + sendOrderPrint(data, orderInfo.getId(), machine, "退款单"); + return null; } @Override - protected void normalOrderPrint(OrderInfo orderInfo, boolean isPre, PrintMachine machine, String balance, List detailList) { - ShopInfo shopInfo = shopInfoService.getById(orderInfo.getShopId()); - long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getTradeDay, orderInfo.getTradeDay()) - .eq(OrderInfo::getStatus, OrderStatusEnums.DONE.getCode()) - .eq(OrderInfo::getShopId, orderInfo.getShopId()) - .le(OrderInfo::getCreateTime, orderInfo.getCreateTime())); - - PrintInfoDTO printInfoDTO = new PrintInfoDTO().setShopName(shopInfo.getShopName()) - .setPrintType("普通打印").setPickupNum(getPickupNum(orderInfo)) - .setOrderNo(orderInfo.getOrderNo()).setTradeDate(DateUtil.format(orderInfo.getCreateTime(), "yyyy-MM-dd HH:mm:ss")) - .setOperator("【POS-1】001").setPayAmount(orderInfo.getPayAmount().toPlainString()) - .setReturn(isReturn(orderInfo)) - .setBalance(balance).setPayType((ObjectUtil.isEmpty(orderInfo.getPayType()) || ObjectUtil.isNull(orderInfo.getPayType()) ? "" : orderInfo.getPayType())).setIntegral("0") - .setOutNumber(orderInfo.getTakeCode()) - .setPrintTitle(isPre ? "预结算单" : "结算单") - .setCount(count) - .setRemark(orderInfo.getRemark()) - // 使用累计的总优惠金额,null 表示没有优惠 - .setDiscountAmount(orderInfo.getDiscountAllAmount() != null - ? orderInfo.getDiscountAllAmount().toPlainString() - : "0.00"); - - BigDecimal originalAmount = orderInfo.getOriginAmount()==null?BigDecimal.ZERO:orderInfo.getOriginAmount(); - printInfoDTO.setOriginalAmount(originalAmount.toPlainString()); - if (isPre) { - originalAmount = BigDecimal.ZERO; - for (OrderDetail orderDetail : detailList) { - if(orderDetail.getIsGift()==1){ - continue; - }else if(orderDetail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0){ - originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getUnitPrice())); - }else { - originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice())); - } - } - printInfoDTO.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())).toPlainString()); - printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee()) - .subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString()); - }else { - printInfoDTO.setPayAmount(originalAmount.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString()); - } - printInfoDTO.setPrintTitle(printInfoDTO.getPrintTitle()); - if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) { - printInfoDTO.setSeatNum(orderInfo.getSeatNum().toString()); - printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString()); - } - if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) { - printInfoDTO.setPackFee(orderInfo.getPackFee().toPlainString()); - } + public PrintInfoDTO guestOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.guestOrderPrint(operator, orderInfo, machine, detailList); + String data = buildGuestOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "客看单"); + return null; + } + @Override + public PrintInfoDTO preOrderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.preOrderPrint(operator, orderInfo, machine, detailList); String data = buildOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "预结算单"); + return null; + } - String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; - if (1 == machine.getVolumeSwitch()) { - voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; - } - String printerNum = "1"; - if (StrUtil.isNotBlank(machine.getPrintQty())) { - printerNum = machine.getPrintQty().split("\\^")[1]; - } - String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum); - printMachineLogService.save(orderInfo.getId(), machine, "结算单", data, resp); - + @Override + public PrintInfoDTO orderPrint(String operator, OrderInfo orderInfo, PrintMachine machine, List detailList) { + PrintInfoDTO printInfoDTO = super.orderPrint(operator, orderInfo, machine, detailList); + String data = buildOrderPrintData(printInfoDTO, detailList); + sendOrderPrint(data, orderInfo.getId(), machine, "结算单"); + return null; } /** @@ -249,7 +188,6 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { */ private static String getToken(String timestamp, String requestId) { StringBuilder token = new StringBuilder(); -// StringBuilder encode = new StringBuilder(); SortedMap map = new TreeMap<>(); map.put("appId", APP_ID); map.put("timestamp", timestamp); @@ -259,15 +197,23 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { String key = next.getKey(); Object value = next.getValue(); token.append(key).append(value); -// encode.append(key).append("=").append(value).append("&"); } -// Map finalMap = new HashMap<>(); -// finalMap.put("ENCODE", encode.toString()); -// finalMap.put("TOKEN", SecureUtil.md5(token + APP_SECRET).toUpperCase()); -// return finalMap; return SecureUtil.md5(token + APP_SECRET).toUpperCase(); } + private void sendOrderPrint(String data, Long orderId, PrintMachine machine, String bizType) { + String voiceJson = "{\"bizType\":\"2\",\"content\":\"\"}"; + if (1 == machine.getVolumeSwitch()) { + voiceJson = "{\"bizType\":\"2\",\"content\":\"您有一笔新的订单,请及时处理\"}"; + } + String printerNum = "1"; + if (StrUtil.isNotBlank(machine.getPrintQty())) { + printerNum = machine.getPrintQty().split("\\^")[1]; + } + String resp = sendPrintRequest(machine.getAddress(), data, voiceJson, printerNum); + printMachineLogService.save(orderId, machine, bizType, data, resp); + } + /** * 检查打印状态 @@ -292,14 +238,4 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { log.info("云想印打印机:{},任务:{}状态:{}", devName, taskId, s); return s; } - - /** - * 计算优惠金额:优先使用 discountAllAmount,如果为 null 则返回 0 - */ - private String calculateDiscountAmount(OrderInfo orderInfo) { - return orderInfo.getDiscountAllAmount() != null - ? orderInfo.getDiscountAllAmount().toPlainString() - : "0.00"; - } - } diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoCustomServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoCustomServiceImpl.java index 7b16d1a2d..9ab6106ac 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoCustomServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoCustomServiceImpl.java @@ -314,7 +314,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { } orderDetails.forEach(item -> item.setOrderTime(DateUtil.date().toLocalDateTime())); AssertUtil.isListEmpty(orderDetails, "下单失败 购物车为空"); - processOrderDetails(orderDetails, param.getLimitRate(),param); + processOrderDetails(orderDetails, param.getLimitRate(), param); //生成订单 OrderInfo orderInfo = initOrderInfo(param, shopInfo, table); orderDetailService.createOrderDetails(orderInfo.getId(), orderDetails); @@ -324,6 +324,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { .eq(CashierCart::getTableCode, param.getTableCode()) ); if ("after-pay".equals(orderInfo.getPayMode())) { + printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.GUEST_ORDER, orderInfo.getPlaceNum()); //发送打票信息 后付费推送多次 需要处理 //orderId_0_0 订单ID_先付后付(1先付0后付)_订单状态 0未完成 1完成 //orderInfo.getId() + "_" + (!"after-pay".equals(orderInfo.getPayMode()) ? 1 : 0) + "_0" @@ -554,7 +555,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { if (param.getTargetOrderId() == null && StrUtil.isBlank(param.getTargetTableCode())) { throw new CzgException("转台失败,请选择目标台桌后转台"); } - if(param.getAllMerge()==null){ + if (param.getAllMerge() == null) { param.setAllMerge(0); } OrderInfo sourceOrder = orderInfoService.getById(param.getSourceOrderId()); @@ -569,13 +570,13 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { ShopTable shopTable = shopTableService.getOneByTableCode(sourceOrder.getShopId(), param.getTargetTableCode()); sourceOrder.setTableCode(shopTable.getTableCode()); sourceOrder.setTableName(shopTable.getName()); - if(param.getAllMerge()==1){ + if (param.getAllMerge() == 1) { OrderInfo upOrder = new OrderInfo(); upOrder.setTableCode(shopTable.getTableCode()); upOrder.setTableName(shopTable.getName()); orderInfoService.update(upOrder, new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId())); - targetOrder=sourceOrder; - }else { + targetOrder = sourceOrder; + } else { OrderInfoAddDTO addDTO = new OrderInfoAddDTO(); addDTO.setShopId(sourceOrder.getShopId()); addDTO.setStaffId(sourceOrder.getStaffId()); @@ -615,16 +616,16 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { if (count < 1) { throw new CzgException("转台失败,该订单无可转商品"); } - orderDetailService.update(orderDetailUp,new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId())); + orderDetailService.update(orderDetailUp, new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId())); } else { orderDetailService.update(orderDetailUp, new QueryWrapper().eq(OrderDetail::getOrderId, sourceOrder.getId()).in(OrderDetail::getId, param.getDetailIds())); } - if(param.getAllMerge()==1){ + if (param.getAllMerge() == 1) { orderInfoService.remove(new QueryWrapper().eq(OrderInfo::getId, sourceOrder.getId())); } } - if(param.getAllMerge()==1){ + if (param.getAllMerge() == 1) { shopTableService.updateStatus(sourceOrder.getShopId(), null, sourceTableCode, ShopTableStatusEnum.IDLE.getValue()); } shopTableService.updateStatus(sourceOrder.getShopId(), null, targetOrder.getTableCode(), ShopTableStatusEnum.UNSETTLED.getValue()); @@ -1028,7 +1029,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { * * @param orderDetails 订单详情 需要回填 */ - private void processOrderDetails(List orderDetails, LimitRateDTO limitRate,OrderInfoAddDTO param) throws CzgException { + private void processOrderDetails(List orderDetails, LimitRateDTO limitRate, OrderInfoAddDTO param) throws CzgException { BigDecimal packFee = BigDecimal.ZERO; for (OrderDetail detail : orderDetails) { if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) { @@ -1358,7 +1359,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { @Transactional public void expired(Long orderId) { OrderInfo orderInfo = orderInfoService.getById(orderId); - if(orderInfo == null){ + if (orderInfo == null) { log.info("订单取消失败,订单Id:{} 为空", orderId); return; } @@ -1581,14 +1582,14 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService { } switch (orderInfoPrintDTO.getType()) { - case 0: - printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ONE_AND_ORDER); + case 0://菜品和结算单同时打印 + printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ONE_AND_ORDER, null); break; - case 1: - printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.PRE_ORDER); + case 1://预结算单 + printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.PRE_ORDER, null); break; - case 2: - printerHandler.handler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ORDER); + case 2://结算单 + printerHandler.orderHandler(orderInfo.getId().toString(), PrinterHandler.PrintTypeEnum.ORDER, null); break; } return true; diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderPayServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderPayServiceImpl.java index d046dff2b..52d2da5ed 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderPayServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderPayServiceImpl.java @@ -498,6 +498,7 @@ public class OrderPayServiceImpl implements OrderPayService { orderInfo.setRefundRemark(orderInfo.getRefundRemark() + param.getRefundReason()); orderInfoService.updateById(orderInfo); //退款后续 + //退款返还库存 if (!returnProMap.isEmpty()) { rabbitPublisher.sendOrderRefundMsg(JSONObject.toJSONString(Map.of("orderId", orderInfo.getId(), "returnProMap", returnProMap)));