chenrui
2025-04-03 cf396d3076a064998fbac84f76861f5ed918c5e5
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardMethodListServiceImpl.java
@@ -1,13 +1,19 @@
package com.ruoyi.basic.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.mapper.StandardMethodListMapper;
import com.ruoyi.basic.mapper.StandardProductListMapper;
import com.ruoyi.basic.mapper.WorkShopMapper;
import com.ruoyi.basic.pojo.StandardMethodList;
import com.ruoyi.basic.pojo.StandardProductList;
import com.ruoyi.basic.pojo.WorkShop;
import com.ruoyi.basic.service.StandardMethodListService;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@@ -29,111 +35,78 @@
    private StandardProductListMapper standardProductListMapper;
    @Override
    public int addStandardMethodList(Integer standardId, String tree) {
        String[] trees = tree.split(" - ");
        Map<String, String> map = standardMethodListMapper.selectStandardMethodById(standardId);
        StandardMethodList list = new StandardMethodList();
        list.setCode(map.get("code"));
        list.setName(map.get("name"));
        list.setRemark(map.get("remark"));
        list.setFactory(trees[0]);
        try {
            list.setLaboratory(trees[1]);
        }catch (Exception e){}
        try {
            list.setSampleType(trees[2]);
        }catch (Exception e){}
        try {
            list.setSample(trees[3]);
        }catch (Exception e){}
        try {
            list.setModel(trees[4]);
        }catch (Exception e){}
        standardMethodListMapper.insert(list);
        List<StandardProductList> standardProductLists = standardMethodListMapper.selectParameterList(list.getCode());
        for (StandardProductList standardProductList : standardProductLists) {
            standardProductList.setStandardMethodListId(list.getId());
            standardProductList.setFactory(trees[0]);
            try {
                standardProductList.setLaboratory(trees[1]);
            }catch (Exception e){}
            try {
                standardProductList.setSampleType(trees[2]);
            }catch (Exception e){}
            try {
                standardProductList.setSample(trees[3]);
            }catch (Exception e){}
            try {
                standardProductList.setModel(trees[4]);
            }catch (Exception e){}
            standardProductListMapper.insert(standardProductList);
        }
        return 1;
    }
    @Autowired
    private WorkShopMapper workShopMapper;
    @Override
    public Map<String, List<?>> selectsStandardMethodByFLSSM(String tree) {
        String[] trees = tree.split(" - ");
        Map<String, List<?>> map = new HashMap<>();
        String str = "";
        List<StandardMethodList> standardMethodLists = new ArrayList<>();
        switch (trees.length){
            case 5:
                str += "\"" + trees[2] + "\",\"" + trees[3] + "\",\"" + trees[4] + "\"";
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str));
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[2] + "\",\"" + trees[3] + "\""));
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[2] + "\""));
                break;
            case 4:
                str += "\"" + trees[2] + "\",\"" + trees[3] + "\"";
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists(str));
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists("\"" + trees[2] + "\""));
                break;
            case 3:
                str += "\"" + trees[2] + "\"";
                standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodLists3(str));
                break;
            default:
                map.put("standardMethodList", null);
                return map;
        String sampleType = ""; // 检验对象
        // 拼接树
        String[] trees = tree.split(" - ");
        map.put("standardMethodList", null);
        if(trees == null && trees.length < 4){
            return map;
        }
        standardMethodLists.addAll(standardMethodListMapper.selectStandardMethodListsByNull(str));
        map.put("standardMethodList", standardMethodLists);
        StringBuilder checkItemQueryTree = new StringBuilder();   // 检查项查询
        StringBuilder productTree = new StringBuilder(); // 检验产品树
        // 判断是否包含车间
        boolean existWorkShopFlag = this.existWorkShop(tree);
        // 车间层级多一层级
        if(existWorkShopFlag){
            switch (trees.length) {
                case 7:
                    sampleType = trees[4];
                    checkItemQueryTree.append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\",\"").append(trees[6]).append("\"");
                    productTree.append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"");
                    break;
                case 6:
                    sampleType = trees[4];
                    checkItemQueryTree.append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"");
                    break;
                case 5:
                    sampleType = trees[4];
                    checkItemQueryTree.append("\"").append(trees[4]).append("\"").append("]");
                    break;
            }
        }else {
            switch (trees.length) {
                case 6:
                    sampleType = trees[3];
                    checkItemQueryTree.append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"");
                    productTree.append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"");
                    break;
                case 5:
                    sampleType = trees[3];
                    checkItemQueryTree.append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"");
                    break;
                case 4:
                    sampleType = trees[3];
                    checkItemQueryTree.append("\"").append(trees[3]).append("\"").append("]");
                    break;
            }
        }
        if(StringUtils.isEmpty(checkItemQueryTree.toString())){
            return map;
        }
        List<StandardMethodList> standardMethodListArray = standardMethodListMapper.selectStandardMethodLists(checkItemQueryTree.toString());
        // 查不到查询检查对象
        if(CollectionUtils.isEmpty(standardMethodListArray)){
            // 如果是完整层级,向上推到产品层级
            if((existWorkShopFlag&&trees.length == 7) || (!existWorkShopFlag&&trees.length == 6)){
                standardMethodListArray = standardMethodListMapper.selectStandardMethodLists(productTree.toString());
            }
            // 还是为空查询对象层级
            if(CollectionUtils.isEmpty(standardMethodListArray)){
                standardMethodListArray = standardMethodListMapper.selectStandardMethodLists(sampleType);
            }
        }
        map.put("standardMethodList", standardMethodListArray);
        return map;
    }
    @Override
    public Map<String, List<?>> selectsStandardMethodByFLSSM2(String tree) {
        String[] trees = tree.split(" - ");
        List<StandardMethodList> standardMethodLists = null;
        switch (trees.length){
            case 5:
                standardMethodLists = standardMethodListMapper.selectStandardMethodLists2(trees[0],trees[1],trees[2],trees[3],trees[4]);
                break;
            case 4:
                standardMethodLists = standardMethodListMapper.selectStandardMethodLists2(trees[0],trees[1],trees[2],trees[3],null);
                break;
            case 3:
                standardMethodLists = standardMethodListMapper.selectStandardMethodLists2(trees[0],trees[1],trees[2],null,null);
                break;
            case 2:
                standardMethodLists = standardMethodListMapper.selectStandardMethodLists2(trees[0],trees[1],null,null,null);
                break;
            case 1:
                standardMethodLists = standardMethodListMapper.selectStandardMethodLists2(trees[0],null,null,null,null);
                break;
        }
        Map<String, List<?>> map = new HashMap<>();
        map.put("standardMethodList", standardMethodLists);
        return map;
    }
    @Override
    public int delStandardMethodByFLSSM(Integer id) {
        standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate().eq(StandardProductList::getStandardMethodListId, id));
        return standardMethodListMapper.deleteById(id);
    }
    @Override
    public List<StandardMethodList> selectStandardMethodEnum() {
        return standardMethodListMapper.selectListEnum();
@@ -143,6 +116,29 @@
    public Integer getStandardMethodId(String code) {
        return baseMapper.getStandardMethodId(code);
    }
    /**
     * 判断是否包含车间
     *
     * @param tree
     * @return
     */
    @Override
    public boolean existWorkShop(String tree){
        QueryWrapper<WorkShop> queryWrapper = new QueryWrapper<>();
        List<WorkShop> workShopList = workShopMapper.selectList(queryWrapper);
        String[] trees = tree.split(" - ");
        if(trees != null && trees.length > 0){
            for (int i = 0; i < trees.length; i++) {
                for (WorkShop workShop : workShopList) {
                    if(workShop.getName().equals(trees[i].trim())){
                        return true;
                    }
                }
            }
        }
        return false;
    }
}