From 087991c76f078defe5eb55d84223021b4199fb3d Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 17 二月 2025 11:22:50 +0800
Subject: [PATCH] 设备模块修改bug

---
 cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java |  223 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 207 insertions(+), 16 deletions(-)

diff --git a/cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java b/cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java
index 2cc8edc..91fb6c0 100644
--- a/cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java
+++ b/cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java
@@ -1,74 +1,265 @@
 package com.yuanchu.mom.service.impl;
 
+import cn.hutool.json.JSONUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yuanchu.mom.common.GetLook;
 import com.yuanchu.mom.common.PrintChina;
+import com.yuanchu.mom.mapper.StandardMethodMapper;
+import com.yuanchu.mom.mapper.StandardProductListMapper;
+import com.yuanchu.mom.mapper.StructureItemParameterMapper;
 import com.yuanchu.mom.pojo.StandardMethod;
+import com.yuanchu.mom.pojo.StandardProductList;
 import com.yuanchu.mom.pojo.StructureItemParameter;
 import com.yuanchu.mom.service.StandardMethodService;
-import com.yuanchu.mom.mapper.StandardMethodMapper;
-import com.yuanchu.mom.service.StandardTreeService;
+import com.yuanchu.mom.service.StandardProductListService;
+import com.yuanchu.mom.service.StructureItemParameterService;
 import com.yuanchu.mom.utils.QueryWrappers;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
 
 /**
-* @author Administrator
-* @description 閽堝琛ㄣ�恠tandard_method(鏍囧噯鏂规硶)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
-* @createDate 2024-03-03 19:21:41
-*/
+ * @author Administrator
+ * @description 閽堝琛ㄣ�恠tandard_method(鏍囧噯鏂规硶)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+ * @createDate 2024-03-03 19:21:41
+ */
 @Service
 @AllArgsConstructor
 public class StandardMethodServiceImpl extends ServiceImpl<StandardMethodMapper, StandardMethod>
-    implements StandardMethodService{
+        implements StandardMethodService {
 
     private GetLook getLook;
 
     private StandardMethodMapper standardMethodMapper;
 
-    private StandardTreeService standardTreeService;
+    StandardProductListMapper standardProductListMapper;
+    StandardProductListService standardProductListService;
+
+    StructureItemParameterMapper structureItemParameterMapper;
+    StructureItemParameterService structureItemParameterService;
 
     @Override
     public Map<String, Object> selectStandardMethodList(Page page, StandardMethod standardMethod) {
         Map<String, Object> map = new HashMap<>();
         map.put("head", PrintChina.printChina(StandardMethod.class));
         Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("selectStandardMethodList");
-        if(map1.get("look")==1) standardMethod.setCreateUser(map1.get("userId"));
+        if (map1.get("look") == 1) standardMethod.setCreateUser(map1.get("userId"));
         map.put("body", standardMethodMapper.selectStandardMethodList(page, QueryWrappers.queryWrappers(standardMethod)));
         return map;
     }
 
     @Override
     public List<StandardMethod> selectStandardMethods() {
-        return standardMethodMapper.selectList(Wrappers.<StandardMethod>lambdaQuery().select(StandardMethod::getId,StandardMethod::getCode,StandardMethod::getName));
+        return standardMethodMapper.selectList(Wrappers.<StandardMethod>lambdaQuery().select(StandardMethod::getId, StandardMethod::getCode, StandardMethod::getName).ne(StandardMethod::getId, 0));
     }
 
     @Override
     public int addStandardMethod(StandardMethod standardMethod) {
         int insert = standardMethodMapper.insert(standardMethod);
-        standardTreeService.reTreeBySampleType(standardMethod.getSampleType());
         return insert;
     }
 
     @Override
     public int delStandardMethod(Integer id) {
-        standardTreeService.reTreeBySampleType(standardMethodMapper.selectById(id).getSampleType());
         int i = standardMethodMapper.deleteById(id);
         return i;
     }
 
     @Override
     public int upStandardMethod(StandardMethod standardMethod) {
+        StandardMethod oldStandardMethod = standardMethodMapper.selectById(standardMethod.getId());
+        if (!oldStandardMethod.getCode().equals(standardMethod.getCode())) {
+            CompletableFuture.supplyAsync(() -> replaceMethod(oldStandardMethod.getCode(), standardMethod.getCode()));
+        }
         int i = standardMethodMapper.updateById(standardMethod);
-        standardTreeService.reTreeBySampleType(standardMethod.getSampleType());
         return i;
     }
+
+    //缂栬緫method鍚庡叏閮ㄦ浛鎹�
+    public String replaceMethod(String oldCode, String code) {
+        //鏌ヨStandardProductList涓墍鏈塎ethod濡傛灉鍖呭惈涔嬪墠鐨勫垯鏇挎崲
+        List<StandardProductList> standardProductLists = standardProductListMapper.selectList(null);
+        for (StandardProductList standardProductList : standardProductLists) {
+            if (standardProductList.getMethod().contains(oldCode)) {
+                String[] split = standardProductList.getMethod().split(",");
+                String a = null;
+                for (int i = 0; i < split.length; i++) {
+                    String methodName = split[i].substring(1, split[i].length() - 1);
+                    if (i == 0) {
+                        methodName = split[i].substring(2, split[i].length() - 1);
+                    } else if (i == split.length - 1) {
+                        methodName = split[i].substring(1, split[i].length() - 2);
+                    }
+                    if (methodName.equals(oldCode)) {
+                        methodName = code;
+                    }
+                    a += "\"" + methodName + "\",";
+                }
+                String method = "[\"" + a.substring(0, a.length() - 1) + "\"]";
+                standardProductList.setMethod(method);
+            }
+        }
+        standardProductListService.updateBatchById(standardProductLists);
+        //鏌ヨStructureItemParameter涓墍鏈塎ethod濡傛灉鍖呭惈涔嬪墠鐨勫垯鏇挎崲
+        List<StructureItemParameter> structureItemParameters = structureItemParameterMapper.selectList(null);
+        for (StructureItemParameter structureItemParameter : structureItemParameters) {
+            if (structureItemParameter.getMethod().contains(oldCode)) {
+                String[] split = structureItemParameter.getMethod().split(",");
+                String a = null;
+                for (int i = 0; i < split.length; i++) {
+                    String methodName = split[i].substring(1, split[i].length() - 1);
+                    if (i == 0) {
+                        methodName = split[i].substring(2, split[i].length() - 1);
+                    } else if (i == split.length - 1) {
+                        methodName = split[i].substring(1, split[i].length() - 2);
+                    }
+                    if (methodName.equals(oldCode)) {
+                        methodName = code;
+                    }
+                    a += "\"" + methodName + "\",";
+                }
+                String method = "[\"" + a.substring(0, a.length() - 1) + "\"]";
+                structureItemParameter.setMethod(method);
+            }
+        }
+        structureItemParameterService.updateBatchById(structureItemParameters);
+        return "鏇挎崲瀹屾瘯!";
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public void inputExcel(MultipartFile file) throws IOException {
+        // 瀛樺偍妫�娴嬪璞ist
+        List<Object> structureTestObjectIdList = new ArrayList<>();
+        List<StandardMethod> result = new ArrayList<>();
+        ExcelUtil.readBySax(file.getInputStream(), 0, (i, l, list) -> {
+            // 鍘婚櫎绗竴琛岃〃澶�
+            if (l == 0) {
+                return;
+            }
+            // 瀛樺偍鍞竴妫�娴嬪璞�
+            if (!structureTestObjectIdList.contains(list.get(2))) {
+                structureTestObjectIdList.add(list.get(2));
+            }
+            StandardMethod standardMethod = formatData(list);
+            result.add(standardMethod);
+        });
+        addStructureTest(structureTestObjectIdList, result);
+    }
+
+    // 鏍煎紡鍖栨暟鎹�
+    public StandardMethod formatData(List<Object> list) {
+        StandardMethod standardMethod = new StandardMethod();
+        standardMethod.setField(list.get(1).toString());
+        // 閫犳牸寮�
+        List<List<Object>> structureTestObjectId = new ArrayList<>();
+        if (ObjectUtils.isEmpty(list.get(3))) {
+            structureTestObjectId.add(Arrays.asList(list.get(2)));
+        } else {
+            structureTestObjectId.add(Arrays.asList(list.get(2), list.get(3)));
+        }
+        standardMethod.setStructureTestObjectId(JSONUtil.toJsonStr(structureTestObjectId));
+        standardMethod.setCode(list.get(4).toString());
+        standardMethod.setName(list.get(5).toString());
+        standardMethod.setNameEn(list.get(6).toString());
+        if (!Objects.equals(list.get(7), null)) {
+            standardMethod.setRemark(list.get(7).toString());
+        }
+        standardMethod.setQualificationId(list.get(8).toString());
+        if (ObjectUtils.isNotEmpty(list.get(9))) {
+            if (list.get(9).equals("鏄�")) {
+                standardMethod.setIsProduct(1);
+            } else if (list.get(9).equals("鍚�")) {
+                standardMethod.setIsProduct(0);
+            }
+        }
+        if (ObjectUtils.isNotEmpty(list.get(10))) {
+            if (list.get(10).equals("鏄�")) {
+                standardMethod.setIsUse(1);
+            } else if (list.get(9).equals("鍚�")) {
+                standardMethod.setIsUse(0);
+            }
+        }
+        return standardMethod;
+    }
+
+    // 鏂板鏁版嵁
+    public void addStructureTest(List<Object> structureTestObjectIdList, List<StandardMethod> standardMethodList) {
+        List<StandardMethod> updateList = new ArrayList<>();
+        List<Integer> deleteListId = new ArrayList<>();
+        List<StandardMethod> addList = new ArrayList<>();
+        if (!structureTestObjectIdList.isEmpty()) {
+            // 寰幆excel閲岄潰鐨勫垎缁�
+            structureTestObjectIdList.forEach(j -> {
+                // 浠xcel涓殑缁勫悕鏌ヨ鏁版嵁搴撲腑鐨勫垎缁�
+                List<StandardMethod> standardMethods = baseMapper.selectList(Wrappers.<StandardMethod>lambdaQuery()
+                        .like(StandardMethod::getStructureTestObjectId, "\"" + j + "\""));
+                // 灏嗙粨鏋滃惊鐜尮閰�
+                for (int i = 0; i < standardMethods.size(); i++) {
+                    boolean isExistence = false;
+                    for (int i1 = 0; i1 < standardMethodList.size(); i1++) {
+                        // 鏇存柊
+                        if (standardMethods.get(i).getStructureTestObjectId().equals(standardMethodList.get(i1).getStructureTestObjectId())
+                                && standardMethods.get(i).getCode().equals(standardMethodList.get(i1).getCode())
+                                && standardMethods.get(i).getField().equals(standardMethodList.get(i1).getField())) {
+                            // 缁檈xcel鏁版嵁璧嬪�糹d鍋氭洿鏂�
+                            standardMethodList.get(i1).setId(standardMethods.get(i).getId());
+                            // 鏇存柊
+                            updateList.add(standardMethodList.get(i1));
+                            isExistence = true;
+                            break;
+                        }
+                    }
+                    // 鍒犻櫎
+                    if (!isExistence) {
+                        deleteListId.add(standardMethods.get(i).getId());
+                    }
+                }
+                for (int i = 0; i < standardMethodList.size(); i++) {
+                    if (standardMethodList.get(i).getStructureTestObjectId().contains("\"" + j + "\"")) {
+                        boolean isExistence = false;
+                        for (int i1 = 0; i1 < standardMethods.size(); i1++) {
+                            if (standardMethods.get(i1).getStructureTestObjectId().equals(standardMethodList.get(i).getStructureTestObjectId())
+                                    && standardMethods.get(i1).getCode().equals(standardMethodList.get(i).getCode())
+                                    && standardMethods.get(i1).getField().equals(standardMethodList.get(i).getField())) {
+                                isExistence = true;
+                                break;
+                            }
+                        }
+                        // 鏂板
+                        if (!isExistence) {
+                            addList.add(standardMethodList.get(i));
+                        }
+                    }
+                }
+            });
+        }
+        if (!addList.isEmpty()) {
+            // 鏂板
+            baseMapper.insertBatchSomeColumn(addList);
+        }
+
+        if (!deleteListId.isEmpty()) {
+            // 鍒犻櫎
+            baseMapper.deleteBatchIds(deleteListId);
+        }
+
+        if (!updateList.isEmpty()) {
+            // 鏇存柊
+            updateList.forEach(i -> {
+                baseMapper.updateById(i);
+            });
+        }
+    }
 }
 
 

--
Gitblit v1.9.3