From 4bc7776bc6c063a9bfb9806e4bf6db5bf22985b1 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 09 十二月 2024 16:10:01 +0800
Subject: [PATCH] 电路试验的互调报告解析

---
 system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java                 |   13 +-
 inspect-server/src/main/java/com/yuanchu/mom/utils/DianLuUtils.java                    |  135 +++++++++++++++++++++++++++++++++
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java |   12 ++
 inspect-server/src/main/java/com/yuanchu/mom/excel/HuTiaoData.java                     |   62 +++++++++++++++
 inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java          |    2 
 5 files changed, 214 insertions(+), 10 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/excel/HuTiaoData.java b/inspect-server/src/main/java/com/yuanchu/mom/excel/HuTiaoData.java
new file mode 100644
index 0000000..8291278
--- /dev/null
+++ b/inspect-server/src/main/java/com/yuanchu/mom/excel/HuTiaoData.java
@@ -0,0 +1,62 @@
+package com.yuanchu.mom.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Data
+public class HuTiaoData {
+
+    @ExcelProperty("娴嬭瘯鏃ユ湡")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private LocalDateTime textTime;
+
+    @ExcelProperty("澶╃嚎搴忓垪鍙�")
+    private String code;
+
+    @ExcelProperty("绔彛鍙�")
+    private String port;
+
+    @ExcelProperty("娴嬭瘯棰戞")
+    private String often;
+
+    @ExcelProperty("P1")
+    private String num1;
+
+    @ExcelProperty("P2")
+    private String num2;
+
+    @ExcelProperty("F1")
+    private String num3;
+
+    @ExcelProperty("F2")
+    private String num4;
+
+    @ExcelProperty("IMF")
+    private String num5;
+
+    @ExcelProperty("娴嬭瘯妯″紡")
+    private String method;
+
+    @ExcelProperty("浜掕皟闃舵暟")
+    private String hutiao;
+
+    @ExcelProperty("涓嬪�捐")
+    private String angle;
+
+    @ExcelProperty("鎸囨爣")
+    private String ask;
+
+    @ExcelProperty("娴嬭瘯缁撴灉")
+    private String value;
+
+    @ExcelProperty("鍒ゅ畾缁撴灉")
+    private String result;
+
+
+}
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java b/inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java
index 6863ffb..8a34598 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/InsOrderPlanService.java
@@ -47,7 +47,7 @@
 
     Map<String,Object> getFileList(Page page, InsOrderFile insOrderFile);
 
-    int uploadFile(Integer orderId, MultipartFile file,String sonLaboratory,Integer sampleId);
+    Object uploadFile(Integer orderId, MultipartFile file,String sonLaboratory,Integer sampleId);
 
     List<String> upPlanUser2(Integer sampleId);
 
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
index e1187dd..28d5611 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -129,6 +129,9 @@
     @Resource
     FuSheUtils fuSheUtils;
 
+    @Resource
+    DianLuUtils dianLuUtils;
+
     @Override
     public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
         Map<String, Object> map = new HashMap<>();
@@ -310,7 +313,7 @@
     }
 
     @Override
-    public int uploadFile(Integer orderId, MultipartFile file, String sonLaboratory, Integer sampleId) {
+    public Object uploadFile(Integer orderId, MultipartFile file, String sonLaboratory, Integer sampleId) {
         String urlString;
         String pathName;
         String path;
@@ -350,6 +353,8 @@
                 fuSheUtils.getFuSheWord1(sonLaboratory, insOrderFile);
             } else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("杩滃満") && split[split.length - 1].equals("xlsx")) {
                 fuSheUtils.getFuSheWord2(sonLaboratory, insOrderFile);
+            }else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("鐢佃矾璇曢獙") && split[split.length - 1].equals("xlsx") && filename.contains("浜よ皟")) {
+               dianLuUtils.readDianLuFile1(sampleId,insOrderFile);
             }
         } catch (Exception e) {
             System.err.println("闄勪欢涓婁紶閿欒");
@@ -1042,7 +1047,10 @@
                     if (insOrder.getFormType().equals("鍘熺悊鏍锋満")) {
                         //鍑哄簱
                         try {
-                            outInsOrderState(laboratory, insSample.getSampleCode(), insOrder.getEntrustCode());
+                            List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, insSample.getInsOrderId()));
+                            for (InsSample sample : insSamples) {
+                                outInsOrderState(laboratory, sample.getSampleCode(), insOrder.getEntrustCode());
+                            }
                         } catch (Exception e) {
 
                         }
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/utils/DianLuUtils.java b/inspect-server/src/main/java/com/yuanchu/mom/utils/DianLuUtils.java
new file mode 100644
index 0000000..2f2c23d
--- /dev/null
+++ b/inspect-server/src/main/java/com/yuanchu/mom/utils/DianLuUtils.java
@@ -0,0 +1,135 @@
+package com.yuanchu.mom.utils;
+
+
+import com.alibaba.excel.EasyExcel;
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.yuanchu.mom.excel.HuTiaoData;
+import com.yuanchu.mom.mapper.InsOrderStateMapper;
+import com.yuanchu.mom.mapper.InsProductMapper;
+import com.yuanchu.mom.mapper.InsProductResult2Mapper;
+import com.yuanchu.mom.mapper.InsSampleMapper;
+import com.yuanchu.mom.pojo.*;
+import com.yuanchu.mom.service.InsOrderPlanService;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+import java.util.stream.Collectors;
+
+@Component
+public class DianLuUtils {
+
+    @Value("${wordUrl}")
+    private String wordUrl;
+
+    @Resource
+    private InsProductMapper insProductMapper;
+
+    @Resource
+    private InsSampleMapper insSampleMapper;
+
+    @Resource
+    private InsProductResult2Mapper insProductResult2Mapper;
+
+    @Resource
+    private InsOrderStateMapper insOrderStateMapper;
+
+    //璇诲彇浜掕皟鐨勬枃浠�
+    public void readDianLuFile1(Integer sampleId,InsOrderFile insOrderFile) {
+        String excelFilePath = wordUrl + "/" + insOrderFile.getFileUrl(); // 鏇存柊涓轰綘鐨勬枃浠惰矾寰�
+        List<HuTiaoData> huTiaoData = readExcelData(excelFilePath);
+        //鏌ヨ璇ユ牱鍝佺殑浜掕皟椤圭洰id
+        List<InsProduct> products = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                .eq(InsProduct::getState, 1)
+                .eq(InsProduct::getInsSampleId, sampleId)
+                .eq(InsProduct::getInspectionItemSubclass, "浜掕皟"));
+        //鏌ヨ妫�楠屼换鍔d
+        List<InsOrderState> orderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery()
+                .eq(InsOrderState::getInsSampleId, sampleId)
+                .eq(InsOrderState::getLaboratory, "鐢佃矾璇曢獙"));
+        //鏌ヨ鍘熸湁妫�楠屾暟鎹�
+        List<InsProduct> productList = getInsProduct(sampleId, "鐢佃矾璇曢獙");
+        //鏍规嵁棰戠偣鍒嗙被
+        Map<String, List<HuTiaoData>> collect = huTiaoData.stream().collect(Collectors.groupingBy(HuTiaoData::getOften,LinkedHashMap::new, Collectors.toList()));
+        for (Map.Entry<String, List<HuTiaoData>> stringListEntry : collect.entrySet()) {
+            InsProductResult2 insProductResult2 = new InsProductResult2();
+            insProductResult2.setOften(stringListEntry.getKey()+"(M)");//棰戠偣
+            //鏍规嵁涓嬪�捐杩涜鍒嗙被
+            Map<String, List<HuTiaoData>> collect1 = stringListEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getAngle,LinkedHashMap::new, Collectors.toList()));
+            String angles = collect1.entrySet().stream().map(stringListEntry1 -> stringListEntry1.getKey() + "掳").collect(Collectors.joining(","));
+            insProductResult2.setAngle(angles); //涓嬪�捐
+            //鏍规嵁绔彛鍙疯繘琛屽垎绫�
+            Map<String, List<HuTiaoData>> collect2 = stringListEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getPort,LinkedHashMap::new, Collectors.toList()));
+            String ports = collect2.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.joining(","));
+            insProductResult2.setPort(ports); //绔彛鍙�
+            //閫氳繃鍚屼竴绔彛鍙峰悓涓�涓嬪�捐鑾峰彇鏈�澶ф楠屽��
+            List<String> string = new ArrayList<>();
+            for (Map.Entry<String, List<HuTiaoData>> listEntry : collect1.entrySet()) {
+                Map<String, List<HuTiaoData>> collect3 = listEntry.getValue().stream().collect(Collectors.groupingBy(HuTiaoData::getPort,LinkedHashMap::new, Collectors.toList()));
+                List<String> stringList = new ArrayList<>();
+                for (Map.Entry<String, List<HuTiaoData>> entry : collect3.entrySet()) {
+                    OptionalDouble max = entry.getValue().stream().mapToDouble(value -> Double.parseDouble(value.getValue())).max();
+                    stringList.add(String.valueOf(max.getAsDouble()));
+                }
+                string.add("[" + stringList.stream().collect(Collectors.joining(",")) + "]");
+            }
+            String value = "[" + string.stream().collect(Collectors.joining(",")) + "]";
+            insProductResult2.setValue(value);
+            insProductResult2.setInsProductId(products.get(0).getId());
+            //娆℃暟
+            insProductResult2.setNum(orderStates.get(0).getNum());
+            //棰戞(鍏堝垽鏂師鏈夋暟鎹槸鍚︽湁)
+            if (ObjectUtils.isNotEmpty(productList.get(0).getInsProductResult2())) {
+                insProductResult2.setFrequency(productList.get(0).getInsProductResult2().get(0).getFrequency());
+            }
+            insProductResult2Mapper.insert(insProductResult2);
+        }
+    }
+
+
+    public static List<HuTiaoData> readExcelData(String filePath) {
+        List<HuTiaoData> dataList = new ArrayList<>();
+
+        // 鍒濆鍖栫洃鍚櫒
+        AnalysisEventListener<HuTiaoData> listener = new AnalysisEventListener<HuTiaoData>() {
+            @Override
+            public void invoke(HuTiaoData data, AnalysisContext context) {
+                // 澶勭悊姣忚鏁版嵁锛岃繖閲岀畝鍗曞湴娣诲姞鍒版暟鎹垪琛ㄤ腑
+                dataList.add(data);
+            }
+
+            @Override
+            public void doAfterAllAnalysed(AnalysisContext context) {
+                // 鎵�鏈夋暟鎹В鏋愬畬鎴愬悗鐨勬搷浣滐紝杩欓噷鏆備笉瀹炵幇
+            }
+        };
+
+        // 璇诲彇Excel鏂囦欢
+        EasyExcel.read(filePath, HuTiaoData.class, listener).sheet().doRead();
+
+        return dataList;
+    }
+
+    public List<InsProduct> getInsProduct(Integer id, String laboratory) {
+        List<InsProduct> insProducts = new ArrayList<>();
+        //鏍峰搧
+        insProducts = insSampleMapper.getInsProduct1(id, laboratory);
+        if (insProducts.size() == 0) {
+            insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
+                    .eq(InsProduct::getInsSampleId, id)
+                    .eq(InsProduct::getState, 1)
+                    .eq(InsProduct::getSonLaboratory, laboratory));
+            for (InsProduct insProduct : insProducts) {
+                List<InsProductResult2> insProductResult2List = insProductResult2Mapper.selectList(Wrappers.<InsProductResult2>lambdaQuery()
+                        .eq(InsProductResult2::getInsProductId, insProduct.getId()).isNull(InsProductResult2::getNum));
+                insProduct.setInsProductResult2(insProductResult2List);
+            }
+        }
+        return insProducts;
+    }
+}
diff --git a/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java b/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java
index 2b40701..d4380f0 100644
--- a/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java
+++ b/system-run/src/test/java/com/yuanchu/mom/SystemRunApplicationTest.java
@@ -3,11 +3,13 @@
 import com.alibaba.fastjson.JSONArray;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.yuanchu.mom.exception.ErrorException;
+import com.yuanchu.mom.utils.DianLuUtils;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.el.lang.ExpressionBuilder;
 import org.junit.jupiter.api.Test;
 import org.springframework.boot.test.context.SpringBootTest;
 
+import javax.annotation.Resource;
 import javax.script.ScriptEngine;
 import javax.script.ScriptEngineManager;
 import java.math.BigDecimal;
@@ -29,15 +31,12 @@
 @SpringBootTest
 class SystemRunApplicationTest {
 
+    @Resource
+    DianLuUtils dianLuUtils;
+
     @Test
     void contextLoads() {
-        List<List<String>> outerList = new ArrayList<>();
-        String str = "[[\"127\",\"123\",\"124\",\"123\",\"119\",\"122\",\"\",\"\",\"126\",\"112\"],[\"117\",\"124\",\"121\",\"122\",\"123\",\"127\",\"123\",\"112\"],[\"125\",\"125\",\"122\",\"123\",\"129\",\"124\",\"122\",\"118\"]]";
-        String[] value = str.split("\\],\\[");
-        String[] split = value[0].replaceAll("[\\[\\]\"]", "").split(",");
-        String aa=split[6];
-        System.out.println(aa);
-
+        //dianLuUtils.readDianLuFile1();
     }
 
 

--
Gitblit v1.9.3