From c29edce627dc82103612e2e29494c14230b1e039 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期一, 19 一月 2026 11:30:23 +0800
Subject: [PATCH] 检验任务提交:表格列宽度设置问题修复

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  155 ++++++++++++++++++++++++++++++++-------------------
 1 files changed, 98 insertions(+), 57 deletions(-)

diff --git a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
index c303e78..8f46956 100644
--- a/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -2544,26 +2544,27 @@
                     newTableRenderData.setRows(new ArrayList<>(firstTwoRows));
                     //璁剧疆鏍峰紡
                     TableStyle tableStyle = new TableStyle();
-                    for (int i = 1; i <= max; i++) {
-                        // 鏍规嵁鍑忓帇閭g粨鏋滀釜鏁颁慨鏀归暱搴�
-                        switch (i) {
-                            case 1:
-                                tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
-                                break;
-                            case 2:
-                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
-                                break;
-                            case 3:
-                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
-                                break;
-                            case 4:
-                                tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
-                                break;
-                            case 5:
-                                tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
-                                break;
-                        }
-                    }
+//                    for (int i = 1; i <= max; i++) {
+//                    }
+                    // 鏍规嵁妫�楠岀粨鏋滀釜鏁颁慨鏀归暱搴�
+                    tableStyle.setColWidths(calcTableColWidths(max));
+//                    switch (max) {
+//                        case 1:
+//                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
+//                            break;
+//                        case 2:
+//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
+//                            break;
+//                        case 3:
+//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
+//                            break;
+//                        case 4:
+//                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
+//                            break;
+//                        case 5:
+//                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
+//                            break;
+//                    }
                     tableStyle.setWidth("10000");
                     tableStyle.setAlign(TableRowAlign.CENTER);
                     BorderStyle borderStyle = new BorderStyle();
@@ -2586,42 +2587,43 @@
                 }
                 tableRenderData.getRows().add(row);
             }
-            if (!tableRenderData.getRows().isEmpty() && tableRenderData.getRows().size() != 3) {
+            TableStyle tableStyle = new TableStyle();
+            if (tableRenderData.getRows().size() != 3) {
                 //璁剧疆鏍峰紡
-                TableStyle tableStyle = new TableStyle();
-                for (int i = 1; i <= max; i++) {
-                    // 鏍规嵁鍑忓帇閭g粨鏋滀釜鏁颁慨鏀归暱搴�
-                    switch (i) {
-                        case 1:
-                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
-                            break;
-                        case 2:
-                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
-                            break;
-                        case 3:
-                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
-                            break;
-                        case 4:
-                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
-                            break;
-                        case 5:
-                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
-                            break;
-                    }
-                }
-                tableStyle.setWidth("10000");
-                tableStyle.setAlign(TableRowAlign.CENTER);
-                BorderStyle borderStyle = new BorderStyle();
-                borderStyle.setColor("000000");
-                borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
-                borderStyle.setSize(14);
-                tableStyle.setLeftBorder(borderStyle);
-                tableStyle.setTopBorder(borderStyle);
-                tableStyle.setRightBorder(borderStyle);
-                tableStyle.setBottomBorder(borderStyle);
-                tableRenderData.setTableStyle(tableStyle);
-                tables1.add(tableRenderData);
+//                for (int i = 1; i <= max; i++) {
+//                }
+                // 鏍规嵁妫�楠岀粨鏋滀釜鏁颁慨鏀归暱搴�
+                tableStyle.setColWidths(calcTableColWidths(max));
+//                switch (max) {
+//                    case 1:
+//                        tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
+//                        break;
+//                    case 2:
+//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
+//                        break;
+//                    case 3:
+//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
+//                        break;
+//                    case 4:
+//                        tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
+//                        break;
+//                    case 5:
+//                        tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
+//                        break;
+//                }
             }
+            tableStyle.setWidth("10000");
+            tableStyle.setAlign(TableRowAlign.CENTER);
+            BorderStyle borderStyle = new BorderStyle();
+            borderStyle.setColor("000000");
+            borderStyle.setType(XWPFTable.XWPFBorderType.THICK);
+            borderStyle.setSize(14);
+            tableStyle.setLeftBorder(borderStyle);
+            tableStyle.setTopBorder(borderStyle);
+            tableStyle.setRightBorder(borderStyle);
+            tableStyle.setBottomBorder(borderStyle);
+            tableRenderData.setTableStyle(tableStyle);
+            tables1.add(tableRenderData);
             tables1.forEach(table -> {
                 Map<String, Object> tableMap = new HashMap<>();
                 tableMap.put("table", table);
@@ -2830,6 +2832,45 @@
     }
 
     /**
+     * 璁$畻琛ㄦ牸鍒楀搴�
+     * @param max 鏈�澶ф楠屼釜鏁�
+     * @return
+     */
+    private static int[] calcTableColWidths(int max){
+        int[] colWidths = null;
+        switch (max) {
+            case 1:
+                colWidths = new int[]{650, 2000, 2000, 850, 2200, 2100, 1200};
+                break;
+            case 2:
+                colWidths = new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200};
+                break;
+            case 3:
+                colWidths = new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200};
+                break;
+            case 4:
+                colWidths = new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200};
+                break;
+            case 5:
+                colWidths = new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200};
+                break;
+        }
+        if(ObjectUtils.isNull(colWidths)){
+            List<Integer> defaultColWidths = new ArrayList<>(Arrays.asList(650, 1100, 1100, 850, 1350));
+            int totalWidth = 3000;//鎬诲搴�
+            int byOneWidth = totalWidth/max;//姣忎竴涓殑瀹藉害
+            int realWidth = 0;//瀹為檯瀹藉害
+            for (int i = 0; i < max; i++) {
+                realWidth+=byOneWidth;
+                defaultColWidths.add(byOneWidth);
+            }
+            defaultColWidths.add(1200+(totalWidth-realWidth));
+            return defaultColWidths.stream().mapToInt(Integer::intValue).toArray();
+        }
+        return colWidths;
+    }
+
+    /**
      * 璋冩暣楂樺害
      * @param row
      * @param rowHeight
@@ -2844,9 +2885,9 @@
         // 鑾峰彇妫�娴嬪唴瀹瑰垽鏂槸鍚﹁秴鍑�
         if (StringUtils.isNotBlank(dataText) && dataText.contains("@")) {
             double number = 1;
-            double chinaLength = 0;
-            double englishLength = 0;
-            double valueLength = 0;
+            double chinaLength = 14;
+            double englishLength = 28;
+            double valueLength = 6;
             // 鏍规嵁绾胯姱涓暟鍒ゆ柇璺濈
             switch (max) {
                 case 1:

--
Gitblit v1.9.3