打印 细节
This commit is contained in:
@@ -662,6 +662,7 @@ public abstract class PrinterHandler {
|
|||||||
.setOperator(operator)
|
.setOperator(operator)
|
||||||
.setReturn(true)
|
.setReturn(true)
|
||||||
.setPrintTitle(printTitle);
|
.setPrintTitle(printTitle);
|
||||||
|
printInfoDTO.setSeatNum(orderInfo.getSeatNum() == null ? "" : orderInfo.getSeatNum().toString());
|
||||||
printInfoDTO.setPickupNum(getTableAreaAndName(orderInfo.getShopId(), orderInfo.getTableCode(), orderInfo.getTableName()));
|
printInfoDTO.setPickupNum(getTableAreaAndName(orderInfo.getShopId(), orderInfo.getTableCode(), orderInfo.getTableName()));
|
||||||
printInfoDTO.setRefundAmount(refundAmount);
|
printInfoDTO.setRefundAmount(refundAmount);
|
||||||
printInfoDTO.setRefundReason(refundReason);
|
printInfoDTO.setRefundReason(refundReason);
|
||||||
@@ -707,7 +708,8 @@ public abstract class PrinterHandler {
|
|||||||
originalAmount = originalAmount.add((orderDetail.getNum().subtract(orderDetail.getReturnNum()).subtract(orderDetail.getRefundNum())).multiply(orderDetail.getPrice()));
|
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.setOriginalAmount((originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee()))
|
||||||
|
.setScale(2, RoundingMode.HALF_UP).toPlainString());
|
||||||
printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())
|
printInfoDTO.setPayAmount(originalAmount.add(orderInfo.getSeatAmount()).add(orderInfo.getPackFee())
|
||||||
.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
|
.subtract(orderInfo.getDiscountAllAmount()).setScale(2, RoundingMode.HALF_UP).toPlainString());
|
||||||
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderInfo.getPackFee().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
@@ -754,11 +756,9 @@ public abstract class PrinterHandler {
|
|||||||
} else {
|
} else {
|
||||||
printInfoDTO.setOperator("");
|
printInfoDTO.setOperator("");
|
||||||
}
|
}
|
||||||
|
printInfoDTO.setSeatNum(orderInfo.getSeatNum() == null ? "" : orderInfo.getSeatNum().toString());
|
||||||
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
|
if (orderInfo.getSeatNum() != null && orderInfo.getSeatAmount().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
printInfoDTO.setSeatNum(orderInfo.getSeatNum() + "");
|
|
||||||
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
|
printInfoDTO.setSeatAmount(orderInfo.getSeatAmount().divide(BigDecimal.valueOf(orderInfo.getSeatNum()), 2, RoundingMode.DOWN).toPlainString());
|
||||||
} else {
|
|
||||||
printInfoDTO.setSeatNum("");
|
|
||||||
}
|
}
|
||||||
if ("结算单".equals(printTitle)) {
|
if ("结算单".equals(printTitle)) {
|
||||||
if (StrUtil.isNotBlank(orderInfo.getPayType())) {
|
if (StrUtil.isNotBlank(orderInfo.getPayType())) {
|
||||||
|
|||||||
@@ -266,7 +266,7 @@ public interface PrinterImpl {
|
|||||||
data.append(getFormatLabel(formatItemLine("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(formatItemLine("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
|
|
||||||
for (OrderDetail detail : detailList) {
|
for (OrderDetail detail : detailList) {
|
||||||
String number = detail.getNum().stripTrailingZeros().toPlainString();
|
String number = detail.getNum().subtract(detail.getReturnNum()).stripTrailingZeros().toPlainString();
|
||||||
String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString());
|
String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString());
|
||||||
data.append(getFormatLabel(formatItemLine(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(formatItemLine(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
|
|
||||||
@@ -310,12 +310,9 @@ public interface PrinterImpl {
|
|||||||
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
data.append(getFormatLabel(leftRightAlign("应付:", printInfoDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
data.append(getFormatLabel(leftRightAlign("应付:", printInfoDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(printInfoDTO.getPrintTitle())) {
|
if ("结算单".equals(printInfoDTO.getPrintTitle())) {
|
||||||
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel("--------------------------------", signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
data.append(getFormatLabel(leftRightAlign("已付:", printInfoDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
data.append(getFormatLabel(leftRightAlign("已付:", printInfoDTO.getPayAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
||||||
|
|
||||||
data.append(signLabelInfo.br);
|
|
||||||
data.append(signLabelInfo.br);
|
|
||||||
data.append(getFormatLabel(leftRightAlign("支付方式:", printInfoDTO.getPayType(), 32), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(leftRightAlign("支付方式:", printInfoDTO.getPayType(), 32), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +347,7 @@ public interface PrinterImpl {
|
|||||||
data.append(getFormatLabel(formatItemLine("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(formatItemLine("品名", "单价", "数量", 18, 9), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
|
|
||||||
for (OrderDetail detail : detailList) {
|
for (OrderDetail detail : detailList) {
|
||||||
String number = detail.getNum().stripTrailingZeros().toPlainString();
|
String number = detail.getNum().subtract(detail.getReturnNum()).stripTrailingZeros().toPlainString();
|
||||||
String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString());
|
String unitPrice = toPlainStr(detail.getUnitPrice().stripTrailingZeros().toPlainString());
|
||||||
data.append(getFormatLabel(formatItemLine(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(formatItemLine(detail.getProductName(), unitPrice, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
|
|
||||||
@@ -425,7 +422,7 @@ public interface PrinterImpl {
|
|||||||
if ("退款单".equals(printInfoDTO.getPrintTitle())) {
|
if ("退款单".equals(printInfoDTO.getPrintTitle())) {
|
||||||
amount = detail.getReturnAmount().stripTrailingZeros().toPlainString();
|
amount = detail.getReturnAmount().stripTrailingZeros().toPlainString();
|
||||||
}
|
}
|
||||||
data.append(getFormatLabel(formatItemLine(detail.getProductName(), amount, number, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
data.append(getFormatLabel(formatItemLine(detail.getProductName(), number, amount, 18, 7), signLabelInfo.s)).append(signLabelInfo.br);
|
||||||
if (StrUtil.isNotBlank(detail.getSkuName())) {
|
if (StrUtil.isNotBlank(detail.getSkuName())) {
|
||||||
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
|
data.append(getFormatLabel(StrUtil.format("规格:{}", detail.getSkuName()), signLabelInfo.s))
|
||||||
.append(signLabelInfo.br);
|
.append(signLabelInfo.br);
|
||||||
@@ -454,10 +451,10 @@ public interface PrinterImpl {
|
|||||||
data.append(getFormatLabel(leftRightAlign("退款总计:", printInfoDTO.getRefundAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
data.append(getFormatLabel(leftRightAlign("退款总计:", printInfoDTO.getRefundAmount(), 16), signLabelInfo.f)).append(signLabelInfo.br);
|
||||||
data.append(getFormatLabel(StrUtil.format("退款方式:{}", toPlainStr(printInfoDTO.getRefundType())), signLabelInfo.s))
|
data.append(getFormatLabel(StrUtil.format("退款方式:{}", toPlainStr(printInfoDTO.getRefundType())), signLabelInfo.s))
|
||||||
.append(signLabelInfo.br);
|
.append(signLabelInfo.br);
|
||||||
data.append(getFormatLabel(StrUtil.format("退款原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold))
|
data.append(getFormatLabel(StrUtil.format("退款原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.s))
|
||||||
.append(signLabelInfo.br);
|
.append(signLabelInfo.br);
|
||||||
} else {
|
} else {
|
||||||
data.append(getFormatLabel(StrUtil.format("退菜原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.l, signLabelInfo.bold))
|
data.append(getFormatLabel(StrUtil.format("退菜原因:{}", printInfoDTO.getRefundReason()), signLabelInfo.s))
|
||||||
.append(signLabelInfo.br);
|
.append(signLabelInfo.br);
|
||||||
}
|
}
|
||||||
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
|
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))
|
||||||
@@ -751,6 +748,9 @@ public interface PrinterImpl {
|
|||||||
key2 = Objects.toString(key2, "");
|
key2 = Objects.toString(key2, "");
|
||||||
key3 = Objects.toString(key3, "");
|
key3 = Objects.toString(key3, "");
|
||||||
|
|
||||||
|
// 👉 核心:key1 超长截取 + 加 ...
|
||||||
|
key1 = truncateWithEllipsis(key1, key1Width);
|
||||||
|
|
||||||
int w1 = getStringWidth(key1);
|
int w1 = getStringWidth(key1);
|
||||||
int w2 = getStringWidth(key2);
|
int w2 = getStringWidth(key2);
|
||||||
int w3 = getStringWidth(key3);
|
int w3 = getStringWidth(key3);
|
||||||
@@ -768,4 +768,29 @@ public interface PrinterImpl {
|
|||||||
+ " ".repeat(space3)
|
+ " ".repeat(space3)
|
||||||
+ key3;
|
+ key3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String truncateWithEllipsis(String text, int maxWidth) {
|
||||||
|
if (maxWidth <= 0) return "";
|
||||||
|
if (getStringWidth(text) <= maxWidth) {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
int currentWidth = 0;
|
||||||
|
int ellipsisWidth = getStringWidth("...");
|
||||||
|
|
||||||
|
for (char c : text.toCharArray()) {
|
||||||
|
int charWidth = (c > 127) ? 2 : 1;
|
||||||
|
|
||||||
|
// 剩下的宽度必须能放下 当前字符 + ...
|
||||||
|
if (currentWidth + charWidth + ellipsisWidth > maxWidth) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append(c);
|
||||||
|
currentWidth += charWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb + "..."; // 超长自动加...
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user