From ede49ec7133b86d9db9dc1f0328418dcdaaef8aa Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期五, 28 二月 2025 15:16:55 +0800
Subject: [PATCH] 报告修改+实验结果

---
 inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java |  161 +++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 123 insertions(+), 38 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java b/inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java
index 5f4644d..af28ef7 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/utils/WordUtils.java
@@ -39,6 +39,8 @@
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 @Component
@@ -2591,37 +2593,52 @@
         Set<String> models = new HashSet<>();
 
         AtomicReference<Integer> productSize = new AtomicReference<>(0);
-        AtomicReference<Integer> productSize1 = new AtomicReference<>(0);
         AtomicReference<Integer> productSize2 = new AtomicReference<>(0);
         AtomicReference<Integer> productSize3 = new AtomicReference<>(0);
         String[] monthNames = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
         SampleProductDto s = insSample;
         models.add(s.getModel());
-        /*鏌ヨ鏍囧噯鏂规硶*/
-        standardMethod.addAll(insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+        List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                 .eq(InsProduct::getInsSampleId, insSample.getId())
-                .eq(InsProduct::getState, 1)).stream().map(InsProduct::getMethodS).distinct().collect(Collectors.toList()));
+                .eq(InsProduct::getState, 1));
+        /*鏌ヨ鏍囧噯鏂规硶*/
+        standardMethod.addAll(insProducts.stream().map(InsProduct::getMethodS).distinct().collect(Collectors.toList()));
         //鎬绘暟
-        Long productCount = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                .eq(InsProduct::getInsSampleId, s.getId()));
-        productSize.set(productSize.get() + Integer.parseInt(productCount + ""));
-        //涓嶅垽瀹�
-        Long productCount1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                .eq(InsProduct::getInsSampleId, s.getId())
-                .eq(InsProduct::getInsResult, 3));
-//        productSize1.set(productSize1.get() + Integer.parseInt(productCount1 + ""));
-        productSize1.set(productSize1.get() + Integer.parseInt(0 + ""));
+        long productCount = insProducts.size();
         //涓嶅悎鏍�
-        Long productCount2 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                .eq(InsProduct::getInsSampleId, s.getId())
-                .eq(InsProduct::getInsResult, 0));
+        long productCount2 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 0).count();
+        //鍚堟牸=(涓嶅垽瀹�+鍚堟牸)
+        long productCount1 = insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 3).count();
+        long productCount3 = productCount1 + insProducts.stream().filter(insProduct -> insProduct.getInsResult() == 1).count();
+        //鍒ゆ柇鏄惁鏈夎緪灏勯」鐩�
+        List<InsProduct> fusheProducts = insProducts.stream().filter(insProduct -> insProduct.getInspectionItem().equals("杈愬皠璇曢獙")).collect(Collectors.toList());
+        if (fusheProducts.size() > 0) {
+            for (InsProduct fusheProduct : fusheProducts) {
+                List<Long> vValues = new ArrayList<>();
+                String insValue = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery()
+                        .eq(InsProductResult::getInsProductId, fusheProduct.getId())).get(0).getInsValue();
+                Pattern pattern = Pattern.compile("\"v\":\"(\\d+)\"");
+                Matcher matcher = pattern.matcher(insValue);
+                while (matcher.find()) {
+                    vValues.add(Long.parseLong(matcher.group(1)));
+                }
+                //涓嶅悎鏍�
+                if (vValues.get(1)!=0){
+                    productCount2 = productCount2 - 1 + vValues.get(1);
+                }
+                //鍚堟牸
+                if (vValues.get(0)!=0) {
+                    if (fusheProduct.getInsResult()==1){
+                        productCount3 = productCount3 - 1 + vValues.get(0);
+                    }else  productCount3 = productCount3 + vValues.get(0);
+                }
+                //鎬绘暟=椤圭洰鎬绘暟-杈愬皠椤圭洰鏁伴噺+杈愬皠鍏蜂綋鐨�(鍚堟牸+涓嶅悎鏍�)鏁伴噺
+                productCount = productCount - 1 + vValues.stream().mapToLong(Long::longValue).sum();
+            }
+        }
+        productSize.set(productSize.get() + Integer.parseInt(productCount + ""));
         productSize2.set(productSize2.get() + Integer.parseInt(productCount2 + ""));
-        //鍚堟牸
-        Long productCount3 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                .eq(InsProduct::getInsSampleId, s.getId())
-                .eq(InsProduct::getInsResult, 1));
-//        productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + ""));
-        productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + productCount1 + ""));
+        productSize3.set(productSize3.get() + Integer.parseInt(productCount3 + ""));
         //灏嗛」鐩寜鐓х珯鐐硅繘琛屽垎绫�
         Map<String, List<InsProduct>> listMap = s.getInsProduct().stream().collect(Collectors.groupingBy(InsProduct::getSonLaboratory));
         // 鍒涘缓涓�涓� Map 灏嗙珯鐐瑰拰椤圭洰ID鐨勬槧灏勫叧绯�
@@ -2677,13 +2694,23 @@
         List<Map<String, Object>> tables4 = new ArrayList<>();
         Integer indexs = 1;
         //鍒ゆ柇鏄惁鏈夌數璺瘯楠�,鐜璇曢獙
-        List<String> strings = insReportDto1.getInsReportDto2s().stream().map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList());
+        List<String> strings = insReportDto1.getInsReportDto2s().stream()
+                .map(InsReportDto2::getLaboratory).distinct().collect(Collectors.toList());
         if (strings.contains("杩戝満") || strings.contains("杩滃満")) {
             Map<String, String> table = new HashMap<>();
             table.put("indexs", indexs + "");
             indexs += 1;
             table.put("term", "杈愬皠鏂瑰悜鍥惧弬鏁�");
-            table.put("result", "涓嶅垽瀹�");
+            List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                    .eq(InsProduct::getState, 1)
+                    .eq(InsProduct::getInsSampleId, insSample.getId())
+                    .eq(InsProduct::getInspectionItem, "杈愬皠璇曢獙")).stream()
+                    .map(InsProduct::getInsResult).distinct().collect(Collectors.toList());
+            if (list.contains(0)) {
+                table.put("result", "涓嶅悎鏍�");
+            } else {
+                table.put("result", "鍚堟牸");
+            }
             tables.add(table);
             /*杈愬皠鐨勮瘯楠岃〃*/
             List<InsOrderFile> insOrderFiles = insOrderFileMapper.selectList(Wrappers.<InsOrderFile>lambdaQuery()
@@ -2812,7 +2839,16 @@
                 Map<String, String> table2 = new HashMap<>();
                 table2.put("indexs", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
                 table2.put("term", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
-                table2.put("result", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
+                List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                        .eq(InsProduct::getState, 1)
+                        .eq(InsProduct::getInsSampleId,insSample.getId())
+                        .in(InsProduct::getSonLaboratory, strings)).stream()
+                        .map(InsProduct::getInsResult).distinct().collect(Collectors.toList());
+                if (list.contains(0)) {
+                    table2.put("result", "涓嶅悎鏍�");
+                } else {
+                    table2.put("result", "鍚堟牸");
+                }
                 tables.add(table2);
 
                 Map<String, String> table3 = new HashMap<>();
@@ -2845,7 +2881,7 @@
                     rowRenderData.setRowStyle(rowStyle);
                     List<CellRenderData> cells = new ArrayList<>();
                     //鍒楁暟
-                    for (int j = 0; j < 2; j++) {
+                    for (int j = 0; j < 3; j++) {
                         CellRenderData cellRenderData = new CellRenderData();
                         CellStyle cellStyle = new CellStyle();
                         cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER);
@@ -2871,9 +2907,17 @@
                                 paragraphRenderDataList.add(paragraphRenderData);
                                 cellRenderData.setParagraphs(paragraphRenderDataList);
                                 cells.add(cellRenderData);
-                            } else {
+                            } else if (j == 1) {
                                 //绗簩鍒�
                                 textRenderData.setText("璇曢獙瑕佹眰");
+                                renderData.add(textRenderData);
+                                paragraphRenderData.setContents(renderData);
+                                paragraphRenderDataList.add(paragraphRenderData);
+                                cellRenderData.setParagraphs(paragraphRenderDataList);
+                                cells.add(cellRenderData);
+                            } else {
+                                //绗笁鍒�
+                                textRenderData.setText("瀹為獙缁撴灉");
                                 renderData.add(textRenderData);
                                 paragraphRenderData.setContents(renderData);
                                 paragraphRenderDataList.add(paragraphRenderData);
@@ -2890,8 +2934,18 @@
                                 paragraphRenderDataList.add(paragraphRenderData);
                                 cellRenderData.setParagraphs(paragraphRenderDataList);
                                 cells.add(cellRenderData);
-                            } else {
+                            } else if (j == 1) {
                                 textRenderData.setText(products.get(i - 1).getTell());
+                                renderData.add(textRenderData);
+                                paragraphRenderData.setContents(renderData);
+                                paragraphRenderDataList.add(paragraphRenderData);
+                                cellRenderData.setParagraphs(paragraphRenderDataList);
+                                cells.add(cellRenderData);
+                            } else {
+                                //绗笁鍒�
+                                //鑾峰彇妫�楠岄」鐩拰缁撹
+                                InsProduct insProduct = products.get(i - 1);
+                                textRenderData.setText("缁忚繃" + insProduct.getInspectionItemSubclass() + "涔嬪悗锛屾牱鍝�" + (insProduct.getInsResult() == 0 ? "涓嶅悎鏍�" : "鏃犲紓甯�") + "銆�");
                                 renderData.add(textRenderData);
                                 paragraphRenderData.setContents(renderData);
                                 paragraphRenderDataList.add(paragraphRenderData);
@@ -2928,7 +2982,8 @@
                 Map<String, Object> table4 = new HashMap<>();
                 table4.put("table4", tableRenderData);
                 tables4.add(table4);
-            } else {
+            }
+            else {
                 Map<String, String> table = new HashMap<>();
                 table.put("indexs", indexs + "");
                 table.put("term", "鐢佃矾鍙傛暟");
@@ -2953,7 +3008,8 @@
                     }
                 }
             }
-        } else {
+        }
+        else {
             //濡傛灉鍙湁鐜璇曢獙娌℃湁鐢佃矾璇曢獙
             strings.remove("杩戝満");
             strings.remove("杩滃満");
@@ -2961,7 +3017,16 @@
                 Map<String, String> table2 = new HashMap<>();
                 table2.put("indexs", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
                 table2.put("term", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
-                table2.put("result", "鐜璇曢獙:" + String.join("銆�", strings) + "鈭�1");
+                List<Integer> list = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                        .eq(InsProduct::getState, 1)
+                        .eq(InsProduct::getInsSampleId,insSample.getId())
+                        .in(InsProduct::getSonLaboratory, strings)).stream()
+                        .map(InsProduct::getInsResult).distinct().collect(Collectors.toList());
+                if (list.contains(0)) {
+                    table2.put("result", "涓嶅悎鏍�");
+                } else {
+                    table2.put("result", "鍚堟牸");
+                }
                 tables.add(table2);
 
                 /*鍒涘缓鐜璇曢獙鏉′欢琛�2*(椤圭洰鏁�+1)*/
@@ -2983,7 +3048,7 @@
                     rowRenderData.setRowStyle(rowStyle);
                     List<CellRenderData> cells = new ArrayList<>();
                     //鍒楁暟
-                    for (int j = 0; j < 2; j++) {
+                    for (int j = 0; j < 3; j++) {
                         CellRenderData cellRenderData = new CellRenderData();
                         CellStyle cellStyle = new CellStyle();
                         cellStyle.setVertAlign(XWPFTableCell.XWPFVertAlign.CENTER);
@@ -3009,9 +3074,17 @@
                                 paragraphRenderDataList.add(paragraphRenderData);
                                 cellRenderData.setParagraphs(paragraphRenderDataList);
                                 cells.add(cellRenderData);
-                            } else {
+                            } else if (j == 1) {
                                 //绗簩鍒�
                                 textRenderData.setText("璇曢獙瑕佹眰");
+                                renderData.add(textRenderData);
+                                paragraphRenderData.setContents(renderData);
+                                paragraphRenderDataList.add(paragraphRenderData);
+                                cellRenderData.setParagraphs(paragraphRenderDataList);
+                                cells.add(cellRenderData);
+                            } else {
+                                //绗笁鍒�
+                                textRenderData.setText("瀹為獙缁撴灉");
                                 renderData.add(textRenderData);
                                 paragraphRenderData.setContents(renderData);
                                 paragraphRenderDataList.add(paragraphRenderData);
@@ -3028,8 +3101,23 @@
                                 paragraphRenderDataList.add(paragraphRenderData);
                                 cellRenderData.setParagraphs(paragraphRenderDataList);
                                 cells.add(cellRenderData);
-                            } else {
+                            } else if (j == 1) {
+                                //绗簩鍒�
                                 textRenderData.setText(products.get(i - 1).getTell());
+                                renderData.add(textRenderData);
+                                paragraphRenderData.setContents(renderData);
+                                paragraphRenderDataList.add(paragraphRenderData);
+                                cellRenderData.setParagraphs(paragraphRenderDataList);
+                                cells.add(cellRenderData);
+                            } else {
+                                //绗笁鍒�
+                                //鑾峰彇妫�楠岄」鐩拰缁撹
+                                InsProduct insProduct = products.get(i - 1);
+                                String shiyanjieguo = "鏃犲紓甯�";
+                                if (ObjectUtils.isNotNull(insProduct.getInsResult())) {
+                                    shiyanjieguo = insProduct.getInsResult() == 0 ? "涓嶅悎鏍�" : "鏃犲紓甯�";
+                                }
+                                textRenderData.setText("缁忚繃" + insProduct.getInspectionItemSubclass() + "涔嬪悗锛屾牱鍝�" + shiyanjieguo + "銆�");
                                 renderData.add(textRenderData);
                                 paragraphRenderData.setContents(renderData);
                                 paragraphRenderDataList.add(paragraphRenderData);
@@ -3138,9 +3226,7 @@
             insOrder.setPhone("/");
         }
         //妫�楠岄」鐩殑鐜
-        InsProduct insProduct = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
-                .eq(InsProduct::getState, 1)
-                .eq(InsProduct::getInsSampleId, insReportDto1.getSampleId())).get(0);
+        InsProduct insProduct = insProducts.get(0);
         String environment = "";
         environment = (ObjectUtils.isNotEmpty(insProduct.getTemperature()) ? insProduct.getTemperature() + "鈩� " : "") + (ObjectUtils.isNotEmpty(insProduct.getHumidity()) ? insProduct.getHumidity() + "%" : "");
         String finalEnvironment = environment;
@@ -3169,7 +3255,6 @@
                     put("twoCode", Pictures.ofLocal(codePath).create());
                     put("models", finalModelStr.replace(",", ""));
                     put("productSize", productSize);
-                    put("productSize1", productSize1);
                     put("productSize2", productSize2);
                     put("productSize3", productSize3);
                     put("createTime", now.format(DateTimeFormatter.ofPattern("yyyy骞碝M鏈坉d鏃�")));

--
Gitblit v1.9.3