qinxuyang преди 18 часа
родител
ревизия
74ca727394
променени са 1 файла, в които са добавени 5 реда и са изтрити 42 реда
  1. 5 42
      alien-store/src/main/java/shop/alien/store/service/impl/PrintTemplate.java

+ 5 - 42
alien-store/src/main/java/shop/alien/store/service/impl/PrintTemplate.java

@@ -104,17 +104,15 @@ public class PrintTemplate {
                 int blankLines = field.getIntValue("blankLines");
 
                 if ("item".equals(key)) {
-                    // 品项区:打印表头 + 列表
+                    // 品项区:打印表头 + 列表(不单独打印区块标题 titleName,避免多出「品项」一行)
                     JSONArray children = field.getJSONArray("children");
                     boolean showUnitPrice = childVisible(children, "unitPrice");
                     boolean showQuantity = childVisible(children, "quantity");
                     boolean showSubtotal = childVisible(children, "subtotal");
 
-                    // 表头
-                    sb.append(titleName).append("\n");
                     // 列标题(简洁处理)
                     List<String> headers = new ArrayList<>();
-                    headers.add("品");
+                    headers.add("品");
                     if (showUnitPrice) headers.add("单价");
                     if (showQuantity) headers.add("数量");
                     if (showSubtotal) headers.add("小计");
@@ -260,10 +258,7 @@ public class PrintTemplate {
                         boolean showUnitPrice = childVisible(children, "unitPrice");
                         boolean showQuantity = childVisible(children, "quantity");
                         boolean showSubtotal = childVisible(children, "subtotal");
-                        String secTitle = nvl(field.getString("titleName"));
-                        if (!secTitle.isEmpty()) {
-                            appendPrettyRawLine(secTitle, field, sb, lineWidth);
-                        }
+                        // 不单独打印 item 的 titleName(避免分割线后多一行「品项」);表头行仍含「品项」列名
                         sb.append(rowItemsHeader(lineWidth, showUnitPrice, showQuantity, showSubtotal));
                         @SuppressWarnings("unchecked")
                         List<Map<String, Object>> items = (List<Map<String, Object>>) context.getOrDefault("items", new ArrayList<>());
@@ -406,39 +401,7 @@ public class PrintTemplate {
                 core = titleName.isEmpty() ? truncateToWidth(value, lineWidth) : kvColon(titleName, value, lineWidth).trim();
             }
         }
-        // small:纯文本无法缩字号,行前缩进以区分(与 appendPrettyRawLine 一致)
-        if ("small".equalsIgnoreCase(fontSize)) {
-            core = "  " + core;
-        }
-        if (bold) {
-            core = "<B>" + core + "</B>";
-        }
-        sb.append(core).append("\n");
-    }
-
-    /** 不带「标题:值」结构的纯文本一行(如品项分组标题) */
-    private static void appendPrettyRawLine(String text, JSONObject style, StringBuilder sb, int lineWidth) {
-        JSONObject s = style == null ? new JSONObject() : style;
-        String align = nvl(s.getString("align"));
-        if (align.isEmpty()) {
-            align = "left";
-        }
-        boolean bold = s.getBooleanValue("bold");
-        String fontSize = nvl(s.getString("fontSize"));
-        if (fontSize.isEmpty()) {
-            fontSize = "normal";
-        }
-        if ("large".equalsIgnoreCase(fontSize)) {
-            sb.append("\n");
-        }
-        String core;
-        if ("center".equals(align)) {
-            core = center(text, lineWidth);
-        } else if ("right".equals(align)) {
-            core = alignRight(text, lineWidth);
-        } else {
-            core = truncateToWidth(text, lineWidth);
-        }
+        // small:纯文本无法缩字号,行前缩进以区分
         if ("small".equalsIgnoreCase(fontSize)) {
             core = "  " + core;
         }
@@ -569,7 +532,7 @@ public class PrintTemplate {
         int qtyW = 4;
         int subW = 7;
         int gapBetweenRightCols = 2; // 右侧各列之间的额外间距
-        int gapBeforeRightCols = 1;  // 左侧“品项”和第一个右列之间的间距
+        int gapBeforeRightCols = 1;  // 左侧「品项」列与第一个右列之间的间距
         int rightCols = (showUnitPrice ? 1 : 0) + (showQty ? 1 : 0) + (showSubtotal ? 1 : 0);
         int gapsTotal = (rightCols > 0 ? gapBeforeRightCols : 0) + Math.max(0, rightCols - 1) * gapBetweenRightCols;