自定义字体大小

This commit is contained in:
2026-05-14 13:52:34 +08:00
parent 451c880d71
commit 732a4718f6
4 changed files with 102 additions and 83 deletions

View File

@@ -19,6 +19,10 @@ public class OrderInfoPrintDTO implements Serializable {
*/ */
@NotNull(message = "id不为空") @NotNull(message = "id不为空")
private Long id; private Long id;
/**
* 店铺id
*/
private Long shopId;
/** /**
* 1 预结算单 * 1 预结算单
* 2 结算单 * 2 结算单

View File

@@ -41,7 +41,7 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
super("飞鹅"); super("飞鹅");
} }
private final PrintSignLabel printSignLabel = new PrintSignLabel() private final PrintLabel printLabel = new PrintLabel()
.setBr("<BR>") .setBr("<BR>")
.setCut("<PCUT>") .setCut("<PCUT>")
.setOut("OUT") .setOut("OUT")
@@ -55,8 +55,8 @@ public class FeiPrinter extends PrinterHandler implements PrinterImpl {
.setBold(new String[]{"<BOLD>", "</BOLD>"}); .setBold(new String[]{"<BOLD>", "</BOLD>"});
@Override @Override
public PrintSignLabel getSignLabelInfo() { public PrintLabel getSignLabelInfo() {
return printSignLabel; return printLabel;
} }
@Override @Override

View File

@@ -30,7 +30,7 @@ import java.util.Objects;
public interface PrinterImpl { public interface PrinterImpl {
@Data @Data
@Accessors(chain = true) @Accessors(chain = true)
class PrintSignLabel { class PrintLabel {
/** /**
* <BR> :换行符 * <BR> :换行符
* <CUT> :切刀指令/自动走纸(主动切纸,仅限切刀打印机使用才有效果/手动撕纸设备使用该指令时为自动走纸) * <CUT> :切刀指令/自动走纸(主动切纸,仅限切刀打印机使用才有效果/手动撕纸设备使用该指令时为自动走纸)
@@ -61,7 +61,7 @@ public interface PrinterImpl {
private String[] centerBold; private String[] centerBold;
private String[] bold; private String[] bold;
private String br; private String br;
//f 的行数字符为 30 //s 的行数字符为 30
private String[] s; private String[] s;
//f 的行数字符为 14 //f 的行数字符为 14
private String[] f; private String[] f;
@@ -71,11 +71,18 @@ public interface PrinterImpl {
private String out; private String out;
private String rs; private String rs;
public String getOut(int num) { public String out() {
if (out != null) { return StrUtil.format("<{}:{}>", out, 180);
return StrUtil.format("<{}:{}>", out, num);
} }
return "";
/**
* 设置可变字体大小
* <CS:x>:设置可变字体大小</CS>x16,24,32,48,64,72,96都可支持如x=96则为96*96字体
*
* @param num 字号
*/
public String[] cs(int num) {
return new String[]{StrUtil.format("<CS:{}>", num), "</CS>"};
} }
} }
@@ -96,7 +103,7 @@ public interface PrinterImpl {
* *
* @return 标签信息 * @return 标签信息
*/ */
PrintSignLabel getSignLabelInfo(); PrintLabel getSignLabelInfo();
/** /**
* 获取分割线 * 获取分割线
@@ -129,7 +136,7 @@ public interface PrinterImpl {
* 构建交班 打印元数据 * 构建交班 打印元数据
*/ */
default String buildHandoverData(HandoverRecordDTO handoverRecord) { default String buildHandoverData(HandoverRecordDTO handoverRecord) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder() StringBuilder builder = new StringBuilder()
.append(formatLabel(handoverRecord.getShopName(), signLabelInfo.center)).append(signLabelInfo.br) .append(formatLabel(handoverRecord.getShopName(), signLabelInfo.center)).append(signLabelInfo.br)
.append(formatLabel("交班小票", signLabelInfo.center)).append(signLabelInfo.br) .append(formatLabel("交班小票", signLabelInfo.center)).append(signLabelInfo.br)
@@ -161,19 +168,19 @@ public interface PrinterImpl {
if (StrUtil.isNotBlank(handoverRecord.getCategoryData())) { if (StrUtil.isNotBlank(handoverRecord.getCategoryData())) {
builder.append(formatLabel("----------- 销售数据 -----------", signLabelInfo.s)).append(signLabelInfo.br) 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); .append(signLabelInfo.br);
JSONArray.parseArray(handoverRecord.getCategoryData()).forEach(item -> { JSONArray.parseArray(handoverRecord.getCategoryData()).forEach(item -> {
JSONObject info = (JSONObject) item; JSONObject info = (JSONObject) item;
String categoryName = info.getString("categoryName"); String categoryName = info.getString("categoryName");
Integer quantity = info.getInteger("quantity"); Integer quantity = info.getInteger("quantity");
BigDecimal amount = info.getBigDecimal("amount"); 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) builder.append(getDividingLine()).append(signLabelInfo.br)
.append(formatLabel("打印时间: " + DateUtil.format(DateUtil.date(), "yyyy/MM/dd HH:mm:ss"), signLabelInfo.s)).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); .append(signLabelInfo.cut);
return builder.toString(); return builder.toString();
} }
@@ -186,18 +193,18 @@ public interface PrinterImpl {
* @return 订单打印元数据 * @return 订单打印元数据
*/ */
default String buildOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) { default String buildOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabel = getSignLabelInfo();
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getShopName(), signLabel.center)).append(signLabel.br);
data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabel.center)).append(signLabel.br);
data.append(formatLabel(orderPrintDTO.getPickupNum(), signLabelInfo.f)).append(signLabelInfo.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)) 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())) { 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(getDividingLine()).append(signLabel.br);
data.append(formatLabel(key3("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(key3("品名", "单价", "数量", 18, 9,32), signLabel.s)).append(signLabel.br);
for (OrderDetail detail : detailList) { for (OrderDetail detail : detailList) {
BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum()); BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum());
@@ -206,11 +213,12 @@ public interface PrinterImpl {
} }
String number = subtract.stripTrailingZeros().toPlainString(); String number = subtract.stripTrailingZeros().toPlainString();
String unitPrice = toPlainStr(detail.getUnitPrice().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())) { if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabel.s))
.append(signLabelInfo.br); .append(signLabel.br);
} }
String proGroupInfo = detail.getProGroupInfo(); String proGroupInfo = detail.getProGroupInfo();
if (StrUtil.isBlank(proGroupInfo)) { if (StrUtil.isBlank(proGroupInfo)) {
@@ -225,41 +233,41 @@ public interface PrinterImpl {
jsonObject.getJSONArray("goods").forEach(item -> { jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName"); String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number"); 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())) { 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())) { 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()) data.append(getDividingLine())
.append(signLabelInfo.br); .append(signLabel.br);
data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabel.s)).append(signLabel.br);
if (ObjectUtil.isNotNull(orderPrintDTO.getDiscountAmount())) { 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())) { 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(getDividingLine()).append(signLabel.br);
data.append(formatLabel(LRAlign("应付:", orderPrintDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br); data.append(formatLabel(LRAlign("应付:", orderPrintDTO.getPayAmount(), 16), signLabel.f)).append(signLabel.br);
if ("结算单".equals(orderPrintDTO.getPrintTitle())) { if ("结算单".equals(orderPrintDTO.getPrintTitle())) {
data.append(getDividingLine()).append(signLabelInfo.br); data.append(getDividingLine()).append(signLabel.br);
data.append(formatLabel(LRAlign("已付:", orderPrintDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br); data.append(formatLabel(LRAlign("已付:", orderPrintDTO.getPayAmount(), 16), signLabel.f)).append(signLabel.br);
data.append(formatLabel(LRAlign("支付方式:", orderPrintDTO.getPayType(), 32), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(LRAlign("支付方式:", orderPrintDTO.getPayType(), 32), signLabel.s)).append(signLabel.br);
} }
data.append(getDividingLine()).append(signLabelInfo.br); data.append(getDividingLine()).append(signLabel.br);
data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabel.s)).append(signLabel.br);
data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("打印时间:{}", DateUtil.date().toString()), signLabel.s)).append(signLabel.br);
data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), signLabel.s)).append(signLabel.br);
data.append(signLabelInfo.getOut(180)); data.append(signLabel.out());
data.append(signLabelInfo.cut); data.append(signLabel.cut);
return data.toString(); return data.toString();
} }
@@ -271,7 +279,7 @@ public interface PrinterImpl {
* @return 订单打印元数据 * @return 订单打印元数据
*/ */
default String buildGuestOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) { default String buildGuestOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br);
data.append(formatLabel("客看单", signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel("客看单", signLabelInfo.center)).append(signLabelInfo.br);
@@ -281,7 +289,7 @@ public interface PrinterImpl {
data.append(formatLabel(formatLabel(LRAlign(orderPrintDTO.getPrintType(), StrUtil.isNotBlank(orderPrintDTO.getSeatNum()) ? orderPrintDTO.getSeatNum() + "" : "", 32)) data.append(formatLabel(formatLabel(LRAlign(orderPrintDTO.getPrintType(), StrUtil.isNotBlank(orderPrintDTO.getSeatNum()) ? orderPrintDTO.getSeatNum() + "" : "", 32))
, signLabelInfo.s)).append(signLabelInfo.br); , signLabelInfo.s)).append(signLabelInfo.br);
data.append(getDividingLine()).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) { for (OrderDetail detail : detailList) {
BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum()); BigDecimal subtract = detail.getNum().subtract(detail.getReturnNum());
@@ -290,7 +298,7 @@ public interface PrinterImpl {
} }
String number = subtract.stripTrailingZeros().toPlainString(); String number = subtract.stripTrailingZeros().toPlainString();
String unitPrice = toPlainStr(detail.getUnitPrice().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())) { if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
@@ -309,15 +317,15 @@ public interface PrinterImpl {
jsonObject.getJSONArray("goods").forEach(item -> { jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName"); String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number"); 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())) { 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())) { 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(getDividingLine()).append(signLabelInfo.br);
data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br); data.append(formatLabel(LRAlign("原价:", orderPrintDTO.getOriginalAmount(), 32), signLabelInfo.s)).append(signLabelInfo.br);
@@ -331,7 +339,7 @@ public interface PrinterImpl {
data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).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("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), 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); data.append(signLabelInfo.cut);
return data.toString(); return data.toString();
} }
@@ -344,7 +352,7 @@ public interface PrinterImpl {
* @return 订单打印元数据 * @return 订单打印元数据
*/ */
default String buildRefundOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) { default String buildRefundOrderPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br);
data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br);
@@ -353,7 +361,7 @@ public interface PrinterImpl {
, signLabelInfo.s)).append(signLabelInfo.br); , signLabelInfo.s)).append(signLabelInfo.br);
data.append(getDividingLine()).append(signLabelInfo.br); data.append(getDividingLine()).append(signLabelInfo.br);
if (CollUtil.isNotEmpty(detailList)) { 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) { for (OrderDetail detail : detailList) {
String number = detail.getNum().stripTrailingZeros().toPlainString(); String number = detail.getNum().stripTrailingZeros().toPlainString();
@@ -361,7 +369,7 @@ public interface PrinterImpl {
if ("退款单".equals(orderPrintDTO.getPrintTitle())) { if ("退款单".equals(orderPrintDTO.getPrintTitle())) {
amount = detail.getReturnAmount().stripTrailingZeros().toPlainString(); 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())) { if (StrUtil.isNotBlank(detail.getSkuName())) {
data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s)) data.append(formatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
.append(signLabelInfo.br); .append(signLabelInfo.br);
@@ -379,7 +387,7 @@ public interface PrinterImpl {
jsonObject.getJSONArray("goods").forEach(item -> { jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName"); String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number"); 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 +409,7 @@ public interface PrinterImpl {
data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).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("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), 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); data.append(signLabelInfo.cut);
return data.toString(); return data.toString();
} }
@@ -413,7 +421,7 @@ public interface PrinterImpl {
* @return 元数据 * @return 元数据
*/ */
default String buildAllKitchenPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) { default String buildAllKitchenPrintData(OrderPrintDTO orderPrintDTO, List<OrderDetail> detailList) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder data = new StringBuilder(); StringBuilder data = new StringBuilder();
data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getShopName(), signLabelInfo.center)).append(signLabelInfo.br);
data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br); data.append(formatLabel(orderPrintDTO.getPrintTitle(), signLabelInfo.center)).append(signLabelInfo.br);
@@ -438,7 +446,7 @@ public interface PrinterImpl {
jsonObject.getJSONArray("goods").forEach(item -> { jsonObject.getJSONArray("goods").forEach(item -> {
String proName = ((JSONObject) item).getString("proName"); String proName = ((JSONObject) item).getString("proName");
String qty = ((JSONObject) item).getString("number"); 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 +465,7 @@ public interface PrinterImpl {
data.append(formatLabel(StrUtil.format("操作员:{}", orderPrintDTO.getOperator()), signLabelInfo.s)).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("打印时间:{}", DateUtil.date().toString()), signLabelInfo.s)).append(signLabelInfo.br);
data.append(formatLabel(StrUtil.format("订单号:{}", orderPrintDTO.getOrderNo()), 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); data.append(signLabelInfo.cut);
return data.toString(); return data.toString();
} }
@@ -469,7 +477,7 @@ public interface PrinterImpl {
* @return 元数据 * @return 元数据
*/ */
default String buildOnlyKitchenPrintData(String pickupNumber, OrderDetail orderDetail) { default String buildOnlyKitchenPrintData(String pickupNumber, OrderDetail orderDetail) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(formatLabel(pickupNumber, signLabelInfo.centerBold)) builder.append(formatLabel(pickupNumber, signLabelInfo.centerBold))
.append(signLabelInfo.br); .append(signLabelInfo.br);
@@ -528,7 +536,7 @@ public interface PrinterImpl {
.append(signLabelInfo.br); .append(signLabelInfo.br);
} }
builder.append(signLabelInfo.br) builder.append(signLabelInfo.br)
.append(signLabelInfo.getOut(150)) .append(signLabelInfo.out())
.append(signLabelInfo.cut); .append(signLabelInfo.cut);
return builder.toString(); return builder.toString();
} }
@@ -537,7 +545,7 @@ public interface PrinterImpl {
* 出入库打印单 * 出入库打印单
*/ */
default String buildStockData(StockPrintDTO record) { default String buildStockData(StockPrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// 标题:入库 + 店铺名称 + 入库单 // 标题:入库 + 店铺名称 + 入库单
@@ -577,7 +585,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(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(); return builder.toString();
} }
@@ -585,7 +593,7 @@ public interface PrinterImpl {
* 经营日报打印单 * 经营日报打印单
*/ */
default String buildDayReportData(DayReportPrintDTO record) { default String buildDayReportData(DayReportPrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// 标题:店铺名称 + 经营日报(居中,和充值/入库单风格统一) // 标题:店铺名称 + 经营日报(居中,和充值/入库单风格统一)
@@ -643,7 +651,7 @@ public interface PrinterImpl {
builder.append(formatLabel(LRAlign(" 订单改价", bdToStr(disSta.getOrderDiscount()), 32), signLabelInfo.s)).append(signLabelInfo.br); 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(); return builder.toString();
} }
@@ -651,7 +659,7 @@ public interface PrinterImpl {
* 日结单 * 日结单
*/ */
default String buildDaySettleData(DaySettlePrintDTO record) { default String buildDaySettleData(DaySettlePrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br);
@@ -701,11 +709,11 @@ public interface PrinterImpl {
builder.append(formatLabel("敏感操作记录", signLabelInfo.bold)).append(signLabelInfo.br); builder.append(formatLabel("敏感操作记录", signLabelInfo.bold)).append(signLabelInfo.br);
for (DaySettlePrintDTO.OperationRecord operation : operationRecords) { for (DaySettlePrintDTO.OperationRecord operation : operationRecords) {
builder.append(formatLabel( 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); , signLabelInfo.s)).append(signLabelInfo.br);
} }
} }
builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); builder.append(signLabelInfo.out()).append(signLabelInfo.cut);
return builder.toString(); return builder.toString();
} }
@@ -713,7 +721,7 @@ public interface PrinterImpl {
* 商品报表打印单 * 商品报表打印单
*/ */
default String buildProductReportData(ProductReportPrintDTO record) { default String buildProductReportData(ProductReportPrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// 标题:店铺名称 + 商品报表(居中,和之前的报表风格统一) // 标题:店铺名称 + 商品报表(居中,和之前的报表风格统一)
@@ -760,7 +768,7 @@ public interface PrinterImpl {
} }
} }
// 结尾空行 + 切纸(和之前所有打印单完全一致) // 结尾空行 + 切纸(和之前所有打印单完全一致)
builder.append(signLabelInfo.getOut(150)).append(signLabelInfo.cut); builder.append(signLabelInfo.out()).append(signLabelInfo.cut);
return builder.toString(); return builder.toString();
} }
@@ -769,7 +777,7 @@ public interface PrinterImpl {
* 充值打印单 * 充值打印单
*/ */
default String buildRechargeData(RechargePrintDTO record) { default String buildRechargeData(RechargePrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// 标题:店铺名称 + 充值凭证 // 标题:店铺名称 + 充值凭证
builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br); builder.append(formatLabel(record.getShopName(), signLabelInfo.center)).append(signLabelInfo.br);
@@ -802,7 +810,7 @@ public interface PrinterImpl {
builder.append(formatLabel(StrUtil.format("充值编号: {}", record.getRechargeId()), signLabelInfo.s)).append(signLabelInfo.br); 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(); return builder.toString();
} }
@@ -810,7 +818,7 @@ public interface PrinterImpl {
* 库存盘点打印单 * 库存盘点打印单
*/ */
default String buildStockCheckData(StockCheckPrintDTO record) { default String buildStockCheckData(StockCheckPrintDTO record) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
// 标题:店铺名称 + 盘点单(居中,和之前所有打印单风格统一) // 标题:店铺名称 + 盘点单(居中,和之前所有打印单风格统一)
@@ -849,7 +857,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(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(); return builder.toString();
} }
@@ -861,7 +869,7 @@ public interface PrinterImpl {
* @return 元数据 * @return 元数据
*/ */
default String buildCallTicketData(String shopName, CallTablePrintDTO printDTO) { default String buildCallTicketData(String shopName, CallTablePrintDTO printDTO) {
PrintSignLabel signLabelInfo = getSignLabelInfo(); PrintLabel signLabelInfo = getSignLabelInfo();
CallTable callTable = printDTO.getCallTable(); CallTable callTable = printDTO.getCallTable();
CallQueue callQueue = printDTO.getCallQueue(); CallQueue callQueue = printDTO.getCallQueue();
String str = formatLabel(shopName, signLabelInfo.center) + String str = formatLabel(shopName, signLabelInfo.center) +
@@ -881,7 +889,7 @@ public interface PrinterImpl {
} }
str = str + formatLabel(StrUtil.format("取号时间: {}", DateUtil.format(callQueue.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s) + str = str + formatLabel(StrUtil.format("取号时间: {}", DateUtil.format(callQueue.getCreateTime(), "yyyy-MM-dd HH:mm:ss")), signLabelInfo.s) +
signLabelInfo.br + signLabelInfo.br +
signLabelInfo.getOut(150) + signLabelInfo.cut; signLabelInfo.out() + signLabelInfo.cut;
return str; return str;
} }
@@ -933,11 +941,11 @@ public interface PrinterImpl {
/** /**
* 通用三列对齐方法(严格总长度) * 通用三列对齐方法(严格总长度)
* 规则key1=左对齐key2=左对齐key3=右对齐 * 规则key1=左对齐key2=左对齐key3=右对齐
* 整行总长度 = totalWidth绝不超界 * 24的字体 最大宽度32
* 32的字体 最大宽度24
*/ */
default String key3(String key1, String key2, String key3, default String key3(String key1, String key2, String key3,
int key1Width, int key1Width, int key2Width, int allWidth) {
int key2Width) {
// 1. 空值安全处理 // 1. 空值安全处理
key1 = Objects.toString(key1, ""); key1 = Objects.toString(key1, "");
key2 = Objects.toString(key2, ""); key2 = Objects.toString(key2, "");
@@ -955,7 +963,7 @@ public interface PrinterImpl {
// 6. 最终按总显示宽度截断100%不超界) // 6. 最终按总显示宽度截断100%不超界)
int usedWidth = key1Width + key2Width + w3; int usedWidth = key1Width + key2Width + w3;
int space3 = Math.max(32 - usedWidth, 0); int space3 = Math.max(allWidth - usedWidth, 0);
// 5. 拼接左1 + 空格 + 左2 + 空格 + (靠右空格) + 右3 // 5. 拼接左1 + 空格 + 左2 + 空格 + (靠右空格) + 右3
return key1 + " ".repeat(space1) return key1 + " ".repeat(space1)
@@ -964,6 +972,13 @@ public interface PrinterImpl {
+ key3; + key3;
} }
/**
* 通用四列对齐方法(严格总长度)
* 规则key1=左对齐key2=左对齐key3=左对齐key4=右对齐
* 24的字体 最大宽度32
* 32的字体 最大宽度24
* 目前写死了最大宽度32
*/
default String key4(String key1, String key2, String key3, String key4, default String key4(String key1, String key2, String key3, String key4,
int key1Width, int key2Width, int key3Width) { int key1Width, int key2Width, int key3Width) {
// 1. 空值安全处理 // 1. 空值安全处理

View File

@@ -40,7 +40,7 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
super("云想印"); super("云想印");
} }
private final PrintSignLabel printSignLabel = new PrintSignLabel() private final PrintLabel printLabel = new PrintLabel()
.setBr("<BR>") .setBr("<BR>")
.setCut("<PCUT>") .setCut("<PCUT>")
.setOut("OUT") .setOut("OUT")
@@ -217,8 +217,8 @@ public class YxyPrinter extends PrinterHandler implements PrinterImpl {
} }
@Override @Override
public PrintSignLabel getSignLabelInfo() { public PrintLabel getSignLabelInfo() {
return printSignLabel; return printLabel;
} }
@Override @Override