From 804c80b0fd284c7464066efbd5e5833ddacfb635 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 11 四月 2025 13:11:16 +0800
Subject: [PATCH] 原辅材下单优化

---
 basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java |  676 +++++++++++++++++++++++++++++++++----------------------
 1 files changed, 401 insertions(+), 275 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
index b50d427..7603c55 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -1,27 +1,23 @@
 package com.ruoyi.basic.service.impl;
 
 import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONArray;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.*;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.dto.*;
+import com.ruoyi.basic.enums.StandardProductListChcekTypeEnums;
+import com.ruoyi.basic.mapper.*;
+import com.ruoyi.basic.pojo.*;
+import com.ruoyi.basic.service.StandardMethodListService;
+import com.ruoyi.basic.service.StandardProductListSupplierAskService;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.basic.dto.CopyStandardProductListDto;
-import com.ruoyi.basic.dto.InsSampleReceiveDto;
-import com.ruoyi.basic.dto.ProductDto;
-import com.ruoyi.basic.dto.ResetTreeDragDTO;
-import com.ruoyi.basic.mapper.IfsInventoryQuantityMapper;
-import com.ruoyi.basic.mapper.StandardProductListMapper;
-import com.ruoyi.basic.mapper.StandardProductListSupplierAskMapper;
-import com.ruoyi.basic.mapper.StandardTreeMapper;
-import com.ruoyi.basic.pojo.StandardProductList;
-import com.ruoyi.basic.pojo.StandardProductListSupplierAsk;
-import com.ruoyi.basic.pojo.StandardTree;
 import com.ruoyi.basic.service.StandardProductListService;
-import com.ruoyi.basic.service.StandardProductListService2;
 import lombok.AllArgsConstructor;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -45,64 +41,84 @@
 
     private StandardTreeMapper standardTreeMapper;
 
-    private StandardProductListService2 standardProductListService2;
-
     private IfsInventoryQuantityMapper ifsInventoryQuantityMapper;
 
     private StandardProductListSupplierAskMapper standardProductListSupplierAskMapper;
 
+    private ProductPartMapper productPartMapper;
+
+    private StructureTestObjectPartMapper structureTestObjectPartMapper;
+
+    private StandardMethodListService standardMethodListService;
+
+    private StructureItemParameterMapper structureItemParameterMapper;
+
+    private ModelMapper modelMapper;
+
+    private StandardProductListBackupRelMapper standardProductListBackupRelMapper;
+
+    private StandardProductListUpdateRecordMapper standardProductListUpdateRecordMapper;
+
+    private StandardProductListUpdateRecordRelMapper standardProductListUpdateRecordRelMapper;
+
+    private StandardProductListSupplierAskService standardProductListSupplierAskService;
+
+    private StandardProductListSupplierAskBackupRelMapper standardProductListSupplierAskBackupRelMapper;
+
+    private StandardMethodMapper standardMethodMapper;
+
 
     @Override
     public int upStandardProductList(StandardProductList list) {
+        // 鏍规嵁id 鏌ヨ鍒板師濮嬪��
+        StandardProductList standardProductList = standardProductListMapper.selectById(list.getId());
+        if (ObjectUtils.isEmpty(standardProductList)) {
+            throw new RuntimeException("鏇存柊澶辫触,鏈煡鎵惧埌妫�鏌ラ」");
+        }
+        // 鍒ゆ柇褰撳墠鐘舵�� 濡傛灉鏄鏍镐腑
+        if (StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())) {
+            throw new RuntimeException("瀹℃牳涓笉鏀寔淇敼");
+        }
+        // 鍒ゆ柇妫�楠岄」鏄惁涓烘槸鍚﹀鎵樿姹� 鏄殑璇濅笉闇�瑕佸仛澶囦唤鍜岀姸鎬佷慨鏀圭洿鎺ユ洿鏂�
+        StructureItemParameter structureItemParameter = structureItemParameterMapper.selectById(standardProductList.getStructureItemParameterId());
+        if (!ObjectUtils.isEmpty(structureItemParameter) && "1".equals(structureItemParameter.getDelegateRequestFlag())) {
+            return standardProductListMapper.updateById(list);
+        }
+        // 鍒ゆ柇鏄惁涓虹敓鏁堢殑淇敼濡傛灉鏄笉鍋氬浠�
+        if (null != list.getState()) {
+            return standardProductListMapper.updateById(list);
+        }
+        // 鏌ヨ鏈�鏂扮殑涓�娆″叧鑱斿浠� 濡傛灉瀛樺湪璇存槑鏈鏍稿畬缁х画淇敼浜嗐�備笉鍋氭暟鎹鐞嗐��
+        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
+        if (ObjectUtils.isEmpty(standardProductListBackupRel)) {
+            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
+            BeanUtils.copyProperties(standardProductList, productListBackupRel);
+            standardProductListBackupRelMapper.insert(productListBackupRel);
+        }
+        // 鍏宠仈鍟嗗澶囦唤
+        StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
+        standardProductListSupplierAsk.setProductListId(list.getId());
+        standardProductListSupplierAskService.backupSupplierAsk(standardProductListSupplierAsk);
+        // 淇敼鐘舵��
+        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
         return standardProductListMapper.updateById(list);
     }
 
-    @Override
-    public int delStandardProduct(JSONArray list) {
-        return standardProductListMapper.deleteBatchIds(list);
-    }
 
     @Override
     public List<StandardProductList> selectStandardProductList(InsSampleReceiveDto insSample) {
-        // 鏄惁娌℃湁浜у搧
-        boolean isNoSample = false;
-//        String[] models = insSample.getModel().split("-(?=[^-]*$)");//鎷嗗垎鏈�鍚庝竴涓��-銆�
         String model = insSample.getModel();
         String modelNum = insSample.getModelNum();
-        List<StandardProductList> list = standardProductListMapper.selectDetail(insSample.getStandardMethodListId(), 1, model, insSample.getIsCableTag());
-        if (list.size() == 0) {
-            if (Objects.equals(insSample.getFactory(), "") || insSample.getFactory() == null) {
-                return null;
-            }
-            String[] split = insSample.getFactory().split(" - ");
-            split[3] = split[3].replace("- ", "");
-            String tree = split[0] + " - " + split[1] + " - " + split[2] + " - " + split[3] + " - null";
-            list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree, insSample.getIsCableTag());
-            if (list.size() == 0) {
-                String tree1 = split[0] + " - " + split[1] + " - " + split[2] + " - null - " + split[3];
-                list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree1, insSample.getIsCableTag());
-
-                // 鍙湁瀵硅薄鐨勪竴灞�
-                if (list.size() == 0) {
-                    String tree2 = split[0] + " - " + split[1] + " - " + split[2] + " - null - null";
-                    list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree2, insSample.getIsCableTag());
-                    // 鏍峰搧鐩存帴璧嬪�兼牱鍝佸垎绫�
-                    list.forEach(standardProductList -> standardProductList.setSample(standardProductList.getSampleType()));
-                    isNoSample = true;
-                }
-            }
+        // 鏌ヨ妫�鏌ラ」鐩�
+        StandardProductListDto standardProductListDto = new StandardProductListDto();
+        standardProductListDto.setTree(insSample.getFactory());
+        standardProductListDto.setStandardMethodListIds(insSample.getStandardMethodListIds());
+        standardProductListDto.setState(insSample.getState());
+        List<StandardProductList> list = new ArrayList<>();
+        if (CollectionUtils.isEmpty(standardProductListDto.getStandardMethodListIds())) {
+            return list;
         }
-        String[] split1 = insSample.getFactory().split(" - ");
-        if (!isNoSample) {
-            //鍒ゆ柇闀垮害
-            if (split1.length > 4) {
-                if (ObjectUtils.isNotEmpty(split1[3])) {
-                    list = list.stream().filter(list1 -> Objects.nonNull(list1.getSample()) && Objects.equals(list1.getSample(), split1[3])).collect(Collectors.toList());
-                } else if (split1[3].equals("")) {
-                    list = list.stream().filter(list1 -> Objects.nonNull(list1.getSampleType()) && Objects.equals(list1.getSampleType(), split1[2])).collect(Collectors.toList());
-                }
-            }
-        }
+        list = standardProductListMapper.standardProductListNoPage(standardProductListDto);
         list = list.stream().filter(a -> {
                     try {
                         if (a.getSection() != null && !Objects.equals(a.getSection(), "")) {
@@ -117,18 +133,54 @@
                                 if (Objects.equals(a.getBsm(), "1")) {
                                     return true;
                                 } else {
-                                    if (sections.get(i).contains("&")) {
-                                        String[] split = sections.get(i).split("&");
-                                        isIf = getIsIf(split[0], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample)
-                                                && getIsIf(split[1], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
-                                    } else {
-                                        isIf = getIsIf(sections.get(i), modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
+                                    int firstIndex = a.getTree().indexOf(" - ");
+                                    String result2 = null;
+                                    if (firstIndex != -1) {
+                                        int secondIndex = a.getTree().indexOf(" - ", firstIndex + 3);
+                                        if (secondIndex != -1) {
+                                            int thirdIndex = a.getTree().indexOf(" - ", secondIndex + 3);
+                                            if (thirdIndex != -1) {
+                                                result2 = a.getTree().substring(secondIndex + 3, thirdIndex);
+                                            }
+                                        }
                                     }
-                                    if (isIf) {
-                                        a.setSection(sections.get(i));
-                                        a.setAsk(asks.get(i));
-                                        a.setTell(tells.get(i));
-                                        return true;
+                                    // 鍒ゆ柇  鍘熻緟鏉�  鍖呮潗
+                                    Set<String> targetStrings = new HashSet<>();
+                                    targetStrings.add("鍘熻緟鏉�");
+                                    targetStrings.add("鍖呮潗");
+                                    boolean isType;
+                                    isType = targetStrings.contains(result2);
+                                    if (isType) {
+                                        if (StringUtils.isNotEmpty(modelNum)){
+                                            String currentSection = sections.get(i);
+                                            String sectionValue = currentSection;
+                                            int equalIndex = currentSection.indexOf("=");
+                                            if (equalIndex != -1) {
+                                                sectionValue = currentSection.substring(equalIndex + 1);
+                                            }
+                                            if (modelNum.equals(sectionValue)) {
+                                                a.setSection(sections.get(i));
+                                                a.setAsk(asks.get(i));
+                                                a.setTell(tells.get(i));
+                                                return true;
+                                            }
+                                        }else {
+                                            return false;
+                                        }
+                                    } else {
+                                        if (sections.get(i).contains("&")) {
+                                            String[] split = sections.get(i).split("&");
+                                            isIf = getIsIf(split[0], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample)
+                                                    && getIsIf(split[1], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
+                                        } else {
+                                            isIf = getIsIf(sections.get(i), modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
+                                        }
+                                        if (isIf) {
+                                            a.setSection(sections.get(i));
+                                            a.setAsk(asks.get(i));
+                                            a.setTell(tells.get(i));
+                                            return true;
+                                        }
                                     }
                                 }
                             }
@@ -139,7 +191,7 @@
                     }
                     return true;
                 }).peek(standardProductList -> {
-                    // todo: 鍒ゆ柇鏄惁鏄師鏉愪笅鍗�, 闇�瑕佸晩鎶婇鑹茬粦瀹氬埌璇曟牱棰滆壊鐨勮姹傚�间笂
+                    //鍒ゆ柇鏄惁鏄師鏉愪笅鍗�, 闇�瑕佸晩鎶婇鑹茬粦瀹氬埌璇曟牱棰滆壊鐨勮姹傚�间笂
                     if (StringUtils.isNotBlank(insSample.getPartNo())) {
                         // 鍒ゆ柇鏄惁鏈夎繖涓瓧娈典笖鏄枃鏈被鍨�
                         if (StringUtils.isNotBlank(standardProductList.getInspectionItem())
@@ -192,20 +244,38 @@
             }
         }
 
+        ProductPart productPart = productPartMapper.selectOne(new LambdaQueryWrapper<ProductPart>().eq(ProductPart::getPartNo, insSample.getPartNo()));
+        if (productPart != null) {
+            if (StringUtils.isNotEmpty(productPart.getInspectionItem())) {
+                String inspectionItem = productPart.getInspectionItem();
+                list = list.stream()
+                        .filter(standardProductList -> inspectionItem.contains(standardProductList.getInspectionItem()))
+                        .collect(Collectors.toList());
+            }
+        }
+
+        StructureTestObjectPart structureTestObjectPart = structureTestObjectPartMapper.selectOne(new LambdaQueryWrapper<StructureTestObjectPart>().eq(StructureTestObjectPart::getPartNo, insSample.getPartNo()));
+        if (structureTestObjectPart != null) {
+            if (StringUtils.isNotEmpty(structureTestObjectPart.getInspectionItem())) {
+                String inspectionItem = structureTestObjectPart.getInspectionItem();
+                list = list.stream()
+                        .filter(standardProductList -> inspectionItem.equals(standardProductList.getInspectionItem()))
+                        .collect(Collectors.toList());
+            }
+        }
         return list;
     }
 
     /**
-     *
-     * @param str                 鍒ゅ畾鍏紡
-     * @param model               鍨嬪彿
-     * @param standardCores       鑺暟
-     * @param conductorMaterial   瀵间綋鏉愯川
-     * @param conductorType       瀵间綋绫诲瀷
+     * @param str               鍒ゅ畾鍏紡
+     * @param model             鍨嬪彿
+     * @param standardCores     鑺暟
+     * @param conductorMaterial 瀵间綋鏉愯川
+     * @param conductorType     瀵间綋绫诲瀷
      * @param insSample
      * @return
      */
-    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType,InsSampleReceiveDto insSample) {
+    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType, InsSampleReceiveDto insSample) {
         Matcher matcher = Pattern.compile("\\d+(\\.\\d+)?").matcher(model);
         String model2 = "";
         while (matcher.find()) {
@@ -263,224 +333,144 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public Map<String, Object> selectStandardProductListByMethodId(Integer id, String tree, Integer page) {
+    public Map<String, Object> selectStandardProductListByMethodId(Integer id, String tree) {
+        String sampleType = "";
+        String sample = "";
+        String model = "";
+        StringBuilder checkItemQueryTree = new StringBuilder();   // 妫�鏌ラ」鏌ヨ 鍙嫾鎺� 妫�鏌ュ璞�-浜у搧
+
+        // 杩斿洖缁撴灉
+        Map<String, Object> map = new HashMap<>();
+        map.put("productList", null);
+        map.put("total", 0);
+
+        // 鍒ゆ柇鏄惁鍖呭惈杞﹂棿
+        boolean existWorkShopFlag = standardMethodListService.existWorkShop(tree);
+        // 鎷兼帴鏍�
         String[] trees = tree.split(" - ");
-        try {
-            String tree1 = trees[2];
-        } catch (Exception e) {
-            throw new BaseException("鎿嶄綔澶揩,绯荤粺浼犲弬閿欒!!!!");
+        if (trees == null && trees.length < 4) {
+            return map;
         }
-        boolean isDrag = false;
-        List<StandardProductList> list = new ArrayList<>();
-        if (trees.length == 3) {
-            List<StandardTree> treeList = new ArrayList<>();
-            StandardTree standardTree = new StandardTree();
-            standardTree.setFactory(trees[0]);
-            standardTree.setLaboratory(trees[1]);
-            standardTree.setSampleType(trees[2]);
-            List<ProductDto> pList = standardTreeMapper.selectPList(trees[2]);
-            if (pList.size() == 0 || pList.get(0) == null) {
-                List<StandardTree> treeList1 = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]));
-                if (treeList1.size() == 0) {
-                    treeList.add(standardTree);
-                } else {
-                    treeList.addAll(treeList1);
-                }
-            } else {
-                for (ProductDto p : pList) {
-                    standardTree.setSample(p.getName());
-                    List<StandardTree> treeList1 = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, p.getName()));
-                    if (treeList1.size() == 0) {
-                        treeList.add(JSON.parseObject(JSON.toJSONString(standardTree), StandardTree.class));
-                    } else {
-                        treeList.addAll(treeList1);
-                    }
-                }
-            }
-            for (StandardTree standardTree2 : treeList) {
-                String tree2 = trees[0] + " - " + trees[1] + " - " + trees[2] + " - " + standardTree2.getSample() + " - " + standardTree2.getModel();
-                list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1]));
-                list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + standardTree2.getSample() + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1]));
-            }
-        } else if (trees.length == 4) {
-            // 鍒ゆ柇绗洓灞傛槸鍚︽湁鍨嬪彿
-            Long count = standardProductListMapper.selectCount(Wrappers.<StandardProductList>lambdaQuery()
-                    .eq(StandardProductList::getStandardMethodListId, id)
-                    .isNull(StandardProductList::getModel)
-                    .like(StandardProductList::getTree, tree));
-            if (count == 0) {
-                isDrag = true;
-            }
-
-            isDrag = true;
-            List<StandardTree> treeList = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3]));
-            if (treeList.size() == 0) {
-                StandardTree standardTree = new StandardTree();
-                standardTree.setFactory(trees[0]);
-                standardTree.setLaboratory(trees[1]);
-                standardTree.setSampleType(trees[2]);
-                standardTree.setSample(trees[3]);
-                treeList.add(standardTree);
-            }
-            for (StandardTree standardTree : treeList) {
-                String str = tree + " - " + standardTree.getModel();
-                list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1]));
-                list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1]));
+        // 杞﹂棿灞傜骇澶氫竴灞傜骇
+        if (existWorkShopFlag) {
+            switch (trees.length) {
+                case 7:
+                    sampleType = trees[4];
+                    sample = trees[5];
+                    model = trees[6];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
+                    break;
+                case 6:
+                    sampleType = trees[4];
+                    sample = trees[5];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
+                    break;
+                case 5:
+                    sampleType = trees[4];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\"").append("]");
+                    break;
             }
         } else {
-            isDrag = true;
-            list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1]));
-            list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1]));
+            switch (trees.length) {
+                case 6:
+                    sampleType = trees[3];
+                    sample = trees[4];
+                    model = trees[5];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
+                    break;
+                case 5:
+                    sampleType = trees[3];
+                    sample = trees[4];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
+                    break;
+                case 4:
+                    sampleType = trees[3];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\"").append("]");
+                    break;
+            }
         }
-        for (StandardProductList productList : list) {
-            productList.setId(IdWorker.getId());
+        if (StringUtils.isEmpty(checkItemQueryTree.toString())) {
+            return map;
         }
-        List<StandardProductList> standardProductLists;
-
-        if (isDrag) {
-            standardProductLists = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
-                    .eq(StandardProductList::getStandardMethodListId, id)
-                    .like(StandardProductList::getTree, tree)
-                    .orderByAsc(StandardProductList::getSort));
-            // 鍒ゆ柇鏄惁鏈夋病鏈夊簭鍙风殑, 娌℃湁搴忓彿閲嶇疆
-            boolean b = standardProductLists.stream().anyMatch(standardProductList -> standardProductList.getSort() == null);
+        // 鍒ゆ柇鏄惁涓哄鎵樿姹傛爣鍑�
+        StandardMethod standardMethod = standardMethodMapper.selectById(id);
+        if (ObjectUtils.isEmpty(standardMethod)) {
+            return map;
+        }
+        StructureItemParameterDto structureItemParameterDto = new StructureItemParameterDto();
+        if (standardMethod.getName().equals("濮旀墭瑕佹眰")) {
+            structureItemParameterDto.setDelegateRequestFlag("1");
         } else {
-            standardProductLists = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
-                    .eq(StandardProductList::getStandardMethodListId, id)
-                    .like(StandardProductList::getTree, tree));
+            structureItemParameterDto.setDelegateRequestFlag("0");
         }
+        structureItemParameterDto.setTree(checkItemQueryTree.toString());
 
-        for (StandardProductList sp : standardProductLists) {
-            for (StandardProductList pl : list) {
-                // 鍒ゆ柇鏉′欢鏄惁鍙湁涓�涓�, 鏈変竴涓殑璇濋粯璁ょ涓�涓�
-                String radiusList = pl.getRadiusList();
-                if (StringUtils.isNotBlank(radiusList) && !radiusList.equals("null") && !radiusList.equals("\"\"")) {
-                    JSONArray jsonArray = JSON.parseArray(radiusList);
-                    List<String> radius = jsonArray.toJavaList(String.class);
-                    if (CollectionUtils.isNotEmpty(radius) && radius.size() == 1) {
-                        pl.setRadius(radius.get(0));
-                    }
-                }
-                if (Objects.equals(sp.getInspectionItem(), pl.getInspectionItem())
-                        && Objects.equals((sp.getInspectionItemSubclass() == null) ? "" : sp.getInspectionItemSubclass(), pl.getInspectionItemSubclass() == null ? "" : pl.getInspectionItemSubclass())
-//                        && Objects.equals(sp.getSample(), pl.getSample())
-                        && Objects.equals(sp.getModel(), pl.getModel())
-                        && sp.getTree().indexOf(pl.getSample() == null ? "null" : pl.getSample()) > -1
-                        && Objects.equals(sp.getStructureItemParameterId(), pl.getStructureItemParameterId())) {
-                    pl.setId(sp.getId());
-                    // 娣诲姞鎺掑簭瀛楁
-                    pl.setSort(sp.getSort());
-                    if (sp.getState() != null && !sp.getState().equals("")) {
-                        pl.setState(sp.getState());
-                    } else {
-                        pl.setState(id == 0 ? 1 : 0);
-                    }
-                    if (sp.getMethodS() != null && !sp.getMethodS().equals("")) {
-                        pl.setMethod(sp.getMethodS());
-                    }
-                    if (sp.getRadius() != null && !sp.getRadius().equals("")) {
-                        pl.setRadius(sp.getRadius());
-                    }
-                    if (sp.getRates() != null && !sp.getRates().equals("")) {
-                        pl.setRates(sp.getRates());
-                    }
-                    if (sp.getAsk() != null && !sp.getAsk().equals("")) {
-                        pl.setAsk(sp.getAsk());
-                    }
-                    if (sp.getTell() != null && !sp.getTell().equals("")) {
-                        pl.setTell(sp.getTell());
-                    }
-                    if (sp.getPrice() != null && !sp.getPrice().equals("")) {
-                        pl.setPrice(sp.getPrice());
-                    }
-                    if (sp.getManHour() != null && !sp.getManHour().equals("")) {
-                        pl.setManHour(sp.getManHour());
-                    }
-                    if (sp.getSection() != null && !sp.getSection().equals("")) {
-                        pl.setSection(sp.getSection());
-                    }
-                    if (sp.getCores() != null && !sp.getCores().equals("")) {
-                        pl.setCores(sp.getCores());
-                    }
-                    if (sp.getConductorMaterial() != null && !sp.getConductorMaterial().equals("")) {
-                        pl.setConductorMaterial(sp.getConductorMaterial());
-                    }
-                    if (sp.getConductorType() != null && !sp.getConductorType().equals("")) {
-                        pl.setConductorType(sp.getConductorType());
-                    }
-                    if (sp.getTemplateId() != null && !sp.getTemplateId().equals("")) {
-                        pl.setTemplateId(sp.getTemplateId());
-                    }
-                    //鍥犱负杩樻湁涓骇鍝佸彨鑰愬紶绾垮す 鎺ョ画閲戝叿 ,杩欎袱涓」鐩殑鏁版嵁瀹屽叏涓�鏍�,鐗规畩澶勭悊
-                    if (sp.getTree() != null && !sp.getTree().equals("") && !pl.getTree().equals("涓ぉ绉戞妧妫�娴嬩腑蹇� - 鐢靛姏浜у搧瀹為獙瀹� - 閲戝叿 - 鑰愬紶绾垮す - null")) {
-                        pl.setTree(sp.getTree());
-                    }
+        // 鏍规嵁妫�楠屽璞�/浜у搧鏌ヨ妫�楠岄」
+        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
+        // 濡傛灉鏄骇鍝佺殑妫�鏌ラ」涓虹┖鍚戜笂鎺�
+        if (CollectionUtils.isEmpty(structureItemParameterList)) {
+            String query = "[\"" + sampleType + "\"]";
+            structureItemParameterDto.setTree(query);
+            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
+        }
+        // 鏌ヨ鏍囧噯搴撳凡缁戝畾妫�鏌ラ」鐩�
+        List<StandardProductList> standardProductList = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
+                .eq(StandardProductList::getStandardMethodListId, id)
+                .like(StandardProductList::getTree, tree)
+                .orderByAsc(StandardProductList::getSort));
+
+        // 灏佽鍙傛暟
+        List<StandardProductList> batchInsertStandardProductListArray = new ArrayList<>();
+        for (StructureItemParameter structureItemParameter : structureItemParameterList) {
+            StandardProductList addStandProductList = new StandardProductList();
+            boolean existFlag = false;
+            // 鍒ゆ柇鏄惁宸茬粦瀹�
+            for (StandardProductList productList : standardProductList) {
+                if (structureItemParameter.getId().equals(productList.getStructureItemParameterId())) {
+                    BeanUtils.copyProperties(productList, addStandProductList);
+                    existFlag = true;
                     break;
                 }
             }
-        }
-        if (page == 1) {
-            Integer userId = SecurityUtils.getUserId().intValue();
-//            CompletableFuture.supplyAsync(() -> {
-            if (trees.length == 5) {
-                standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
-                        .eq(StandardProductList::getStandardMethodListId, id)
-                        .eq(StandardProductList::getTree, tree));
-            } else {
-                standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
-                        .eq(StandardProductList::getStandardMethodListId, id)
-                        .like(StandardProductList::getTree, tree));
+            // 濡傛灉鏈粦瀹�
+            if (!existFlag) {
+                BeanUtils.copyProperties(structureItemParameter, addStandProductList);
+                addStandProductList.setTell(structureItemParameter.getAskTell());
+                addStandProductList.setStructureItemParameterId(structureItemParameter.getId());
+                addStandProductList.setManHour(Objects.toString(structureItemParameter.getManHour(), ""));
             }
-
-            try {
-                standardProductListService2.saveBatch(list.stream().map(a -> {
-                    a.setFactory(trees[0]);
-                    a.setLaboratory(trees[1]);
-                    a.setSampleType(trees[2]);
-                    a.setCreateUser(userId);
-                    a.setUpdateUser(userId);
-                    a.setStandardMethodListId(id);
-                    return a;
-                }).collect(Collectors.toList()));
-            } catch (Exception e) {
-                // 澶勭悊閲嶅 ID 鐨勮褰曪紝閲嶆柊鐢熸垚 ID 骞剁户缁皾璇曟彃鍏�
-                for (StandardProductList productList : list) {
-                    productList.setId(IdWorker.getId());
-                }
-            }
+            addStandProductList.setId(addStandProductList.getId() != null ? addStandProductList.getId() : IdWorker.getId());
+            batchInsertStandardProductListArray.add(addStandProductList);
 
         }
-        Map<String, Object> map = new HashMap<>();
-        Collections.sort(list, (o1, o2) -> {
-            String field1 = o1.getManHourGroup();
-            String field2 = o2.getManHourGroup();
+        // 鎺掑簭澶勭悊 宸叉湁椤哄簭鎸夌収鍘熼『搴� 娌℃湁椤哄簭鐨勬寜鐓ф楠岄」鐨刬d鍗囧簭锛岄粯璁ゆ帓鍦ㄦ渶鍚�
+        batchInsertStandardProductListArray.sort(Comparator.comparing((StandardProductList item) -> item.getSort() != null ? item.getSort() : Integer.MAX_VALUE)
+                .thenComparing(StandardProductList::getStructureItemParameterId));
 
-            boolean isEmpty1 = field1 == null || field1.isEmpty();
-            boolean isEmpty2 = field2 == null || field2.isEmpty();
+        // 鍒犻櫎鍘熺粦瀹氭暟鎹�
+        standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
+                .eq(StandardProductList::getStandardMethodListId, id)
+                .eq(StandardProductList::getTree, tree));
 
-            if (isEmpty1 && isEmpty2) {
-                return 0;
-            } else if (isEmpty1) {
-                return 1;
-            } else if (isEmpty2) {
-                return -1;
-            } else {
-                int num1 = extractNumber(field1);
-                int num2 = extractNumber(field2);
-                return Integer.compare(num1, num2);
-            }
-        });
-          // 鎸夌収绱㈠紩鎺掑簭
-        if (isDrag) {
-            list.sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
-                    - (o2.getSort() == null ? 0 : o2.getSort()));
+        for (int i = 0; i < batchInsertStandardProductListArray.size(); i++) {
+            StandardProductList productList = batchInsertStandardProductListArray.get(i);
+            productList.setTree(tree);
+            productList.setFactory(trees[0]);
+            productList.setLaboratory(trees[1]);
+            productList.setSampleType(sampleType);
+            productList.setSample(sample);
+            productList.setModel(model);
+            productList.setCreateUser(SecurityUtils.getUserId().intValue());
+            productList.setUpdateUser(SecurityUtils.getUserId().intValue());
+            productList.setStandardMethodListId(id);
+            productList.setSort(i);
         }
-        try {
-            map.put("productList", list.subList((page - 1) * 300, page * 300));
-        } catch (IndexOutOfBoundsException e) {
-            map.put("productList", list.subList((page - 1) * 300, list.size()));
+        // 鎵归噺娣诲姞鏍囧噯
+        if (CollectionUtils.isNotEmpty(batchInsertStandardProductListArray)) {
+            baseMapper.saveBatchProductLists(batchInsertStandardProductListArray);
         }
-        map.put("total", list.size());
+        map.put("productList", batchInsertStandardProductListArray);
+        map.put("total", batchInsertStandardProductListArray.size());
         return map;
     }
 
@@ -528,11 +518,34 @@
 
     /**
      * 淇敼鏍囧噯搴撳尯闂�
+     *
      * @param list
      * @return
      */
     @Override
     public boolean updateSection(StandardProductList list) {
+        // 鏍规嵁id 鏌ヨ鍒板師濮嬪��
+        StandardProductList standardProductList = standardProductListMapper.selectById(list.getId());
+        if (ObjectUtils.isEmpty(standardProductList)) {
+            throw new RuntimeException("鏇存柊澶辫触,鏈煡鎵惧埌妫�鏌ラ」");
+        }
+        // 鍒ゆ柇褰撳墠鐘舵�� 濡傛灉鏄鏍镐腑
+        if (StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())) {
+            throw new RuntimeException("瀹℃牳涓笉鏀寔淇敼");
+        }
+        // 鏌ヨ鏈�鏂扮殑涓�娆″叧鑱斿浠� 濡傛灉瀛樺湪璇存槑鏈鏍稿畬缁х画淇敼浜嗐�備笉鍋氭暟鎹鐞嗐��
+        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
+        if (ObjectUtils.isEmpty(standardProductListBackupRel)) {
+            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
+            BeanUtils.copyProperties(standardProductList, productListBackupRel);
+            standardProductListBackupRelMapper.insert(productListBackupRel);
+        }
+        // 鍏宠仈鍟嗗澶囦唤
+        StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
+        standardProductListSupplierAsk.setProductListId(list.getId());
+        standardProductListSupplierAskService.backupSupplierAsk(standardProductListSupplierAsk);
+        // 淇敼鐘舵��
+        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
         standardProductListMapper.updateSection(list);
         return true;
     }
@@ -540,6 +553,7 @@
 
     /**
      * 鏍囧噯搴撴嫋鎷�
+     *
      * @param resetTreeDragDTO
      */
     @Override
@@ -558,7 +572,7 @@
                     resetTreeDragDTO.getTree());
 
             // 浠庝笅寰�涓�
-        } else if (beginIndex > endIndex){
+        } else if (beginIndex > endIndex) {
             standardProductListMapper.updateSortDown(beginIndex,
                     endIndex,
                     methodId,
@@ -574,11 +588,12 @@
 
     @Override
     public void resetTreeDragBatch(List<StandardProductList> standardProductLists) {
-        standardProductListService2.updateBatchById(standardProductLists);
+        this.updateBatchById(standardProductLists);
     }
 
     /**
      * 妫�楠岄」瑕佹眰鍊煎姣�
+     *
      * @param copyDto
      * @return
      */
@@ -622,6 +637,7 @@
 
     /**
      * 妫�楠岄」澶嶅埗瀵规瘮涓�涓�
+     *
      * @param dto
      * @return
      */
@@ -656,6 +672,7 @@
 
     /**
      * 妫�楠岄」澶嶅埗鎺掑簭
+     *
      * @param copyDto
      * @return
      */
@@ -685,6 +702,115 @@
         this.updateBatchById(productLists);
         return false;
     }
+
+    /**
+     * 鏍囧噯鏍戜笅妫�楠岄」鎻愪氦
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void productListSubmit(StandardProductListUpdateRecord standardProductListUpdateRecord) {
+        // 鏌ヨ鎵�鏈夊緟瀹℃牳鐨勬暟鎹�
+        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
+        List<StandardProductList> unCheckStandardProductListArray = standardProductListMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(unCheckStandardProductListArray)) {
+            throw new RuntimeException("鏆傛棤淇敼鏁版嵁");
+        }
+        List<Long> standardProductListIds = new ArrayList<>();
+        // 鎻掑叆淇敼璁板綍
+        standardProductListUpdateRecordMapper.insert(standardProductListUpdateRecord);
+        // 鎻掑叆淇敼璁板綍鍏宠仈琛�
+        List<StandardProductListUpdateRecordRel> standardProductListUpdateRecordRelList = new ArrayList<>();
+        for (StandardProductList standardProductList : unCheckStandardProductListArray) {
+            StandardProductListUpdateRecordRel standardProductListUpdateRecordRel = new StandardProductListUpdateRecordRel();
+            BeanUtils.copyProperties(standardProductList, standardProductListUpdateRecordRel);
+            standardProductListUpdateRecordRel.setId(null);
+            standardProductListUpdateRecordRel.setStandardProductListId(standardProductList.getId());
+            standardProductListUpdateRecordRel.setStandardProductListUpdateRecordId(standardProductListUpdateRecord.getId());
+            standardProductListUpdateRecordRelList.add(standardProductListUpdateRecordRel);
+            standardProductListUpdateRecordRelMapper.insert(standardProductListUpdateRecordRel);
+            standardProductListIds.add(standardProductList.getId());
+        }
+
+        // 淇敼鏍囧噯鏍戜笅妫�鏌ラ」鐘舵�佷负瀹℃牳涓�
+        standardProductListMapper.updateProductListCheckStatus(standardProductListIds, StandardProductListChcekTypeEnums.CHECK_ING.getCode());
+    }
+
+    /**
+     * 鏍囧噯鏍戜笅妫�楠岄」瀹℃牳
+     *
+     * @param standardProductListUpdateRecord
+     */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void productListCheck(StandardProductListUpdateRecord standardProductListUpdateRecord) {
+        // 鏌ヨ鎵�鏈夊鏍镐腑鐨勬暟鎹�
+        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.CHECK_ING.getCode());
+        List<StandardProductList> standardProductListArray = standardProductListMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(standardProductListArray)) {
+            return;
+        }
+        List<Long> standardProductListIds = new ArrayList<>();
+        for (StandardProductList standardProductList : standardProductListArray) {
+            standardProductListIds.add(standardProductList.getId());
+        }
+        // 瀹℃牳閫氳繃
+        if (StandardProductListChcekTypeEnums.PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())) {
+            // 淇敼鐘舵��
+            standardProductListMapper.updateProductListCheckStatus(standardProductListIds, StandardProductListChcekTypeEnums.PASS_CHECK.getCode());
+        }
+        // 瀹℃牳鏈�氳繃
+        if (StandardProductListChcekTypeEnums.NO_PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())) {
+            // 鏌ヨ鎵�鏈夋爣鍑嗘爲涓嬬殑妫�楠岄」鐩浠芥暟鎹�
+            List<StandardProductListBackupRel> standardProductListBackupRelList = standardProductListBackupRelMapper.selectBatchIds(standardProductListIds);
+            // 鍥炴粴鏍囧噯鏍戜笅鐨勬楠岄」鐩暟鎹�
+            for (StandardProductListBackupRel standardProductListBackupRel : standardProductListBackupRelList) {
+                StandardProductList standardProductList = new StandardProductList();
+                BeanUtils.copyProperties(standardProductListBackupRel, standardProductList);
+                standardProductListMapper.updateById(standardProductList);
+            }
+            // 鍥炴粴妫�楠岄」鐩巶瀹跺瘑搴︾粦瀹氳〃鏁版嵁
+            QueryWrapper<StandardProductListSupplierAskBackupRel> supplierAskBackupRelQueryWrapper = new QueryWrapper<>();
+            supplierAskBackupRelQueryWrapper.in("product_list_id", standardProductListIds);
+            List<StandardProductListSupplierAskBackupRel> standardProductListSupplierAskBackupRelList = standardProductListSupplierAskBackupRelMapper.selectList(supplierAskBackupRelQueryWrapper);
+            if (!CollectionUtils.isEmpty(standardProductListSupplierAskBackupRelList)) {
+                QueryWrapper<StandardProductListSupplierAsk> deleteWrapper = new QueryWrapper<>();
+                deleteWrapper.in("product_list_id", standardProductListIds);
+                standardProductListSupplierAskMapper.delete(deleteWrapper);
+                ArrayList<StandardProductListSupplierAsk> supplierAskRollBackList = new ArrayList<>();
+                for (StandardProductListSupplierAskBackupRel standardProductListSupplierAskBackupRel : standardProductListSupplierAskBackupRelList) {
+                    StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
+                    BeanUtils.copyProperties(standardProductListSupplierAskBackupRel, standardProductListSupplierAsk);
+                    supplierAskRollBackList.add(standardProductListSupplierAsk);
+                }
+                standardProductListSupplierAskMapper.batchInsertSupplierAsk(supplierAskRollBackList);
+            }
+
+        }
+        // 鍒犻櫎鏍囧噯鏍戜笅鐨勬楠岄」鐩浠芥暟鎹�
+        standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
+        // 鍒犻櫎缁戝畾鍘傚澶囦唤鏁版嵁
+        standardProductListSupplierAskBackupRelMapper.batchDeleteByProductIds(standardProductListIds);
+        standardProductListUpdateRecordMapper.updateById(standardProductListUpdateRecord);
+    }
+
+    /**
+     * 鏌ヨ鏍囧噯搴撴槸鍚﹀瓨鍦ㄥ鏍镐腑鐘舵��
+     *
+     * @return
+     */
+    @Override
+    public boolean existCheckingRecord() {
+        QueryWrapper<StandardProductListUpdateRecord> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.CHECK_ING.getCode());
+        List<StandardProductListUpdateRecord> standardProductListUpdateRecordList = standardProductListUpdateRecordMapper.selectList(queryWrapper);
+        if (CollectionUtils.isEmpty(standardProductListUpdateRecordList)) {
+            return false;
+        } else {
+            return true;
+        }
+    }
 }
 
 

--
Gitblit v1.9.3