From 7f75b111c64641a21b8f3784fb9b4cc34e681b2d Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期三, 15 四月 2026 15:24:07 +0800
Subject: [PATCH] 检验任务:修复多芯产品生成报告中线芯颜色与检验值不对应问题

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  163 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 102 insertions(+), 61 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..7cd309f 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
@@ -12,7 +12,6 @@
 import com.alibaba.fastjson.JSONObject;
 import com.aspose.words.License;
 import com.aspose.words.SaveFormat;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
@@ -2426,7 +2425,7 @@
         List<String> resultChList = new ArrayList<>();
         List<String> resultEnList = new ArrayList<>();
         // 鍒ゆ柇鏄惁鏄彧鏈変竴涓牱鍝�
-        boolean isOneSample = samples.size() == 1 ? true : false;
+        boolean isOneSample = samples.size() == 1;
         /*鍩虹鎶ュ憡(鏍规嵁缁樺埗鐨勫師濮嬭褰曟ā鐗堝舰鎴�)*/
         samples.forEach(a -> {
             models.add(a.getModel());
@@ -2544,26 +2543,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 +2586,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 +2831,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 +2884,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:
@@ -3712,7 +3752,6 @@
         // 妫�楠岄」鍒嗙被      妫�楠岄」  妫�楠屽瓙椤�
         Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapCn = new LinkedHashMap<>();
         Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapEn = new LinkedHashMap<>();
-
         // 涓棿妫�娴嬪�兼坊鍔�
         for (int i = 0; i < sampleList.size(); i++) {
             SampleProductExportDto sample = sampleList.get(i);
@@ -3793,7 +3832,9 @@
 
             // 鍒ゆ柇鏄惁鏈夌數缂嗘爣璇唌ap
             if (CollectionUtils.isNotEmpty(sample.getCableTagValueMap())) {
-                sample.setLastValueList(new ArrayList<>(sample.getCableTagValueMap().values()));
+                TreeMap<String, String> cableTagValues = new TreeMap<>(Comparator.comparingInt(cableTags::indexOf));
+                cableTagValues.putAll(sample.getCableTagValueMap());
+                sample.setLastValueList(new ArrayList<>(cableTagValues.values()));
             }
             if (CollectionUtils.isNotEmpty(sample.getCableTagResultMap())) {
                 sample.setInsResultList(new ArrayList<>(sample.getCableTagResultMap().values()));

--
Gitblit v1.9.3