From a26151eff700b514ca92b0ac9207200b866071fc Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 30 五月 2024 15:24:48 +0800
Subject: [PATCH] 工时统计+权限+异步处理method+检验样品结果判断

---
 cnas-server/src/main/java/com/yuanchu/mom/service/impl/StandardMethodServiceImpl.java |   84 ++++++++++++++++++++++++++++++++++++++----
 1 files changed, 76 insertions(+), 8 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 2e227d8..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
@@ -9,8 +9,14 @@
 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.service.StandardProductListService;
+import com.yuanchu.mom.service.StructureItemParameterService;
 import com.yuanchu.mom.utils.QueryWrappers;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -19,34 +25,41 @@
 
 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;
+
+    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).ne(StandardMethod::getId, 0));
+        return standardMethodMapper.selectList(Wrappers.<StandardMethod>lambdaQuery().select(StandardMethod::getId, StandardMethod::getCode, StandardMethod::getName).ne(StandardMethod::getId, 0));
     }
 
     @Override
@@ -63,8 +76,63 @@
 
     @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);
         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)
@@ -94,7 +162,7 @@
         standardMethod.setField(list.get(1).toString());
         // 閫犳牸寮�
         List<List<Object>> structureTestObjectId = new ArrayList<>();
-        if (ObjectUtils.isEmpty(list.get(3))){
+        if (ObjectUtils.isEmpty(list.get(3))) {
             structureTestObjectId.add(Arrays.asList(list.get(2)));
         } else {
             structureTestObjectId.add(Arrays.asList(list.get(2), list.get(3)));

--
Gitblit v1.9.3