From e4774c6ff705d93fcf3694e244a18dad7f0bec77 Mon Sep 17 00:00:00 2001
From: chenrui <1187576398@qq.com>
Date: 星期三, 02 四月 2025 09:31:18 +0800
Subject: [PATCH] 标准库功能修改备份开发

---
 basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java |  147 +++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 125 insertions(+), 22 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 e0a265f..5a53933 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,25 +1,22 @@
 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.StandardMethodService;
 import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.QueryWrappers;
 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.service.StandardProductListService;
 import lombok.AllArgsConstructor;
-import org.apache.catalina.security.SecurityUtil;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -59,9 +56,39 @@
     @Autowired
     private StructureItemParameterMapper structureItemParameterMapper;
 
+    @Autowired
+    private ModelMapper modelMapper;
+
+    @Autowired
+    private StandardProductListBackupRelMapper standardProductListBackupRelMapper;
+
+    @Autowired
+    private StandardProductListUpdateRecordMapper standardProductListUpdateRecordMapper;
+
+    @Autowired
+    private StandardProductListUpdateRecordRelMapper standardProductListUpdateRecordRelMapper;
+
 
     @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("瀹℃牳涓笉鏀寔淇敼");
+        }
+        // 鏌ヨ鏈�鏂扮殑涓�娆″叧鑱斿浠� 濡傛灉瀛樺湪璇存槑鏈鏍稿畬缁х画淇敼浜嗐�備笉鍋氭暟鎹鐞嗐��
+        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
+        if(ObjectUtils.isEmpty(standardProductListBackupRel)){
+            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
+            BeanUtils.copyProperties(standardProductList, productListBackupRel);
+            standardProductListBackupRelMapper.insert(productListBackupRel);
+        }
+        // 淇敼鐘舵��
+        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
         return standardProductListMapper.updateById(list);
     }
 
@@ -290,6 +317,7 @@
         String sampleType = "";
         String sample = "";
         String model = "";
+        StringBuilder checkItemQueryTree = new StringBuilder();   // 妫�鏌ラ」鏌ヨ 鍙嫾鎺� 妫�鏌ュ璞�-浜у搧
 
         // 杩斿洖缁撴灉
         Map<String, Object> map = new HashMap<>();
@@ -303,57 +331,60 @@
         if(trees == null && trees.length < 4){
             return map;
         }
-        StringBuilder queryTreeBuilder = new StringBuilder();
         // 杞﹂棿灞傜骇澶氫竴灞傜骇
         if(existWorkShopFlag){
             switch (trees.length) {
                 case 7:
-                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\",\"").append(trees[6]).append("\"").append("]");
                     sampleType = trees[4];
                     sample = trees[5];
                     model = trees[6];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                     break;
                 case 6:
-                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                     sampleType = trees[4];
                     sample = trees[5];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                     break;
                 case 5:
-                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\"").append("]");
                     sampleType = trees[4];
+                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\"").append("]");
                     break;
             }
         }else {
             switch (trees.length) {
                 case 6:
-                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                     sampleType = trees[3];
                     sample = trees[4];
                     model = trees[5];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                     break;
                 case 5:
-                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                     sampleType = trees[3];
                     sample = trees[4];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                     break;
                 case 4:
-                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\"").append("]");
                     sampleType = trees[3];
+                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\"").append("]");
                     break;
             }
         }
-        if(StringUtils.isEmpty(queryTreeBuilder.toString())){
+        if(StringUtils.isEmpty(checkItemQueryTree.toString())){
             return map;
         }
-        // 鏍规嵁妫�楠屽璞�/浜у搧/鍨嬪彿鏌ヨ妫�楠岄」
-        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(queryTreeBuilder.toString());
+        // 鏍规嵁妫�楠屽璞�/浜у搧鏌ヨ妫�楠岄」
+        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(checkItemQueryTree.toString());
+        // 濡傛灉鏄骇鍝佺殑妫�鏌ラ」涓虹┖鍚戜笂鎺�
+        if(CollectionUtils.isEmpty(structureItemParameterList)){
+            String query = "[\"" + sampleType + "\"]";
+            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(query);
+        }
 
         // 鏌ヨ鏍囧噯搴撳凡缁戝畾妫�鏌ラ」鐩�
         List<StandardProductList> standardProductList = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                 .eq(StandardProductList::getStandardMethodListId, id)
                 .like(StandardProductList::getTree, tree)
                 .orderByAsc(StandardProductList::getSort));
-
 
         // 灏佽鍙傛暟
         List<StandardProductList> batchInsertStandardProductListArray = new ArrayList<>();
@@ -374,19 +405,18 @@
                 addStandProductList.setStructureItemParameterId(structureItemParameter.getId());
 
             }
-            addStandProductList.setId(null);
+            addStandProductList.setId(addStandProductList.getId() != null ? addStandProductList.getId() : IdWorker.getId());
             batchInsertStandardProductListArray.add(addStandProductList);
 
         }
-
         // 鎺掑簭澶勭悊 宸叉湁椤哄簭鎸夌収鍘熼『搴� 娌℃湁椤哄簭鐨勬寜鐓ф楠岄」鐨刬d鍗囧簭锛岄粯璁ゆ帓鍦ㄦ渶鍚�
         batchInsertStandardProductListArray.sort(Comparator.comparing((StandardProductList item) -> item.getSort() != null ? item.getSort() : Integer.MAX_VALUE)
                 .thenComparing(StandardProductList::getStructureItemParameterId));
 
         // 鍒犻櫎鍘熺粦瀹氭暟鎹�
         standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
-                    .eq(StandardProductList::getStandardMethodListId, id)
-                    .eq(StandardProductList::getTree, tree));
+                .eq(StandardProductList::getStandardMethodListId, id)
+                .eq(StandardProductList::getTree, tree));
 
         for (int i = 0; i < batchInsertStandardProductListArray.size(); i++) {
             StandardProductList productList = batchInsertStandardProductListArray.get(i);
@@ -611,6 +641,79 @@
         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);
+
+        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())){
+            // 鍒犻櫎澶囦唤鏁版嵁
+            standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
+            // 淇敼鐘舵��
+            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);
+                standardProductList.setCheckStatus("");
+                standardProductListMapper.updateById(standardProductList);
+            }
+            // 鍒犻櫎澶囦唤鏁版嵁
+            standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
+        }
+        standardProductListUpdateRecordMapper.updateById(standardProductListUpdateRecord);
+    }
 }
 
 

--
Gitblit v1.9.3