From 50164d95bfe34f532e3f2513a53f62c0864fe1a2 Mon Sep 17 00:00:00 2001
From: zhuo <2089219845@qq.com>
Date: 星期三, 07 五月 2025 18:11:31 +0800
Subject: [PATCH] 关闭流

---
 inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java |  167 +++++++++++++++++++------------------------------------
 1 files changed, 58 insertions(+), 109 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 b8bb4a0..b8dd63e 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
@@ -258,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)) {
@@ -502,13 +499,15 @@
                     }
                 }
 
-                //鏌ヨ妫�楠屽崟淇℃伅
                 // 娣诲姞宸ユ椂
-                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("[]")) {
+                    InsProduct finalInsProduct = insProductMapper.selectById(product.getId());
+                    threadPoolTaskExecutor.execute(() -> {
+                        InsOrder insOrder = insOrderMapper.selectById(insSample.getInsOrderId());
+                        this.addAuxiliary(userId, finalInsProduct, insOrder);
+                    });
+                }
 
             }
         });
@@ -879,22 +878,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()
@@ -917,7 +902,7 @@
         insOrderRatesService.saveBatch(orderRatesList);
 
 
-        // 14.鍙戦�佷紒涓氬井淇¢�氱煡
+        // 13.鍙戦�佷紒涓氬井淇¢�氱煡
         // 鏌ヨ鍘熸潗鏂�
         IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(order.getIfsInventoryId());
         // 鏌ヨ鏍峰搧淇℃伅
@@ -942,18 +927,18 @@
             }
         });
 
-        // 15.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴
+        // 14.ifs绉诲簱(鍘熸潗鏂欓渶瑕佽繘琛岀Щ搴撴搷浣�) --> 鏈�鍚庢墽琛�,鍥犱负澶辫触鏃犳硶鍥炴粴
         if (ifsInventoryQuantity != null) {
             // 鐧昏妫�楠岀粨鏋�
             // 鍒ゆ柇鏄惁鏈変笉鍚堟牸, 鏈変笉鍚堟牸涓嶈兘绉诲簱
             // todo: ifs绉诲簱
             insReportService.isRawMaterial(order);
 
-            // 16 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10%
+            // 15 鍒ゆ柇褰撳墠鏍峰搧鏄惁涓哄師鏉愭枡, 鍘熸潗鏂欓渶瑕佽繘琛屾暟鎹垎鏋�, 鍒ゆ柇涔嬪墠10鏉℃暟鎹悓涓�涓緵搴斿晢, 鍚屼竴涓楠岄」鐨勫亸宸槸鍚﹁秴杩�10%
             // 鏌ヨifs淇℃伅鑾峰彇鑾峰彇鍓�10涓緵搴斿晢涓�鏍风殑, 妫�楠岄」涓�鏍蜂俊鎭�
             threadPoolTaskExecutor.execute(() -> {
                 // 娣诲姞鍒嗘瀽鏁版嵁
-                addAnalysis(productList, ifsInventoryQuantity, order, userName);
+                addAnalysis(productList, ifsInventoryQuantity, order, sendUserAccount);
             });
 
 
@@ -981,13 +966,13 @@
      * @param ifsInventoryQuantity
      * @param order
      */
-    private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String userName) {
+    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() < 5) {
+                if (insProductAnalysisDtoList.size() < 10) {
                     continue;
                 }
 
@@ -1048,10 +1033,10 @@
                             message += "\n妫�楠岄」: " + insProduct.getInspectionItem() + insProduct.getInspectionItemSubclass();
                             message += "\n鍋忓樊瓒呰繃浜� 10%";
                             // 鍙戦�佺粰鎻愪氦浜�
-                            WxCpUtils.inform(userName, message, null);
-
-                            // todo: 鍙戦�佺粰妫�娴嬩腑蹇冧富浠�(鍥哄畾姝�)
-                            WxCpUtils.inform("ZT-004704", message, null);
+//                            WxCpUtils.inform(sendUserAccount, message, null);
+//
+//                            // todo: 鍙戦�佺粰妫�娴嬩腑蹇冧富浠�(鍥哄畾姝�)
+//                            WxCpUtils.inform("ZT-004704", message, null);
                         } catch (Exception e) {
                             e.printStackTrace();
                             log.error("鍋忓樊棰勮浼佷笟寰俊閫氱煡鎶ラ敊");
@@ -1322,36 +1307,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));
@@ -1361,6 +1323,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 -> {
@@ -1372,38 +1348,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) {
@@ -1421,13 +1388,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")));
@@ -1458,6 +1424,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);
                     }
@@ -1520,41 +1488,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));
-            }
-        }
+
     }
 
     /**
@@ -2069,7 +2014,7 @@
             insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                     .eq(InsReport::getInsOrderId, insOrder.getId()));
             insReportMapper.insert(insReport);
-
+            inputStream.close();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -2210,7 +2155,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();
@@ -2229,7 +2173,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())) {
@@ -2624,6 +2567,7 @@
             insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                     .eq(InsReport::getInsOrderId, insOrder.getId()));
             insReportMapper.insert(insReport);
+            inputStream.close();
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
@@ -4298,6 +4242,11 @@
 
         // 淇濆瓨鍒伴檮浠堕噷闈�
         uploadFile(insOrderId, multipartFile);
+        try {
+            inputStream.close();
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
     }
 

--
Gitblit v1.9.3