From 61f34419e094f2363276d614a960b379cc456482 Mon Sep 17 00:00:00 2001
From: zhuo <2089219845@qq.com>
Date: 星期二, 20 五月 2025 10:37:15 +0800
Subject: [PATCH] 业务代码合并

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  478 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 250 insertions(+), 228 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 b57a72f..8d29eee 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;
@@ -116,8 +117,6 @@
     @Resource
     private AuxiliaryOutputWorkingHoursService auxiliaryOutputWorkingHoursService;
     @Resource
-    private AuxiliaryOutputWorkingHoursTemporaryService auxiliaryOutputWorkingHoursTemporaryService;
-    @Resource
     private AuxiliaryOutputWorkingHoursMapper auxiliaryOutputWorkingHoursMapper;
     @Resource
     private InformationNotificationService informationNotificationService;
@@ -158,6 +157,11 @@
     private ISysDictTypeService iSysDictTypeService;
     @Resource
     private InsOrderRatesService insOrderRatesService;
+    @Resource
+    private InsProductDeviationWarningService insProductDeviationWarningService;
+    @Resource
+    private InsProductDeviationWarningDetailService insProductDeviationWarningDetailService;
+
 
     @Override
     public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
@@ -254,16 +258,13 @@
         List<InsProduct> insProducts = new ArrayList<>();
         switch (dto.getType()) {
             case 0:
-                insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), null);
-                //鏍峰搧
-                break;
             case 4:
-                //鐢电紗閰嶇疆
-                insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), null);
+                //濮旀墭
+                insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag());
                 break;
             case 5:
                 //鍘熸潗鏂欎笅鍗�
-                insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), null);
+                insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag());
                 break;
         }
         if (BeanUtil.isEmpty(insProducts)) {
@@ -360,15 +361,16 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void saveInsContext(Map<String, Object> insContext, Integer currentTable, Integer currentSampleId, Integer orderId, String sonLaboratory) {
+    public void saveInsContext(SaveInsContextDto saveInsContextDto) {
+        Map<String, Object> insContext = JSON.parseObject(saveInsContextDto.getParam(), Map.class);
         Integer userId = SecurityUtils.getUserId().intValue();
-        InsSample insSample = insSampleMapper.selectById(currentSampleId);
+        InsSample insSample = insSampleMapper.selectById(saveInsContextDto.getSampleId());
         insContext.forEach((k, v) -> {
             JSONObject jo = JSON.parseObject(JSON.toJSONString(v));
             InsProduct insProduct = new InsProduct();
             insProduct.setId(Integer.parseInt(k));
             InsProduct product = insProductMapper.selectById(insProduct.getId());
-            if (currentTable.equals(product.getTemplateId()) && currentSampleId.equals(product.getInsSampleId())) {
+            if (saveInsContextDto.getCurrentTable().equals(product.getTemplateId()) && saveInsContextDto.getSampleId().equals(product.getInsSampleId())) {
                 List<InsProductResult> oldResults = insProductResultMapper.selectList(Wrappers.<InsProductResult>lambdaQuery()
                         .eq(InsProductResult::getInsProductId, insProduct.getId()));
                 InsProductResult newResult = new InsProductResult();
@@ -498,23 +500,34 @@
                     }
                 }
 
-                //鏌ヨ妫�楠屽崟淇℃伅
                 // 娣诲姞宸ユ椂
-                InsProduct finalInsProduct = insProductMapper.selectById(product.getId());
-                threadPoolTaskExecutor.execute(() -> {
-                    InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId());
-                    this.addAuxiliary(userId, finalInsProduct, insOrder);
-                });
+                // 鍒ゆ柇鏄惁鍙槸鍙備笌璁$畻鍊�, 鍙備笌璁$畻鍊煎疄闄呮病鏈夊~鍐�
+                if (StringUtils.isNotBlank(newResult.getInsValue()) && !newResult.getInsValue().equals("[]")) {
+                    threadPoolTaskExecutor.execute(() -> {
+                        InsProduct finalInsProduct = insProductMapper.selectById(product.getId());
+                        InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId());
+                        this.addAuxiliary(userId, finalInsProduct, insOrder);
+                    });
+                } else {
+                    // 鍒ゆ柇鏄惁鏄病鏈夋楠屽�肩殑鍐呭
+                    if (saveInsContextDto.getIsNoTestValue() != null && saveInsContextDto.getIsNoTestValue() == 1) {
+                        threadPoolTaskExecutor.execute(() -> {
+                            InsProduct finalInsProduct = insProductMapper.selectById(product.getId());
+                            InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId());
+                            this.addAuxiliary(userId, finalInsProduct, insOrder);
+                        });
+                    }
+                }
 
             }
         });
         String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null);
         if (sampleIdStr != null) {
-            int count = insProductMapper.selectInsProductCountByOrderId(orderId);
+            int count = insProductMapper.selectInsProductCountByOrderId(saveInsContextDto.getOrderId());
             if (count == 0) {
                 insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate()
-                        .eq(InsOrderState::getInsOrderId, orderId)
-                        .eq(InsOrderState::getLaboratory, sonLaboratory)
+                        .eq(InsOrderState::getInsOrderId, saveInsContextDto.getOrderId())
+                        .eq(InsOrderState::getLaboratory, saveInsContextDto.getSonLaboratory())
                         .set(InsOrderState::getInsState, 2));
             }
         }
@@ -522,55 +535,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) {
@@ -597,20 +615,6 @@
      */
     private void getTemplateThing(InsOrder order, List<InsProduct> insProducts) {
         Set<Integer> set = new HashSet<>();
-        // 妫�楠岄」鍒嗙被+妫�楠岄」+妫�楠屽瓙椤圭殑鎷兼帴
-//        List<String> itemNameList = insProducts.stream().map(insProduct -> {
-//            String itemName = "";
-//            if (StringUtils.isNotBlank(insProduct.getInspectionItemClass())) {
-//                itemName += insProduct.getInspectionItemClass().trim();
-//            }
-//            if (StringUtils.isNotBlank(insProduct.getInspectionItem())) {
-//                itemName += insProduct.getInspectionItem().trim();
-//            }
-//            if (StringUtils.isNotBlank(insProduct.getInspectionItemSubclass())) {
-//                itemName += insProduct.getInspectionItemSubclass().trim();
-//            }
-//            return itemName;
-//        }).collect(Collectors.toList());
         // 鏌ヨ璁㈠崟鐘舵�佸垽鏂槸鍚︽槸鏌ュ巻鍙叉ā鏉�
         if (order.getIsFirstSubmit() != null && order.getIsFirstSubmit().equals(1)) {
             InsOrderState insOrderState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery()
@@ -669,7 +673,7 @@
     }
 
     /**
-     * todo: 娓呴櫎娌℃湁浣跨敤鐨勬楠岄」
+     * todo: 鍘熷璁板綍妯℃澘娓呴櫎娌℃湁浣跨敤鐨勬楠岄」(鏆傛椂鏈塨ug鏃犳硶浣跨敤)
      * @param sheet
      * @param itemNameList
      */
@@ -870,22 +874,8 @@
             this.addProductSpotCheck(insSamples, order);
         }
 
-        // 12.娣诲姞宸ユ椂
-//        // 鍒犻櫎鍘熸湰璁㈠崟宸ユ椂
-//        auxiliaryOutputWorkingHoursService.remove(Wrappers.<AuxiliaryOutputWorkingHours>lambdaQuery()
-//                .eq(AuxiliaryOutputWorkingHours::getOrderId, orderId));
-//        // 鏌ヨ宸ユ椂鏆傚瓨
-//        List<AuxiliaryOutputWorkingHoursTemporary> hoursTemporaries = auxiliaryOutputWorkingHoursTemporaryService.list(Wrappers.<AuxiliaryOutputWorkingHoursTemporary>lambdaQuery()
-//                .eq(AuxiliaryOutputWorkingHoursTemporary::getOrderId, orderId));
-//        List<AuxiliaryOutputWorkingHours> outputWorkingHours = hoursTemporaries.stream().map(hoursTemporary -> {
-//            AuxiliaryOutputWorkingHours workingHours = new AuxiliaryOutputWorkingHours();
-//            BeanUtil.copyProperties(hoursTemporary, workingHours);
-//            workingHours.setId(null);
-//            return workingHours;
-//        }).collect(Collectors.toList());
-//        auxiliaryOutputWorkingHoursService.saveBatch(outputWorkingHours);
 
-        // 13.娣诲姞璁㈠崟璐圭敤缁熻淇℃伅
+        // 12.娣诲姞璁㈠崟璐圭敤缁熻淇℃伅
         List<InsProduct> productList = insProductMapper.selectProductByOrderId(orderId);
         // 鍒犻櫎鍘熸湰璐圭敤淇℃伅
         insOrderRatesService.remove(Wrappers.<InsOrderRates>lambdaQuery()
@@ -908,7 +898,7 @@
         insOrderRatesService.saveBatch(orderRatesList);
 
 
-        // 14.鍙戦�佷紒涓氬井淇¢�氱煡
+        // 13.鍙戦�佷紒涓氬井淇¢�氱煡
         // 鏌ヨ鍘熸潗鏂�
         IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
         // 鏌ヨ鏍峰搧淇℃伅
@@ -917,7 +907,7 @@
                 .last("limit 1"));
         threadPoolTaskExecutor.execute(() -> {
             String message = "";
-            message += "妫�楠屼换鍔″鏍搁�氱煡";
+            message += "鑰愪笣绯荤粺妫�楠屼换鍔″鏍搁�氱煡";
             message += "\n鎻愪氦浜�: " + userName;
             message += "\n濮旀墭缂栧彿: " + order.getEntrustCode();
             message += "\n鏍峰搧鍚嶇О: " + insSample.getModel();
@@ -933,42 +923,19 @@
             }
         });
 
-        // 15.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴
+        // 14.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴
         if (ifsInventoryQuantity != null) {
             // 鐧昏妫�楠岀粨鏋�
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱
             // todo: ifs绉诲簱
             insReportService.isRawMaterial(order);
 
-            // 16 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10%
+            // 15 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10%
             // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭�
-//            threadPoolTaskExecutor.execute(() -> {
-//
-//                for (InsProduct insProduct : productList) {
-//                    // todo: 鏆傛椂鍒ゆ柇鏄惁鏄�佸寲
-//                    if (insProduct.getInspectionItem().contains("鑰佸寲")) {
-//                        List<InsProductAnalysisDto> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
-//
-//                        if (insProductAnalysisDtoList.size() < 10) {
-//                            continue;
-//                        }
-//
-//                        // 鍒ゆ柇褰撳墠妫�娴嬮」鏄惁鍋忓樊瓒呰繃10%
-//                        List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductAnalysisDto::getLastValue)
-//                                .collect(Collectors.toList());
-//
-//                        double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue());
-//                        // 鍒ゆ柇鍋忓樊鏄惁澶т簬10
-//                        if (deviation > 10) {
-//                            // 鍙戦�侀�氱煡, 骞朵笖娣诲姞鏁版嵁
-//
-//
-//
-//
-//                        }
-//                    }
-//                }
-//            });
+            threadPoolTaskExecutor.execute(() -> {
+                // 娣诲姞鍒嗘瀽鏁版嵁
+                addAnalysis(productList, ifsInventoryQuantity, order, sendUserAccount);
+            });
 
 
         } else {
@@ -990,6 +957,93 @@
     }
 
     /**
+     * *****娣诲姞鍒嗘瀽鏁版嵁******
+     * @param productList
+     * @param ifsInventoryQuantity
+     * @param order
+     */
+    private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String sendUserAccount) {
+        for (InsProduct insProduct : productList) {
+            // 鍒ゆ柇鏄惁鏄暟鍊肩被鍨�
+            if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) {
+                List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
+
+                if (insProductAnalysisDtoList.size() < 10) {
+                    continue;
+                }
+
+                // 鍒ゆ柇褰撳墠妫�娴嬮」鏄惁鍋忓樊瓒呰繃10%
+                List<String> laseValueList = insProductAnalysisDtoList.stream().map(InsProductDeviationWarningDetail::getTestValue)
+                        .collect(Collectors.toList());
+
+                double deviation = isDeviationOverTenPercent(laseValueList, insProduct.getLastValue());
+                // 鍒ゆ柇鍋忓樊鏄惁澶т簬10
+                if (deviation > 10) {
+                    // 鍒ゆ柇涔嬪墠鏄惁娣诲姞杩�, 娣诲姞杩囦笉闇�瑕佹坊鍔�
+                    long count = insProductDeviationWarningService.count(Wrappers.<InsProductDeviationWarning>lambdaQuery()
+                            .eq(InsProductDeviationWarning::getInsProductId, insProduct.getId()));
+                    if (count == 0L) {
+                        // 鍙戦�侀�氱煡, 骞朵笖娣诲姞鏁版嵁
+                        // 娣诲姞涓昏〃淇℃伅
+                        InsProductDeviationWarning deviationWarning = new InsProductDeviationWarning();
+                        deviationWarning.setInsOrderId(order.getId());
+                        deviationWarning.setInsSampleId(insProduct.getInsSampleId());
+                        deviationWarning.setInsProductId(insProduct.getId());
+                        deviationWarning.setEntrustCode(order.getEntrustCode());
+                        deviationWarning.setSampleCode(insProduct.getSampleCode());
+                        deviationWarning.setSupplierName(ifsInventoryQuantity.getSupplierName());
+                        deviationWarning.setDeviationValue(Double.toString(deviation));
+                        deviationWarning.setDetectionTime(insProduct.getUpdateTime());
+                        insProductDeviationWarningService.save(deviationWarning);
+
+                        // 娣诲姞璇︽儏鏁版嵁
+                        InsProductDeviationWarningDetail deviationWarningDetail = new InsProductDeviationWarningDetail();
+                        deviationWarningDetail.setInsOrderId(order.getId());
+                        deviationWarningDetail.setInsSampleId(insProduct.getInsSampleId());
+                        deviationWarningDetail.setInsProductId(insProduct.getId());
+                        deviationWarningDetail.setEntrustCode(order.getEntrustCode());
+                        deviationWarningDetail.setSampleCode(insProduct.getSampleCode());
+                        deviationWarningDetail.setSupplierName(ifsInventoryQuantity.getSupplierName());
+                        deviationWarningDetail.setTestValue(insProduct.getLastValue());
+                        deviationWarningDetail.setDetectionTime(insProduct.getCreateTime());
+                        deviationWarningDetail.setIsIssue(1);
+
+                        insProductAnalysisDtoList.add(deviationWarningDetail);
+
+                        // 娣诲姞id
+                        for (InsProductDeviationWarningDetail warningDetail : insProductAnalysisDtoList) {
+                            warningDetail.setDeviationWarningId(deviationWarning.getDeviationWarningId());
+                        }
+
+                        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(sendUserAccount, message, null);
+//
+//                            // todo: 鍙戦�佺粰妫�娴嬩腑蹇冧富浠�(鍥哄畾姝�)
+//                            WxCpUtils.inform("ZT-004704", message, null);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                            log.error("鍋忓樊棰勮浼佷笟寰俊閫氱煡鎶ラ敊");
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    /**
      * *****璁$畻鍋忓樊****
      * @param data
      * @param targetStr
@@ -1008,7 +1062,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);
     }
 
     /**
@@ -1111,7 +1168,7 @@
                 IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
 
                 String message = "";
-                message += "鎶ュ憡缂栧埗瀹℃壒閫氱煡";
+                message += "鑰愪笣绯荤粺鎶ュ憡缂栧埗瀹℃壒閫氱煡";
                 message += "\n妫�楠屼汉: " + userName;
                 message += "\n澶嶆牳浜�: " + chenkUserName;
                 message += "\n濮旀墭缂栧彿: " + order.getEntrustCode();
@@ -1153,7 +1210,7 @@
                 IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
 
                 String message = "";
-                message += "妫�楠屼换鍔″鏍搁��鍥為�氱煡";
+                message += "鑰愪笣绯荤粺妫�楠屼换鍔″鏍搁��鍥為�氱煡";
                 message += "\n澶嶆牳浜�: " + userName;
                 message += "\n濮旀墭缂栧彿: " + order.getEntrustCode();
                 message += "\n鏍峰搧鍚嶇О: " + insSample.getModel();
@@ -1246,36 +1303,13 @@
     }
 
     /**
-     * 鑾峰彇涓嶅悎鏍兼暟鎹�
-     * @return
-     */
-    @Override
-    public List<InsProduct> getInsProductUnqualified(InsOrderPlanProductDto dto) {
-        List<InsProduct> insProducts = new ArrayList<>();
-        switch (dto.getType()) {
-            case 0:
-                //鏍峰搧
-                insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), "1");
-                break;
-            case 4:
-                //鐢电紗閰嶇疆
-                insProducts = insSampleMapper.getInsProduct1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), "1");
-                break;
-            case 5:
-                //鍘熸潗鏂欎笅鍗�
-                insProducts = insSampleMapper.getInsProduct6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), "1");
-                break;
-        }
-        return insProducts;
-    }
-
-    /**
      * 鏂板涓嶅悎鏍煎娴嬪唴瀹�
-     * @param ids
      * @return
      */
     @Override
-    public boolean addDisqualificationRetest(List<Integer> ids) {
+    public boolean addDisqualificationRetest(List<InsProduct> insProductsList) {
+        List<Integer> ids = insProductsList.stream().map(InsProduct::getId).collect(Collectors.toList());
+
         // 鍒ゆ柇涔嬪墠鏄惁娣诲姞杩�
         Long count = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery()
                 .in(InsUnqualifiedRetestProduct::getInsProductId, ids));
@@ -1285,6 +1319,20 @@
 
         // 鏌ヨ涓嶅悎鏍煎唴瀹�
         List<InsUnqualifiedRetestProduct> list = insUnqualifiedRetestProductMapper.selectRetestProduct(ids);
+        // 寰幆鍒ゆ柇鏄惁鏄粦瀹氬��, 缁戝畾鍊间慨鏀规楠岃姹�
+        for (InsUnqualifiedRetestProduct insUnqualifiedRetestProduct : list) {
+            for (InsProduct insProduct : insProductsList) {
+                if (insProduct.getIsBinding().equals(1)) {
+                    insUnqualifiedRetestProduct.setIsBinding(1);
+                    insUnqualifiedRetestProduct.setAsk(null);
+                    insUnqualifiedRetestProduct.setTell(null);
+                    insUnqualifiedRetestProduct.setPrice(null);
+                    insUnqualifiedRetestProduct.setManHour(null);
+                    insUnqualifiedRetestProduct.setSection(null);
+                }
+            }
+        }
+
         // 鏂板涓嶅悎鏍煎唴瀹�
         insUnqualifiedRetestProductService.saveBatch(list);
         list.forEach(insUnqualifiedRetestProduct -> {
@@ -1296,38 +1344,29 @@
     }
 
     @Override
-    public List<InsProduct> getInsProductUnqualifiedRetest(Integer id, Integer type, String laboratory, String cableTag, String rawMaterialTag, String retestTag) {
+    public List<InsProduct> getInsProductUnqualifiedRetest(InsOrderPlanProductDto dto) {
 
         List<InsProduct> insProducts = new ArrayList<>();
-        switch (type) {
+        switch (dto.getType()) {
             case 0:
-                //鏍峰搧
-                insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest1(id, laboratory, retestTag);
-                break;
             case 4:
-                //鐢电紗閰嶇疆
-                insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest5(id, laboratory, cableTag, retestTag);
+                //濮旀墭
+                insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest1(dto.getId(), dto.getLaboratory(), dto.getCableTag(), dto.getRepetitionTag(), dto.getRetestTag());
                 break;
             case 5:
                 //鍘熸潗鏂欎笅鍗�
-                insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest6(id, laboratory, rawMaterialTag, retestTag);
+                insProducts = insUnqualifiedRetestProductMapper.getInsProductUnqualifiedRetest6(dto.getId(), dto.getLaboratory(), dto.getRawMaterialTag(), dto.getRetestTag());
                 break;
         }
         if (BeanUtil.isEmpty(insProducts)) {
             return null;
         }
-        InsOrder order = insOrderMapper.selectFirstSubmit(id);
+        InsOrder order = insOrderMapper.selectFirstSubmit(dto.getId());
         getTemplateThing(order, Collections.unmodifiableList(insProducts));
         return insProducts;
     }
 
 
-    /**
-     * 淇濆瓨涓嶅悎鏍煎娴嬫楠屽唴瀹�
-     * @param currentTable
-     * @param orderId
-     * @param sonLaboratory
-     */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void saveUnqualifiedContext(Map<String, Object> insContext, Integer currentTable, Integer currentSampleId, Integer orderId, String sonLaboratory) {
@@ -1345,13 +1384,12 @@
                     BeanUtil.copyProperties(oldResults.get(0), newResult);
                 }
                 newResult.setRetestProductId(Integer.parseInt(k));
-
+                /*鏍¢獙涓�涓媟esult琛�*/
                 if (oldResults.size() > 1) {
                     for (int i = 1; i < oldResults.size(); i++) {
                         insUnqualifiedRetestResultMapper.deleteById(oldResults.get(i));
                     }
                 }
-
                 //妫�楠屽��
                 if (jo.get("insValue") != null) {
                     JSONArray jsonArray = JSON.parseArray(JSON.toJSONString(jo.get("insValue")));
@@ -1382,6 +1420,8 @@
                     for (Object o : jsonArray2) {
                         JSONObject comValue = JSON.parseObject(JSON.toJSONString(o));
                         Map<String, Object> map = new HashMap<>();
+                        map.put("r", JSON.toJSONString(comValue.get("r")));
+                        map.put("c", JSON.toJSONString(comValue.get("c")));
                         map.put("v", JSON.parseObject(JSON.toJSONString(comValue.get("v"))).get("v"));
                         cv.add(map);
                     }
@@ -1444,41 +1484,18 @@
                 insProductUserMapper.insert(new InsProductUser(null, userId, LocalDateTime.now(), insProduct.getId()));
 
 
-                InsSample insSample = insSampleMapper.selectById(insProductMapper.selectById(insProduct.getId()).getInsSampleId());
-                insSample.setInsState(1);
-                Long l = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                        .eq(InsProduct::getInsSampleId, insSample.getId()));
-                Long l1 = insProductMapper.selectCount(Wrappers.<InsProduct>lambdaQuery()
-                        .eq(InsProduct::getInsSampleId, insSample.getId())
-                        .and(wrapper -> wrapper
-                                .isNotNull(InsProduct::getInsResult)
-                                .or()
-                                .ne(InsProduct::getInsResult, 2)
-                        ));
-                if (Objects.equals(l, l1)) {
-                    insSample.setInsState(2);
-                }
-                insSampleMapper.updateById(insSample);
                 /*鏍¢獙涓�涓媟esult琛�*/
                 List<InsUnqualifiedRetestResult> insProductResults = insUnqualifiedRetestResultMapper.selectList(Wrappers.<InsUnqualifiedRetestResult>lambdaQuery()
-                        .eq(InsUnqualifiedRetestResult::getRetestProductId, insProduct.getId()));
+                        .eq(InsUnqualifiedRetestResult::getRetestProductId, product.getId()));
                 if (insProductResults.size() > 1) {
                     for (int i = 1; i < insProductResults.size(); i++) {
                         insUnqualifiedRetestResultMapper.deleteById(insProductResults.get(i));
                     }
                 }
+
             }
         });
-        String sampleIdStr = insContext.keySet().stream().findFirst().orElse(null);
-        if (sampleIdStr != null) {
-            int count = insProductMapper.selectInsProductCountByOrderId(orderId);
-            if (count == 0) {
-                insOrderStateMapper.update(new InsOrderState(), Wrappers.<InsOrderState>lambdaUpdate()
-                        .eq(InsOrderState::getInsOrderId, orderId)
-                        .eq(InsOrderState::getLaboratory, sonLaboratory)
-                        .set(InsOrderState::getInsState, 2));
-            }
-        }
+
     }
 
     /**
@@ -1993,7 +2010,7 @@
             insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                     .eq(InsReport::getInsOrderId, insOrder.getId()));
             insReportMapper.insert(insReport);
-
+            inputStream.close();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -2134,7 +2151,6 @@
      * @param
      */
     private void addBitReport(Integer orderId, InsOrder insOrder) {
-        Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId());
         //samples鏄笉鍖呮嫭甯︽湁"/"鐨勬牱鍝�
         List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId);
         InsReport insReport = new InsReport();
@@ -2153,7 +2169,6 @@
         boolean isOneSample = samples.size() == 1 ? true : false;
         /*鍩虹鎶ュ憡(鏍规嵁缁樺埗鐨勫師濮嬭褰曟ā鐗堝舰鎴�)*/
         samples.forEach(a -> {
-            Map<Integer, String> map2 = new HashMap<>();
             models.add(a.getModel());
             String standardMethodCode = baseMapper.getStandardMethodCode(a.getStandardMethodListId());
             if (StrUtil.isNotBlank(a.getSpecialStandardMethod())) {
@@ -2548,6 +2563,7 @@
             insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                     .eq(InsReport::getInsOrderId, insOrder.getId()));
             insReportMapper.insert(insReport);
+            inputStream.close();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -4222,6 +4238,11 @@
 
         // 淇濆瓨鍒伴檮浠堕噷闈�
         uploadFile(insOrderId, multipartFile);
+        try {
+            inputStream.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
     }
 
@@ -4376,42 +4397,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