feat(print): 客户信息脱敏, 新增总计数量
This commit is contained in:
1 parent
1cc030d0db
commit
265f1647b0
1 file changed
+29
-4
+29
-4
@@ -33,6 +33,7 @@ public class OrderReceiptBuilder {
|
|||||||
|
|
||||||
sb.append("商品").append(pad("数量", 6)).append(pad("单价", 6)).append("<BR>");
|
sb.append("商品").append(pad("数量", 6)).append(pad("单价", 6)).append("<BR>");
|
||||||
sb.append(LINE);
|
sb.append(LINE);
|
||||||
|
int totalPieces = 0;
|
||||||
if (items != null) {
|
if (items != null) {
|
||||||
for (StoreOrderCartInfoDO item : items) {
|
for (StoreOrderCartInfoDO item : items) {
|
||||||
String name = nullToEmpty(item.getTitle());
|
String name = nullToEmpty(item.getTitle());
|
||||||
@@ -41,6 +42,7 @@ public class OrderReceiptBuilder {
|
|||||||
}
|
}
|
||||||
sb.append(name).append("<BR>");
|
sb.append(name).append("<BR>");
|
||||||
Integer number = item.getNumber() == null ? 0 : item.getNumber();
|
Integer number = item.getNumber() == null ? 0 : item.getNumber();
|
||||||
|
totalPieces += number;
|
||||||
BigDecimal price = item.getPrice() == null ? BigDecimal.ZERO : item.getPrice();
|
BigDecimal price = item.getPrice() == null ? BigDecimal.ZERO : item.getPrice();
|
||||||
sb.append(" x").append(number)
|
sb.append(" x").append(number)
|
||||||
.append(" ").append(price.toPlainString())
|
.append(" ").append(price.toPlainString())
|
||||||
@@ -48,6 +50,8 @@ public class OrderReceiptBuilder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb.append(LINE);
|
sb.append(LINE);
|
||||||
|
sb.append("总计:").append(totalPieces).append("件<BR>");
|
||||||
|
sb.append(LINE);
|
||||||
|
|
||||||
if (order.getCouponPrice() != null && order.getCouponPrice().compareTo(BigDecimal.ZERO) > 0) {
|
if (order.getCouponPrice() != null && order.getCouponPrice().compareTo(BigDecimal.ZERO) > 0) {
|
||||||
sb.append("优惠:-").append(order.getCouponPrice().toPlainString()).append("<BR>");
|
sb.append("优惠:-").append(order.getCouponPrice().toPlainString()).append("<BR>");
|
||||||
@@ -62,13 +66,13 @@ public class OrderReceiptBuilder {
|
|||||||
sb.append(LINE);
|
sb.append(LINE);
|
||||||
|
|
||||||
if (StrUtil.isNotBlank(order.getRealName())) {
|
if (StrUtil.isNotBlank(order.getRealName())) {
|
||||||
sb.append("姓名:").append(order.getRealName()).append("<BR>");
|
sb.append("顾客姓名:").append(maskName(order.getRealName())).append("<BR>");
|
||||||
}
|
}
|
||||||
if (StrUtil.isNotBlank(order.getUserPhone())) {
|
if (StrUtil.isNotBlank(order.getUserPhone())) {
|
||||||
sb.append("电话:").append(order.getUserPhone()).append("<BR>");
|
sb.append("顾客电话:").append(maskPhone(order.getUserPhone())).append("<BR>");
|
||||||
}
|
}
|
||||||
if (takeout && StrUtil.isNotBlank(order.getUserAddress())) {
|
if (takeout) {
|
||||||
sb.append("地址:").append(order.getUserAddress()).append("<BR>");
|
sb.append("[隐私保护]顾客地址已隐藏,您可登录配送APP查看").append("<BR>");
|
||||||
}
|
}
|
||||||
if (order.getPayTime() != null) {
|
if (order.getPayTime() != null) {
|
||||||
sb.append("支付时间:").append(order.getPayTime().format(PAY_TIME_FMT)).append("<BR>");
|
sb.append("支付时间:").append(order.getPayTime().format(PAY_TIME_FMT)).append("<BR>");
|
||||||
@@ -85,6 +89,27 @@ public class OrderReceiptBuilder {
|
|||||||
return s == null ? "" : s;
|
return s == null ? "" : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 只保留姓氏,其余用 * 代替,如 张三 -> 张* */
|
||||||
|
private static String maskName(String name) {
|
||||||
|
String trimmed = name.trim();
|
||||||
|
if (trimmed.isEmpty()) {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
if (trimmed.length() == 1) {
|
||||||
|
return trimmed;
|
||||||
|
}
|
||||||
|
return trimmed.charAt(0) + "*".repeat(trimmed.length() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 手机号保留前三位和后四位,如 13812345678 -> 138****5678 */
|
||||||
|
private static String maskPhone(String phone) {
|
||||||
|
String trimmed = phone.trim();
|
||||||
|
if (trimmed.length() < 7) {
|
||||||
|
return trimmed.charAt(0) + "****";
|
||||||
|
}
|
||||||
|
return trimmed.substring(0, 3) + "****" + trimmed.substring(trimmed.length() - 4);
|
||||||
|
}
|
||||||
|
|
||||||
private static String pad(String text, int width) {
|
private static String pad(String text, int width) {
|
||||||
if (text == null) {
|
if (text == null) {
|
||||||
text = "";
|
text = "";
|
||||||
|
|||||||
Reference in new issue
Block a user