From cb3ec598dc18e66b70a2cc9f7181c8be5bcf6e57 Mon Sep 17 00:00:00 2001
From: zhuo <2089219845@qq.com>
Date: 星期二, 01 四月 2025 08:50:16 +0800
Subject: [PATCH] 检验项预警非文字检验项都要预警

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  205 +++++++++++++++++++++++++++------------------------
 1 files changed, 109 insertions(+), 96 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 f8d709c..b8bb4a0 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
@@ -72,6 +72,7 @@
 import java.math.RoundingMode;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
@@ -115,8 +116,6 @@
     private InsProductUserMapper insProductUserMapper;
     @Resource
     private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService;
-    @Resource
-    private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService;
     @Resource
     private AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper;
     @Resource
@@ -527,55 +526,60 @@
 
         // 娣诲姞璁惧璁板綍
         threadPoolTaskExecutor.execute(() -> {
-            InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId());
-            User user = userMapper.selectById(userId);
-            // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍
-            List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId());
-            Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet());
+            // 娣诲姞璁惧浣跨敤璁板綍
+            addDeviceRecord(insSample, userId);
+        });
+    }
 
-            // 鑾峰彇璁㈠崟璁惧缂栧彿
-            List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId());
-            Set<String> deviceCodeSet = new HashSet<>();
-            for (InsProductResult result : resultList) {
-                // 娣诲姞璁惧缂栧彿
-                List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class);
-                for (JSONObject jsonObject : jsonObjects) {
-                    if (!"".equals(jsonObject.get("v") + "")) {
-                        List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�");
-                        deviceCodeSet.addAll(v);
-                    }
+    private synchronized void addDeviceRecord(InsSample insSample, Integer userId) {
+        InsOrder order = insOrderMapper.selectById(insSample.getInsOrderId());
+        User user = userMapper.selectById(userId);
+        // 鏌ヨ璁惧浣跨敤璁板綍鏌ヨ璇ヨ鍗曠殑浣跨敤璁板綍
+        List<InsOrderDeviceRecordDto> deviceRecordDtoList = insOrderDeviceRecordMapper.selectDeviceNumber(insSample.getInsOrderId());
+        Set<String> recordCodeset = deviceRecordDtoList.stream().map(InsOrderDeviceRecordDto::getManagementNumber).collect(Collectors.toSet());
+
+        // 鑾峰彇璁㈠崟璁惧缂栧彿
+        List<InsProductResult> resultList = insProductResultMapper.selectResultByOrderId(insSample.getInsOrderId());
+        Set<String> deviceCodeSet = new HashSet<>();
+        for (InsProductResult result : resultList) {
+            // 娣诲姞璁惧缂栧彿
+            List<JSONObject> jsonObjects = JSON.parseArray(result.getEquipValue(), JSONObject.class);
+            for (JSONObject jsonObject : jsonObjects) {
+                if (!"".equals(jsonObject.get("v") + "")) {
+                    List<String> v = StrUtil.split(jsonObject.get("v") + "", "锛�");
+                    deviceCodeSet.addAll(v);
                 }
             }
-            // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍
-            Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset);
-            // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id
-            if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) {
-                List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers);
-                List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> {
-                    InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord();
-                    insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId());
-                    insOrderDeviceRecord.setDeviceId(deviceId);
-                    insOrderDeviceRecord.setSampleCode(order.getEntrustCode());
-                    insOrderDeviceRecord.setUseBefore(1);
-                    insOrderDeviceRecord.setUseAfter(1);
-                    insOrderDeviceRecord.setUsePerson(user.getName());
-                    insOrderDeviceRecord.setUsePersonId(user.getId());
-                    return insOrderDeviceRecord;
-                }).collect(Collectors.toList());
+        }
+        // 1.鍒ゆ柇鏄惁鏈夋病鏈夋坊鍔犵殑浣跨敤璁板綍
+        Set<String> orderDeviceNumbers = getDeviceDifference(deviceCodeSet, recordCodeset);
+        // 娣诲姞浣跨敤璁板綍, 鏍规嵁缂栧彿鏌ヨ璁惧id
+        if (CollectionUtils.isNotEmpty(orderDeviceNumbers)) {
+            List<Integer> orderDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(orderDeviceNumbers);
+            List<InsOrderDeviceRecord> collect = orderDeviceIds.stream().map(deviceId -> {
+                InsOrderDeviceRecord insOrderDeviceRecord = new InsOrderDeviceRecord();
+                insOrderDeviceRecord.setInsOrderId(insSample.getInsOrderId());
+                insOrderDeviceRecord.setDeviceId(deviceId);
+                insOrderDeviceRecord.setSampleCode(order.getEntrustCode());
+                insOrderDeviceRecord.setUseBefore(1);
+                insOrderDeviceRecord.setUseAfter(1);
+                insOrderDeviceRecord.setUsePerson(user.getName());
+                insOrderDeviceRecord.setUsePersonId(user.getId());
+                return insOrderDeviceRecord;
+            }).collect(Collectors.toList());
 
-                insOrderDeviceRecordService.saveBatch(collect);
+            insOrderDeviceRecordService.saveBatch(collect);
 
-            }
+        }
 
-            // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢�
-            Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet);
-            if (CollectionUtils.isNotEmpty(repoprNumbers)) {
-                List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers);
-                insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery()
-                        .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds)
-                        .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId()));
-            }
-        });
+        // 2.鍒ゆ柇鏄惁鍙栨秷浜嗚澶囦娇鐢�
+        Set<String> repoprNumbers = getDeviceDifference(recordCodeset, deviceCodeSet);
+        if (CollectionUtils.isNotEmpty(repoprNumbers)) {
+            List<Integer> reportDeviceIds = insOrderDeviceRecordMapper.selectDeviceIdsByNumbers(repoprNumbers);
+            insOrderDeviceRecordMapper.delete(Wrappers.<InsOrderDeviceRecord>lambdaQuery()
+                    .in(InsOrderDeviceRecord::getDeviceId, reportDeviceIds)
+                    .eq(InsOrderDeviceRecord::getInsOrderId, insSample.getInsOrderId()));
+        }
     }
 
     private static Set<String> getDeviceDifference(Set<String> number1, Set<String> number2) {
@@ -674,7 +678,7 @@
     }
 
     /**
-     * todo: 娓呴櫎娌℃湁浣跨敤鐨勬楠岄」
+     * todo: 鍘熷璁板綍妯℃澘娓呴櫎娌℃湁浣跨敤鐨勬楠岄」(鏆傛椂鏈塨ug鏃犳硶浣跨敤)
      * @param sheet
      * @param itemNameList
      */
@@ -949,7 +953,7 @@
             // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭�
             threadPoolTaskExecutor.execute(() -> {
                 // 娣诲姞鍒嗘瀽鏁版嵁
-                addAnalysis(productList, ifsInventoryQuantity, order);
+                addAnalysis(productList, ifsInventoryQuantity, order, userName);
             });
 
 
@@ -977,13 +981,13 @@
      * @param ifsInventoryQuantity
      * @param order
      */
-    private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order) {
+    private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String userName) {
         for (InsProduct insProduct : productList) {
-            // todo: 鏆傛椂鍒ゆ柇鏄惁鏄�佸寲
-            if (insProduct.getInspectionItem().contains("鑰佸寲")) {
+            // 鍒ゆ柇鏄惁鏄暟鍊肩被鍨�
+            if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) {
                 List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
 
-                if (insProductAnalysisDtoList.size() < 10) {
+                if (insProductAnalysisDtoList.size() < 5) {
                     continue;
                 }
 
@@ -1020,6 +1024,7 @@
                         deviationWarningDetail.setSampleCode(insProduct.getSampleCode());
                         deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName());
                         deviationWarningDetail.setTestValue(insProduct.getLastValue());
+                        deviationWarningDetail.setDetectionTime(insProduct.getCreateTime());
                         deviationWarningDetail.setIsIssue(1);
 
                         insProductAnalysisDtoList.add(deviationWarningDetail);
@@ -1031,22 +1036,26 @@
 
                         insProductDeviationWarningDetailService.saveBatch(insProductAnalysisDtoList);
 
+                        //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡  妫�楠岄」棰勮棰勮閫氱煡
+                        try {
+                            String message = "";
+                            message += "妫�楠岄」棰勮棰勮閫氱煡";
+                            message += "\n濮旀墭缂栧彿: " + order.getEntrustCode();
+                            message += "\n鏍峰搧鍚嶇О: " + order.getSample();
+                            message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail();
+                            message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo();
+                            message += "\n渚涘簲鍟嗗悕绉�: " + ifsInventoryQuantity.getSupplierName();
+                            message += "\n妫�楠岄」: " + insProduct.getInspectionItem() + insProduct.getInspectionItemSubclass();
+                            message += "\n鍋忓樊瓒呰繃浜� 10%";
+                            // 鍙戦�佺粰鎻愪氦浜�
+                            WxCpUtils.inform(userName, message, null);
 
-//                    String message = "";
-//                    message += "妫�楠屼换鍔″鏍搁�氱煡";
-//                    message += "\n鎻愪氦浜�: " + userName;
-//                    message += "\n濮旀墭缂栧彿: " + order.getEntrustCode();
-//                    message += "\n鏍峰搧鍚嶇О: " + insSample.getModel();
-//                    message += "\n瑙勬牸鍨嬪彿: " + order.getPartDetail();
-//                    if (ifsInventoryQuantity != null) {
-//                        message += "\n鎵规鍙�: " + ifsInventoryQuantity.getUpdateBatchNo();
-//                    }
-//                    //鍙戦�佷紒涓氬井淇℃秷鎭�氱煡  鎻愪氦澶嶆牳
-//                    try {
-//                        WxCpUtils.inform(sendUserAccount, message, null);
-//                    } catch (Exception e) {
-//                        throw new RuntimeException(e);
-//                    }
+                            // todo: 鍙戦�佺粰妫�娴嬩腑蹇冧富浠�(鍥哄畾姝�)
+                            WxCpUtils.inform("ZT-004704", message, null);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            log.error("鍋忓樊棰勮浼佷笟寰俊閫氱煡鎶ラ敊");
+                        }
                     }
                 }
             }
@@ -1072,7 +1081,10 @@
         double target = Double.parseDouble(targetStr);
         double deviationPercent = Math.abs(target - average) / average * 100;
 
-        return deviationPercent;
+        // 淇濈暀涓や綅灏忔暟
+        DecimalFormat df = new DecimalFormat("#.00");
+        String formatted = df.format(deviationPercent);
+        return Double.parseDouble(formatted);
     }
 
     /**
@@ -4440,42 +4452,43 @@
             return;
         }
 
-        //棣栧厛鍒ゆ柇褰撳墠浜虹殑褰撳墠鏃堕棿鏄惁鏄帓鐝椂闂村唴,濡傛灉涓嶆槸灏辨槸鍔犵彮
-        LocalDateTime today = LocalDateTime.of(LocalDate.now(), LocalTime.MIDNIGHT);
-
         //鏍¢獙濡傛灉杩欎釜浜鸿繖涓娴嬮」鐩凡缁忔坊鍔犺繃浜�
         List<AuxiliaryOutputWorkingHours> count2s = auxiliaryOutputWorkingHoursMapper.selectList(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
                 .eq(AuxiliaryOutputWorkingHours::getCheck, userId)
                 .eq(AuxiliaryOutputWorkingHours::getInsProductId, insProduct.getId()));
         if (CollectionUtils.isNotEmpty(count2s)) {
-            auxiliaryOutputWorkingHoursMapper.deleteBatchIds(count2s.stream().map(auxiliaryOutputWorkingHours -> auxiliaryOutputWorkingHours.getId()).collect(Collectors.toList()));
-        }
-        if (ObjectUtils.isNotEmpty(insProduct.getManHour()) && StringUtils.isNotBlank(insProduct.getLastValue())) {
-            AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours();
-            auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被
-            auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤�
-            auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤�
-            auxiliaryOutputWorkingHours.setSample(insSampleMapper.selectById(insProduct.getInsSampleId()).getSampleCode());//鏍峰搧缂栧彿
-            auxiliaryOutputWorkingHours.setOrderId(insOrder.getId());//璁㈠崟id
-            auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//闈炲姞鐝鎵樺崟鍙�
-            auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃�
-            auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲�
-            auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂
-            auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
-            DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡
-            LocalDateTime localDateTime = LocalDateTime.now();
-            DateTime parse = DateUtil.parse(localDateTime.format(formatter));
-            auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡
-            auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ
-            auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉
-            auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环
-            auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id
-            auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id
+            for (AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours : count2s) {
+                auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉
+            }
+            auxiliaryOutputWorkingHoursService.updateBatchById(count2s);
+        } else {
+            if (ObjectUtils.isNotEmpty(insProduct.getManHour()) && StringUtils.isNotBlank(insProduct.getLastValue())) {
+                AuxiliaryOutputWorkingHours auxiliaryOutputWorkingHours = new AuxiliaryOutputWorkingHours();
+                auxiliaryOutputWorkingHours.setInspectionItemClass(insProduct.getInspectionItemClass());//妫�娴嬮」鍒嗙被
+                auxiliaryOutputWorkingHours.setInspectionItem(insProduct.getInspectionItem());//妫�娴嬬埗椤�
+                auxiliaryOutputWorkingHours.setInspectionItemSubclass(insProduct.getInspectionItemSubclass());//妫�娴嬪瓙椤�
+                auxiliaryOutputWorkingHours.setSample(insSampleMapper.selectById(insProduct.getInsSampleId()).getSampleCode());//鏍峰搧缂栧彿
+                auxiliaryOutputWorkingHours.setOrderId(insOrder.getId());//璁㈠崟id
+                auxiliaryOutputWorkingHours.setOrderNo(insOrder.getEntrustCode());//闈炲姞鐝鎵樺崟鍙�
+                auxiliaryOutputWorkingHours.setWorkTime(insProduct.getManHour());//闈炲姞鐝伐鏃�
+                auxiliaryOutputWorkingHours.setAmount(1);//闈炲姞鐝暟閲�
+                auxiliaryOutputWorkingHours.setOutputWorkTime((ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getOvertimeWorkTime()) ? auxiliaryOutputWorkingHours.getOvertimeWorkTime() : BigDecimal.ZERO).add(ObjectUtils.isNotEmpty(auxiliaryOutputWorkingHours.getWorkTime()) ? auxiliaryOutputWorkingHours.getWorkTime() : BigDecimal.ZERO));//浜ч噺宸ユ椂
+                auxiliaryOutputWorkingHours.setManHourGroup(insProduct.getManHourGroup());//宸ユ椂鍒嗙粍
+                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                DateTimeFormatter formatters = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                auxiliaryOutputWorkingHours.setDateTime(LocalDateTime.now().toLocalDate().atStartOfDay().format(formatters));//鏃ユ湡
+                LocalDateTime localDateTime = LocalDateTime.now();
+                DateTime parse = DateUtil.parse(localDateTime.format(formatter));
+                auxiliaryOutputWorkingHours.setWeekDay(getWeek(localDateTime.format(formatters)));//鏄熸湡
+                auxiliaryOutputWorkingHours.setWeek(String.valueOf(DateUtil.weekOfYear(DateUtil.offsetDay(parse, 1))));//鍛ㄦ
+                auxiliaryOutputWorkingHours.setCheck(userId);//妫�娴嬩汉
+                auxiliaryOutputWorkingHours.setPrice(insProduct.getPrice());//鍗曚环
+                auxiliaryOutputWorkingHours.setSampleId(insProduct.getInsSampleId());//鏍峰搧id
+                auxiliaryOutputWorkingHours.setInsProductId(insProduct.getId());//妫�楠岄」id
 
-            auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
+                auxiliaryOutputWorkingHoursMapper.insert(auxiliaryOutputWorkingHours);
 
+            }
         }
     }
 

--
Gitblit v1.9.3