From a5b1bad21ba279ade3954852a5e281e9086042f0 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期二, 26 十一月 2024 15:22:52 +0800
Subject: [PATCH] 前端联调修改2.0

---
 inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java |  133 ++++++++++++++++++++++++--------------------
 1 files changed, 73 insertions(+), 60 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java b/inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java
index 46de379..7e1e95d 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/utils/FuSheUtils.java
@@ -1,5 +1,6 @@
 package com.yuanchu.mom.utils;
 
+import cn.hutool.core.lang.UUID;
 import com.deepoove.poi.XWPFTemplate;
 import com.deepoove.poi.config.Configure;
 import com.deepoove.poi.config.ConfigureBuilder;
@@ -11,8 +12,10 @@
 import com.yuanchu.mom.exception.ErrorException;
 import com.yuanchu.mom.mapper.InsOrderFileMapper;
 import com.yuanchu.mom.mapper.InsOrderMapper;
+import com.yuanchu.mom.mapper.InsSampleMapper;
 import com.yuanchu.mom.pojo.InsOrder;
 import com.yuanchu.mom.pojo.InsOrderFile;
+import com.yuanchu.mom.pojo.InsSample;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.openxml4j.util.ZipSecureFile;
@@ -42,7 +45,7 @@
     InsOrderFileMapper insOrderFileMapper;
 
     @Resource
-    InsOrderMapper insOrderMapper;
+    InsSampleMapper insSampleMapper;
 
     public void getFuSheWord1(String sonLaboratory, InsOrderFile insOrderFile) {
         //璇诲彇excel鏂囦欢鍐呭
@@ -56,6 +59,7 @@
             Exceldata exceldata = new Exceldata();
             Map<Integer, Object> project = new HashMap<>();
             HashMap<String, Object> datas1 = new HashMap<>();
+            Boolean exitLoop=false;
             for (int i = 0; i < workbook.getNumberOfSheets(); i++) {
                 String s = "";
                 Sheet sheet = workbook.getSheetAt(i);
@@ -85,10 +89,13 @@
                                     default:
                                         System.out.print("NULL\t");
                                 }
-                            }
-                            else {
+                            } else {
                                 switch (cell.getCellType()) {
                                     case STRING:
+                                        if (cell.getColumnIndex()==1) {
+                                            exitLoop=true;
+                                            break;
+                                        }
                                         if (StringUtils.isNotEmpty(s)) {
                                             datas.put(s, list);
                                         }
@@ -113,6 +120,10 @@
                                         System.out.print("NULL\t");
                                 }
                             }
+                            if (exitLoop){
+                                exitLoop=false;
+                                break;
+                            }
                             if (map.isEmpty()) {
                                 list.add(map);
                             }
@@ -135,15 +146,17 @@
                     for (Map<String, Object> number : hashMaps) {
                         number.put("绔彛", s1);
                         Double o = (Double) number.get("棰戠巼");
-                        floatList.add(o);
+                        if (o!=null) {
+                            floatList.add(o);
+                        }
                     }
                     Double maxValue = Collections.max(floatList);
                     Double minValue = Collections.min(floatList);
-                    if (map.get(minValue + "-" + maxValue + "-" + s) == null) {
-                        map.put(minValue + "-" + maxValue + "-" + s, s1);
+                    if (map.get(minValue + "," + maxValue + "," + s) == null) {
+                        map.put(minValue + "," + maxValue + "," + s, s1);
                     } else {
-                        Object o = map.get(minValue + "-" + maxValue + "-" + s);
-                        map.put(minValue + "-" + maxValue + "-" + s, s1 + "," + o);
+                        Object o = map.get(minValue + "," + maxValue + "," + s);
+                        map.put(minValue + "," + maxValue + "," + s, s1 + "," + o);
                     }
                 }
             }
@@ -199,8 +212,8 @@
         HashMap<String, Object> map2 = new HashMap<>();
         List<Map<String, Object>> list = new ArrayList<>();
         XWPFDocument document = new XWPFDocument();
-        String jiaodu="";
-        String port="";
+        String jiaodu = "";
+        String port = "";
         try (CSVReader reader = new CSVReader(new InputStreamReader(new FileInputStream(excelFilePath), fileEncoding))) {
             List<String[]> records = reader.readAll();
             for (int i = 0; i < records.size(); i++) {
@@ -211,13 +224,13 @@
                 for (int i1 = 0; i1 < record.length; i1++) {
                     String value = record[i1];
                     if (i == 0) {
-                        project.put(i1,value);
+                        project.put(i1, value);
                     }
                     if (i == 1) {
-                        biaozhun.put(project.get(i1).toString(),value);
+                        biaozhun.put(project.get(i1).toString(), value);
                     }
-                    if (i>2) {
-                        if (i1==0&&StringUtils.isNotEmpty(value)) {
+                    if (i > 2) {
+                        if (i1 == 0 && StringUtils.isNotEmpty(value)) {
 
                             if (map2.size() != 0) {
                                 map2.put(port, list);
@@ -225,16 +238,16 @@
                                 map2 = new HashMap<>();
                             }
                             datas1.put(value, "");
-                            jiaodu=value;
+                            jiaodu = value;
                         } else if (i1 == 1 && StringUtils.isNotEmpty(value)) {
                             if (list.size() != 0) {
                                 map2.put(port, list);
                                 list = new ArrayList<>();
                             }
                             map2.put(value, "");
-                            port=value;
+                            port = value;
                         } else if (StringUtils.isNotEmpty(value)) {
-                            if (value.equals("鏈�澶у��")||value.equals("鏈�灏忓��")||value.equals("鎸囨爣")||value.equals("绫诲埆")) {
+                            if (value.equals("鏈�澶у��") || value.equals("鏈�灏忓��") || value.equals("鎸囨爣") || value.equals("绫诲埆")) {
                                 break;
                             } else if (value.equals("骞冲潎鍊�")) {
                                 for (int i2 = 0; i2 < record.length; i2++) {
@@ -242,24 +255,24 @@
                                     if (value1.equals("骞冲潎鍊�")) {
                                         continue;
                                     }
-                                    pingjun.put(project.get(i2).toString(),value1);
+                                    pingjun.put(project.get(i2).toString(), value1);
                                 }
                                 break;
                             }
-                            map1.put(project.get(i1).toString(),value);
+                            map1.put(project.get(i1).toString(), value);
                         }
                     }
                     System.out.print(value + " ");
                 }
-                if (map1.size()!=0) {
+                if (map1.size() != 0) {
                     list.add(map1);
                 }
-                if (pingjun.size()!=0) {
-                    pingjunzhi.put(jiaodu,pingjun);
+                if (pingjun.size() != 0) {
+                    pingjunzhi.put(jiaodu, pingjun);
                 }
-                if (i==records.size()-1) {
-                    map2.put(port,list);
-                    datas1.put(jiaodu,map2);
+                if (i == records.size() - 1) {
+                    map2.put(port, list);
+                    datas1.put(jiaodu, map2);
                 }
                 System.out.println();
             }
@@ -274,23 +287,23 @@
 
         HashMap<String, Object> map = new HashMap<>();
         for (String s : datas1.keySet()) {
-            Map<String, List<HashMap<String,Object>>> numbers = (Map<String, List<HashMap<String,Object>>>) datas1.get(s);
+            Map<String, List<HashMap<String, Object>>> numbers = (Map<String, List<HashMap<String, Object>>>) datas1.get(s);
             for (String s1 : numbers.keySet()) {
                 List<HashMap<String, Object>> hashMaps = numbers.get(s1);
 
                 List<Integer> floatList = new ArrayList<>();
                 for (Map<String, Object> number : hashMaps) {
                     number.put("绔彛", s1);
-                    floatList.add( Integer.parseInt((String) number.get("娴嬭瘯棰戠巼(MHZ)")));
+                    floatList.add(Integer.parseInt((String) number.get("娴嬭瘯棰戠巼(MHZ)")));
                 }
                 Integer maxValue = Collections.max(floatList);
                 Integer minValue = Collections.min(floatList);
 
-                if (map.get(minValue + "-" + maxValue+"-"+s) == null) {
-                    map.put(minValue + "-" + maxValue+"-"+s, s1);
+                if (map.get(minValue + "-" + maxValue + "-" + s) == null) {
+                    map.put(minValue + "-" + maxValue + "-" + s, s1);
                 } else {
-                    Object o = map.get(minValue + "-" + maxValue+"-"+s);
-                    map.put(minValue + "-" + maxValue+"-"+s, s1 + "," + o);
+                    Object o = map.get(minValue + "-" + maxValue + "-" + s);
+                    map.put(minValue + "-" + maxValue + "-" + s, s1 + "," + o);
                 }
             }
 
@@ -305,9 +318,9 @@
             int size1 = -1;
 
             for (String s : datas1.keySet()) {
-                Map<String, List<HashMap<String,Object>>> o1 = (Map<String, List<HashMap<String,Object>>>)datas1.get(s);
+                Map<String, List<HashMap<String, Object>>> o1 = (Map<String, List<HashMap<String, Object>>>) datas1.get(s);
                 for (String s3 : o1.keySet()) {
-                    List<HashMap<String, Object>> numbers =  o1.get(s3);
+                    List<HashMap<String, Object>> numbers = o1.get(s3);
                     for (String s2 : collect) {
                         if (s3.equals(s2)) {
                             if (numbers.size() > size1) {
@@ -323,7 +336,7 @@
         System.out.println(map);
 
         try {
-            createWord2(sonLaboratory,document,exceldata, map,pingjunzhi,biaozhun,insOrderFile);
+            createWord2(sonLaboratory, document, exceldata, map, pingjunzhi, biaozhun, insOrderFile);
         } catch (IOException e) {
             e.printStackTrace();
         }
@@ -339,8 +352,8 @@
         runs.setText("杈愬皠鏂瑰悜鍥惧弬鏁�");
         for (String s : map.keySet()) {
             Map<String, Object> dataRow = exceldata.getDataRow();
-            String result = s.substring(s.lastIndexOf("-") + 1);
-            String result1 = s.substring(0, s.lastIndexOf("-"));
+            String result = s.substring(s.lastIndexOf(",") + 1);
+            String result1 = s.substring(0, s.lastIndexOf(","));
             String o = map.get(s).toString();
             String[] split = o.split(",");
             Integer s1 = Integer.parseInt(split[split.length - 1]);
@@ -518,24 +531,25 @@
                 paragraph11.setAlignment(ParagraphAlignment.CENTER);
                 XWPFRun run11 = paragraph11.createRun();
                 double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString()));
-                run11.setText(String.format("%.2f",v));
+                run11.setText(String.format("%.2f", v));
                 size++;
             }
         }
         // 杈撳嚭鍒版枃浠�
         try {
-            InsOrder insOrder = insOrderMapper.selectById(insOrderFile.getInsOrderId());
+            InsSample insSample = insSampleMapper.selectById(insOrderFile.getInsSampleId());
             String[] split = insOrderFile.getFileName().split("\\.");
-            String name = insOrderFile.getFileName().substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length()));
-            FileOutputStream out = new FileOutputStream(wordUrl + "/" + insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            String name = insOrderFile.getFileName().replace('#','&').substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length()));
+            FileOutputStream out = new FileOutputStream(wordUrl + "/" + UUID.randomUUID() + "_" + insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             document.write(out);
             out.close();
             document.close();
             InsOrderFile orderFile = new InsOrderFile();
             orderFile.setInsOrderId(insOrderFile.getInsOrderId());
-            orderFile.setFileUrl(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            orderFile.setInsSampleId(insOrderFile.getInsSampleId());
+            orderFile.setFileUrl(UUID.randomUUID() + "_" + insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             orderFile.setType(2);
-            orderFile.setFileName(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            orderFile.setFileName(insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             orderFile.setSonLaboratory(sonLaboratory);
             insOrderFileMapper.insert(orderFile);
         } catch (IOException e) {
@@ -543,19 +557,19 @@
         }
     }
 
-    public void createWord2(String sonLaboratory,XWPFDocument document,Exceldata exceldata, HashMap<String, Object> map,HashMap<String,Object> pj,HashMap<String,Object> bz,InsOrderFile insOrderFile) throws IOException {
+    public void createWord2(String sonLaboratory, XWPFDocument document, Exceldata exceldata, HashMap<String, Object> map, HashMap<String, Object> pj, HashMap<String, Object> bz, InsOrderFile insOrderFile) throws IOException {
         int size = 1;
         for (String s : map.keySet()) {
             Map<String, Object> dataRow = exceldata.getDataRow();
             String result = s.substring(s.lastIndexOf("-") + 1);
-            String result1 = s.substring(0,s.lastIndexOf("-"));
+            String result1 = s.substring(0, s.lastIndexOf("-"));
             String o = map.get(s).toString();
             String[] split = o.split(",");
             Integer s1 = Integer.parseInt(split[split.length - 1]);
             Integer i1 = split.length - 1;
             int row = 3 + s1;
             int cell = 6 + i1;
-            HashMap<String,Object> o2 =(HashMap<String,Object>) pj.get(result);
+            HashMap<String, Object> o2 = (HashMap<String, Object>) pj.get(result);
 
             XWPFTable table1 = document.createTable(2, cell);
 
@@ -578,7 +592,7 @@
             XWPFRun run15 = paragraph15.createRun();
             run15.setText("鏍囧噯瑕佹眰");
 
-            XWPFParagraph paragraph16 = table1.getRow(0).getCell(cell-1).getParagraphArray(0);
+            XWPFParagraph paragraph16 = table1.getRow(0).getCell(cell - 1).getParagraphArray(0);
             XWPFRun run16 = paragraph16.createRun();
             run16.setText("妫�楠岀粨璁�");
 
@@ -588,8 +602,7 @@
 
             XWPFParagraph paragraph18 = table1.getRow(1).getCell(0).getParagraphArray(0);
             XWPFRun run18 = paragraph18.createRun();
-            run18.setText("棰戞锛� "+result1+"MHz "+"涓嬪�捐"+result);
-
+            run18.setText("棰戞锛� " + result1 + "MHz " + "涓嬪�捐" + result);
 
 
             List<String> collect = Arrays.stream(split).collect(Collectors.toList());
@@ -604,7 +617,7 @@
 
             Map<String, List<Map<String, Object>>> o1 = (Map<String, List<Map<String, Object>>>) dataRow.get(result);
             for (String s2 : collect) {
-                if (s2.contains("绔彛")||s2.contains("P")) {
+                if (s2.contains("绔彛") || s2.contains("P")) {
                     List<Map<String, Object>> mapList = o1.get(s2);
                     list.addAll(mapList);
                 }
@@ -622,7 +635,7 @@
 
 
             for (String s2 : aggregatedMap.keySet()) {
-                if (s2.equals("绔彛")||s2.equals("娴嬭瘯棰戠巼(MHZ)")) {
+                if (s2.equals("绔彛") || s2.equals("娴嬭瘯棰戠巼(MHZ)")) {
                     continue;
                 }
                 List<Map<String, Object>> mapList = aggregatedMap.get(s2);
@@ -672,7 +685,6 @@
                 }
 
 
-
                 XWPFParagraph paragraph3 = table.getRow(0).getCell(3).getParagraphArray(0);
                 XWPFRun run3 = paragraph3.createRun();
                 run3.setText(bz.get(s2).toString());
@@ -704,7 +716,7 @@
 
                 for (int i = 0; i < collect.size(); i++) {
                     String s3 = collect.get(i);
-                    if (s3.contains("绔彛")||s3.contains("P")) {
+                    if (s3.contains("绔彛") || s3.contains("P")) {
                         XWPFParagraph paragraph10 = table.getRow(1).getCell(5 + i).getParagraphArray(0);
                         XWPFRun run10 = paragraph10.createRun();
                         run10.setText(s3);
@@ -712,7 +724,7 @@
                 }
 
                 Map<Integer, List<Map<String, Object>>> group = mapList.stream()
-                        .collect(Collectors.groupingBy(item -> Integer.parseInt(item.get("娴嬭瘯棰戠巼(MHZ)").toString()) ));
+                        .collect(Collectors.groupingBy(item -> Integer.parseInt(item.get("娴嬭瘯棰戠巼(MHZ)").toString())));
 
 
                 int hang = 2;
@@ -726,7 +738,7 @@
                             if (text.equals(port)) {
                                 XWPFParagraph paragraph10 = table.getRow(hang).getCell(i).getParagraphArray(0);
                                 XWPFRun run10 = paragraph10.createRun();
-                                count=Double.parseDouble(stringObjectMap.get(s2).toString())+count;
+                                count = Double.parseDouble(stringObjectMap.get(s2).toString()) + count;
                                 String project = stringObjectMap.get(s2).toString();
                                 run10.setText(project);
                             }
@@ -740,7 +752,7 @@
                     hang++;
                 }
 
-                XWPFParagraph paragraph11 = table.getRow(row-1).getCell(5).getParagraphArray(0);
+                XWPFParagraph paragraph11 = table.getRow(row - 1).getCell(5).getParagraphArray(0);
                 XWPFRun run11 = paragraph11.createRun();
                 double v = count / (Double.parseDouble(s1.toString()) * Double.parseDouble(i1.toString()));
                 run11.setText(o2.get(s2).toString());
@@ -752,18 +764,19 @@
 
         // 杈撳嚭鍒版枃浠�
         try {
-            InsOrder insOrder = insOrderMapper.selectById(insOrderFile.getInsOrderId());
+            InsSample insSample = insSampleMapper.selectById(insOrderFile.getInsSampleId());
             String[] split = insOrderFile.getFileName().split("\\.");
-            String name = insOrderFile.getFileName().replace("#","&").substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length()));
-            FileOutputStream out = new FileOutputStream(wordUrl + "/" + insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            String name = insOrderFile.getFileName().replace("#", "&").substring(0, (insOrderFile.getFileName().length() - split[split.length - 1].length()));
+            FileOutputStream out = new FileOutputStream(wordUrl + "/" + UUID.randomUUID() + "_" + insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             document.write(out);
             out.close();
             document.close();
             InsOrderFile orderFile = new InsOrderFile();
             orderFile.setInsOrderId(insOrderFile.getInsOrderId());
-            orderFile.setFileUrl(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            orderFile.setInsSampleId(insOrderFile.getInsSampleId());
+            orderFile.setFileUrl(UUID.randomUUID() + "_" + insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             orderFile.setType(2);
-            orderFile.setFileName(insOrder.getEntrustCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
+            orderFile.setFileName(insSample.getSampleCode() + "&" + sonLaboratory + name + "瑙f瀽鐨勮緪灏勭珯鐐规姤鍛�.docx");
             orderFile.setSonLaboratory(sonLaboratory);
             insOrderFileMapper.insert(orderFile);
         } catch (IOException e) {

--
Gitblit v1.9.3