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 a4bdeca2f..67b84382c 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 @@ -19,6 +19,10 @@ public class OrderInfoPrintDTO implements Serializable { */ @NotNull(message = "id不为空") private Long id; + /** + * 店铺id + */ + private Long shopId; /** * 1 预结算单 * 2 结算单 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 d6106bb05..154a0ed54 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 @@ -41,7 +41,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { super("飞鹅"); } - private final PrintSignLabel printSignLabel = new PrintSignLabel() + private final PrintLabel printLabel = new PrintLabel() .setBr("
") .setCut("") .setOut("OUT") @@ -55,8 +55,8 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl { .setBold(new String[]{"", ""}); @Override - public PrintSignLabel getSignLabelInfo() { - return printSignLabel; + public PrintLabel getSignLabelInfo() { + return printLabel; } @Override 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 286bd8532..b2af99d03 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 @@ -30,7 +30,7 @@ import java.util.Objects; public interface PrinterImpl { @Data @Accessors(chain = true) - class PrintSignLabel { + class PrintLabel { /** *
:换行符 * :切刀指令/自动走纸(主动切纸,仅限切刀打印机使用才有效果/手动撕纸设备使用该指令时为自动走纸) @@ -61,7 +61,7 @@ public interface PrinterImpl { private String[] centerBold; private String[] bold; private String br; - //f 的行数字符为 30 + //s 的行数字符为 30 private String[] s; //f 的行数字符为 14 private String[] f; @@ -71,11 +71,26 @@ public interface PrinterImpl { private String out; private String rs; - public String getOut(int num) { - if (out != null) { - return StrUtil.format("<{}:{}>", out, num); - } - return ""; + + /** + * 走纸 + */ + public String out(int num) { + return StrUtil.format("<{}:{}>", out, num); + } + + public String out() { + return out(180); + } + + /** + * 设置可变字体大小 + * :设置可变字体大小(x:16,24,32,48,64,72,96都可支持,如x=96则为96*96字体) + * + * @param num 字号 + */ + public String[] cs(int num) { + return new String[]{StrUtil.format("", num), ""}; } } @@ -96,7 +111,7 @@ public interface PrinterImpl { * * @return 标签信息 */ - PrintSignLabel getSignLabelInfo(); + PrintLabel getSignLabelInfo(); /** * 获取分割线 @@ -129,7 +144,7 @@ public interface PrinterImpl { * 构建交班 打印元数据 */ default String buildHandoverData(HandoverRecordDTO handoverRecord) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder() .append(formatLabel(handoverRecord.getShopName(), signLabelInfo.center)).append(signLabelInfo.br) .append(formatLabel("交班小票", signLabelInfo.center)).append(signLabelInfo.br) @@ -161,19 +176,19 @@ public interface PrinterImpl { if (StrUtil.isNotBlank(handoverRecord.getCategoryData())) { builder.append(formatLabel("----------- 销售数据 -----------", signLabelInfo.s)).append(signLabelInfo.br) - .append(formatLabel(key3("商品分类", "数量", "总计", 14, 8), signLabelInfo.s)) + .append(formatLabel(key3("商品分类", "数量", "总计", 14, 8, 32), signLabelInfo.s)) .append(signLabelInfo.br); JSONArray.parseArray(handoverRecord.getCategoryData()).forEach(item -> { JSONObject info = (JSONObject) item; String categoryName = info.getString("categoryName"); Integer quantity = info.getInteger("quantity"); BigDecimal amount = info.getBigDecimal("amount"); - builder.append(formatLabel(key3(categoryName, quantity.toString(), bdToStr(amount), 14, 8), signLabelInfo.s)).append(signLabelInfo.br); + builder.append(formatLabel(key3(categoryName, quantity.toString(), bdToStr(amount), 14, 8, 32), signLabelInfo.s)).append(signLabelInfo.br); }); } builder.append(getDividingLine()).append(signLabelInfo.br) .append(formatLabel("打印时间: " + DateUtil.format(DateUtil.date(), "yyyy/MM/dd HH:mm:ss"), signLabelInfo.s)).append(signLabelInfo.br) - .append(signLabelInfo.getOut(180)) + .append(signLabelInfo.out()) .append(signLabelInfo.cut); return builder.toString(); } @@ -186,18 +201,18 @@ public interface PrinterImpl { * @return 订单打印元数据 */ default String buildOrderPrintData(OrderPrintDTO orderPrintDTO, List detailList) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabel = getSignLabelInfo(); StringBuilder data = new StringBuilder(); - data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); - data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); - data.append(formatLabel(orderPrintDTO.getPickupNum(), signLabelInfo.f)).append(signLabelInfo.br); + data.append(formatLabel(orderPrintDTO.getShopName(), signLabel.center)).append(signLabel.br); + data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabel.center)).append(signLabel.br); + data.append(formatLabel(orderPrintDTO.getPickupNum(), signLabel.f)).append(signLabel.br); data.append(formatLabel(formatLabel(LRAlign(orderPrintDTO.getPrintType(), StrUtil.isNotBlank(orderPrintDTO.getSeatNum()) ? orderPrintDTO.getSeatNum() + "人" : "", 32)) - , signLabelInfo.s)).append(signLabelInfo.br); + , signLabel.s)).append(signLabel.br); if (StrUtil.isNotBlank(orderPrintDTO.getTradeDate())) { - data.append(formatLabel(StrUtil.format("结账时间:{}", orderPrintDTO.getTradeDate()), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(StrUtil.format("结账时间:{}", orderPrintDTO.getTradeDate()), signLabel.s)).append(signLabel.br); } - data.append(getDividingLine()).append(signLabelInfo.br); - data.append(formatLabel(key3("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(getDividingLine()).append(signLabel.br); + data.append(formatLabel(key3("品名", "单价", "数量", 18, 9, 32), signLabel.s)).append(signLabel.br); for (OrderDetail detail : detailList) { BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum()); @@ -206,11 +221,12 @@ public interface PrinterImpl { } String number = subtract.stripTrailingZeros().toPlainString(); String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString()); - data.append(formatLabel(key3(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(detail.getProductName(), unitPrice, number, 18, 7, 32), signLabel.s)).append(signLabel.br); +// data.append(formatLabel(key3(detail.getProductName(), unitPrice, number, 13, 4,24), signLabel.cs(32))).append(signLabel.br); if (StrUtil.isNotBlank(detail.getSkuName())) { - data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) - .append(signLabelInfo.br); + data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabel.s)) + .append(signLabel.br); } String proGroupInfo = detail.getProGroupInfo(); if (StrUtil.isBlank(proGroupInfo)) { @@ -225,41 +241,41 @@ public interface PrinterImpl { jsonObject.getJSONArray("goods").forEach(item -> { String proName = ((JSONObject) item).getString("proName"); String qty = ((JSONObject) item).getString("number"); - data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9, 32), signLabel.s)).append(signLabel.br); }); } } if (StrUtil.isNotBlank(orderPrintDTO.getSeatAmount())) { - data.append(formatLabel(key3("餐位费", orderPrintDTO.getSeatAmount(), orderPrintDTO.getSeatNum(), 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("餐位费", orderPrintDTO.getSeatAmount(), orderPrintDTO.getSeatNum(), 18, 9, 32), signLabel.s)).append(signLabel.br); } if (StrUtil.isNotBlank(orderPrintDTO.getPackFee())) { - data.append(formatLabel(key3("打包费", toPlainStr(orderPrintDTO.getPackFee()), "", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("打包费", toPlainStr(orderPrintDTO.getPackFee()), "", 18, 9, 32), signLabel.s)).append(signLabel.br); } data.append(getDividingLine()) - .append(signLabelInfo.br); - data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br); + .append(signLabel.br); + data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabel.s)).append(signLabel.br); if (ObjectUtil.isNotNull(orderPrintDTO.getDiscountAmount())) { - data.append(formatLabel(LRAlign("优惠:", "-" + orderPrintDTO.getDiscountAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(LRAlign("优惠:", "-" + orderPrintDTO.getDiscountAmount(), 32), signLabel.s)).append(signLabel.br); } if (StrUtil.isNotBlank(orderPrintDTO.getRemark())) { - data.append(formatLabel(StrUtil.format("备注:{}", orderPrintDTO.getRemark()), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(StrUtil.format("备注:{}", orderPrintDTO.getRemark()), signLabel.s)).append(signLabel.br); } - data.append(getDividingLine()).append(signLabelInfo.br); - data.append(formatLabel(LRAlign("应付:", orderPrintDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br); + data.append(getDividingLine()).append(signLabel.br); + data.append(formatLabel(LRAlign("应付:", orderPrintDTO.getPayAmount(), 16), signLabel.f)).append(signLabel.br); if ("结算单".equals(orderPrintDTO.getPrintTitle())) { - data.append(getDividingLine()).append(signLabelInfo.br); - data.append(formatLabel(LRAlign("已付:", orderPrintDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br); - data.append(formatLabel(LRAlign("支付方式:", orderPrintDTO.getPayType(), 32), signLabelInfo.s)).append(signLabelInfo.br); + data.append(getDividingLine()).append(signLabel.br); + data.append(formatLabel(LRAlign("已付:", orderPrintDTO.getPayAmount(), 16), signLabel.f)).append(signLabel.br); + data.append(formatLabel(LRAlign("支付方式:", orderPrintDTO.getPayType(), 32), signLabel.s)).append(signLabel.br); } - data.append(getDividingLine()).append(signLabelInfo.br); - data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(signLabelInfo.getOut(180)); - data.append(signLabelInfo.cut); + data.append(getDividingLine()).append(signLabel.br); + data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabel.s)).append(signLabel.br); + data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabel.s)).append(signLabel.br); + data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabel.s)).append(signLabel.br); + data.append(signLabel.out()); + data.append(signLabel.cut); return data.toString(); } @@ -271,7 +287,7 @@ public interface PrinterImpl { * @return 订单打印元数据 */ default String buildGuestOrderPrintData(OrderPrintDTO orderPrintDTO, List detailList) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder data = new StringBuilder(); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel("客看单", signLabelInfo.center)).append(signLabelInfo.br); @@ -281,7 +297,7 @@ public interface PrinterImpl { data.append(formatLabel(formatLabel(LRAlign(orderPrintDTO.getPrintType(), StrUtil.isNotBlank(orderPrintDTO.getSeatNum()) ? orderPrintDTO.getSeatNum() + "人" : "", 32)) , signLabelInfo.s)).append(signLabelInfo.br); data.append(getDividingLine()).append(signLabelInfo.br); - data.append(formatLabel(key3("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("品名", "单价", "数量", 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); for (OrderDetail detail : detailList) { BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum()); @@ -290,7 +306,7 @@ public interface PrinterImpl { } String number = subtract.stripTrailingZeros().toPlainString(); String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString()); - data.append(formatLabel(key3(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(detail.getProductName(), unitPrice, number, 18, 7, 32), signLabelInfo.s)).append(signLabelInfo.br); if (StrUtil.isNotBlank(detail.getSkuName())) { data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) @@ -309,15 +325,15 @@ public interface PrinterImpl { jsonObject.getJSONArray("goods").forEach(item -> { String proName = ((JSONObject) item).getString("proName"); String qty = ((JSONObject) item).getString("number"); - data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); }); } } if (StrUtil.isNotBlank(orderPrintDTO.getSeatAmount())) { - data.append(formatLabel(key3("餐位费", orderPrintDTO.getSeatAmount(), orderPrintDTO.getSeatNum(), 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("餐位费", orderPrintDTO.getSeatAmount(), orderPrintDTO.getSeatNum(), 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); } if (StrUtil.isNotBlank(orderPrintDTO.getPackFee())) { - data.append(formatLabel(key3("打包费", toPlainStr(orderPrintDTO.getPackFee()), "", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("打包费", toPlainStr(orderPrintDTO.getPackFee()), "", 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); } data.append(getDividingLine()).append(signLabelInfo.br); data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br); @@ -331,7 +347,7 @@ public interface PrinterImpl { data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(signLabelInfo.getOut(180)); + data.append(signLabelInfo.out()); data.append(signLabelInfo.cut); return data.toString(); } @@ -344,7 +360,7 @@ public interface PrinterImpl { * @return 订单打印元数据 */ default String buildRefundOrderPrintData(OrderPrintDTO orderPrintDTO, List detailList) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder data = new StringBuilder(); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); @@ -353,7 +369,7 @@ public interface PrinterImpl { , signLabelInfo.s)).append(signLabelInfo.br); data.append(getDividingLine()).append(signLabelInfo.br); if (CollUtil.isNotEmpty(detailList)) { - data.append(formatLabel(key3("退款明细", "数量", "小计", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3("退款明细", "数量", "小计", 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); for (OrderDetail detail : detailList) { String number = detail.getNum().stripTrailingZeros().toPlainString(); @@ -361,7 +377,7 @@ public interface PrinterImpl { if ("退款单".equals(orderPrintDTO.getPrintTitle())) { amount = detail.getReturnAmount().stripTrailingZeros().toPlainString(); } - data.append(formatLabel(key3(detail.getProductName(), number, amount, 18, 7), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(detail.getProductName(), number, amount, 18, 7, 32), signLabelInfo.s)).append(signLabelInfo.br); if (StrUtil.isNotBlank(detail.getSkuName())) { data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) .append(signLabelInfo.br); @@ -379,7 +395,7 @@ public interface PrinterImpl { jsonObject.getJSONArray("goods").forEach(item -> { String proName = ((JSONObject) item).getString("proName"); String qty = ((JSONObject) item).getString("number"); - data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); }); } } @@ -401,7 +417,7 @@ public interface PrinterImpl { data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(signLabelInfo.getOut(180)); + data.append(signLabelInfo.out()); data.append(signLabelInfo.cut); return data.toString(); } @@ -413,7 +429,7 @@ public interface PrinterImpl { * @return 元数据 */ default String buildAllKitchenPrintData(OrderPrintDTO orderPrintDTO, List detailList) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder data = new StringBuilder(); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); @@ -438,7 +454,7 @@ public interface PrinterImpl { jsonObject.getJSONArray("goods").forEach(item -> { String proName = ((JSONObject) item).getString("proName"); String qty = ((JSONObject) item).getString("number"); - data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9), signLabelInfo.s)).append(signLabelInfo.br); + data.append(formatLabel(key3(" - " + proName, "", qty, 18, 9, 32), signLabelInfo.s)).append(signLabelInfo.br); }); } } @@ -457,7 +473,7 @@ public interface PrinterImpl { data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); - data.append(signLabelInfo.getOut(180)); + data.append(signLabelInfo.out()); data.append(signLabelInfo.cut); return data.toString(); } @@ -468,13 +484,18 @@ public interface PrinterImpl { * @param pickupNumber 取餐号 * @return 元数据 */ - default String buildOnlyKitchenPrintData(Integer isCode, String pickupNumber, OrderDetail orderDetail) { + default String buildOnlyKitchenPrintData(String pickupNumber, OrderDetail orderDetail) { PrintSignLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); builder.append(formatLabel(pickupNumber, signLabelInfo.centerBold)) .append(signLabelInfo.br); + builder.append(signLabelInfo.br); + builder.append(signLabelInfo.br); + builder.append(signLabelInfo.br); builder.append(formatLabel(StrUtil.format("时间:{}", DateUtil.format(orderDetail.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s, signLabelInfo.center)) .append(signLabelInfo.br); + builder.append(signLabelInfo.out(70)); + Integer isWaitCall = ObjectUtil.defaultIfNull(orderDetail.getIsWaitCall(), 0); if (isWaitCall == 1) { if (!orderDetail.getProductName().contains("【等叫】")) { @@ -532,7 +553,7 @@ public interface PrinterImpl { .append(signLabelInfo.br); } builder.append(signLabelInfo.br) - .append(signLabelInfo.getOut(150)) + .append(signLabelInfo.out()) .append(signLabelInfo.cut); return builder.toString(); } @@ -541,7 +562,7 @@ public interface PrinterImpl { * 出入库打印单 */ default String buildStockData(StockPrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); // 标题:入库 + 店铺名称 + 入库单 @@ -581,7 +602,7 @@ public interface PrinterImpl { builder.append(formatLabel(StrUtil.format("打印时间: {}", DateUtil.format(record.getPrintTime(), "yyyy/MM/dd HH:mm:ss")), signLabelInfo.s)).append(signLabelInfo.br); // 结尾空行 + 切纸(和充值单保持一致) - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -589,7 +610,7 @@ public interface PrinterImpl { * 经营日报打印单 */ default String buildDayReportData(DayReportPrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); // 标题:店铺名称 + 经营日报(居中,和充值/入库单风格统一) @@ -647,7 +668,7 @@ public interface PrinterImpl { builder.append(formatLabel(LRAlign(" 订单改价", bdToStr(disSta.getOrderDiscount()), 32), signLabelInfo.s)).append(signLabelInfo.br); // 结尾空行 + 切纸(和充值/入库单完全一致) - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -655,7 +676,7 @@ public interface PrinterImpl { * 日结单 */ default String buildDaySettleData(DaySettlePrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); @@ -705,11 +726,11 @@ public interface PrinterImpl { builder.append(formatLabel("敏感操作记录", signLabelInfo.bold)).append(signLabelInfo.br); for (DaySettlePrintDTO.OperationRecord operation : operationRecords) { builder.append(formatLabel( - key3(operation.getOperation(), "数量:" + operation.getCount(), "金额" + bdToStr(operation.getAmount()), 8, 14) + key3(operation.getOperation(), "数量:" + operation.getCount(), "金额" + bdToStr(operation.getAmount()), 8, 14, 32) , signLabelInfo.s)).append(signLabelInfo.br); } } - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -717,7 +738,7 @@ public interface PrinterImpl { * 商品报表打印单 */ default String buildProductReportData(ProductReportPrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); // 标题:店铺名称 + 商品报表(居中,和之前的报表风格统一) @@ -764,7 +785,7 @@ public interface PrinterImpl { } } // 结尾空行 + 切纸(和之前所有打印单完全一致) - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -773,7 +794,7 @@ public interface PrinterImpl { * 充值打印单 */ default String buildRechargeData(RechargePrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); // 标题:店铺名称 + 充值凭证 builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); @@ -806,7 +827,7 @@ public interface PrinterImpl { builder.append(formatLabel(StrUtil.format("充值编号: {}", record.getRechargeId()), signLabelInfo.s)).append(signLabelInfo.br); // 结尾空行 + 切纸 - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -814,7 +835,7 @@ public interface PrinterImpl { * 库存盘点打印单 */ default String buildStockCheckData(StockCheckPrintDTO record) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); StringBuilder builder = new StringBuilder(); // 标题:店铺名称 + 盘点单(居中,和之前所有打印单风格统一) @@ -853,7 +874,7 @@ public interface PrinterImpl { builder.append(formatLabel(StrUtil.format("打印时间: {}", DateUtil.format(LocalDateTime.now(), "yyyy/MM/dd HH:mm:ss")), signLabelInfo.s)).append(signLabelInfo.br); // 结尾空行 + 切纸(和之前所有打印单完全一致) - builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); + builder.append(signLabelInfo.out()).append(signLabelInfo.cut); return builder.toString(); } @@ -865,7 +886,7 @@ public interface PrinterImpl { * @return 元数据 */ default String buildCallTicketData(String shopName, CallTablePrintDTO printDTO) { - PrintSignLabel signLabelInfo = getSignLabelInfo(); + PrintLabel signLabelInfo = getSignLabelInfo(); CallTable callTable = printDTO.getCallTable(); CallQueue callQueue = printDTO.getCallQueue(); String str = formatLabel(shopName, signLabelInfo.center) + @@ -885,7 +906,7 @@ public interface PrinterImpl { } str = str + formatLabel(StrUtil.format("取号时间: {}", DateUtil.format(callQueue.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s) + signLabelInfo.br + - signLabelInfo.getOut(150) + signLabelInfo.cut; + signLabelInfo.out() + signLabelInfo.cut; return str; } @@ -937,11 +958,11 @@ public interface PrinterImpl { /** * 通用三列对齐方法(严格总长度) * 规则:key1=左对齐,key2=左对齐,key3=右对齐 - * 整行总长度 = totalWidth,绝不超界 + * 24的字体 最大宽度32 + * 32的字体 最大宽度24 */ default String key3(String key1, String key2, String key3, - int key1Width, - int key2Width) { + int key1Width, int key2Width, int allWidth) { // 1. 空值安全处理 key1 = Objects.toString(key1, ""); key2 = Objects.toString(key2, ""); @@ -959,7 +980,7 @@ public interface PrinterImpl { // 6. 最终按总显示宽度截断(100%不超界) int usedWidth = key1Width + key2Width + w3; - int space3 = Math.max(32 - usedWidth, 0); + int space3 = Math.max(allWidth - usedWidth, 0); // 5. 拼接:左1 + 空格 + 左2 + 空格 + (靠右空格) + 右3 return key1 + " ".repeat(space1) @@ -968,6 +989,13 @@ public interface PrinterImpl { + key3; } + /** + * 通用四列对齐方法(严格总长度) + * 规则:key1=左对齐,key2=左对齐,key3=左对齐,key4=右对齐 + * 24的字体 最大宽度32 + * 32的字体 最大宽度24 + * 目前写死了最大宽度32 + */ default String key4(String key1, String key2, String key3, String key4, int key1Width, int key2Width, int key3Width) { // 1. 空值安全处理 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 7924ec117..fb624c610 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 @@ -40,7 +40,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { super("云想印"); } - private final PrintSignLabel printSignLabel = new PrintSignLabel() + private final PrintLabel printLabel = new PrintLabel() .setBr("
") .setCut("") .setOut("OUT") @@ -217,8 +217,8 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl { } @Override - public PrintSignLabel getSignLabelInfo() { - return printSignLabel; + public PrintLabel getSignLabelInfo() { + return printLabel; } @Override