zss
2024-05-30 a26151eff700b514ca92b0ac9207200b866071fc
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,6 +25,7 @@
import java.io.IOException;
import java.util.*;
import java.util.concurrent.CompletableFuture;
/**
* @author Administrator
@@ -33,6 +40,12 @@
    private GetLook getLook;
    private StandardMethodMapper standardMethodMapper;
    StandardProductListMapper standardProductListMapper;
    StandardProductListService standardProductListService;
    StructureItemParameterMapper structureItemParameterMapper;
    StructureItemParameterService structureItemParameterService;
    @Override
    public Map<String, Object> selectStandardMethodList(Page page, StandardMethod standardMethod) {
@@ -63,10 +76,65 @@
    @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中所有Method如果包含之前的则替换
        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中所有Method如果包含之前的则替换
        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 {