zss
2025-03-11 eeb8d7faa8d25b3ca9fe75ef28f035c49af5b06d
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
@@ -10,7 +10,6 @@
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.common.exception.base.BaseException;
import com.ruoyi.basic.dto.FactoryDto;
import com.ruoyi.basic.dto.LaboratoryDto;
import com.ruoyi.basic.dto.SampleTypeDto;
@@ -21,6 +20,8 @@
import com.ruoyi.basic.pojo.StandardTree;
import com.ruoyi.basic.pojo.StructureTestObject;
import com.ruoyi.basic.service.*;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.framework.exception.ErrorException;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
@@ -51,24 +52,17 @@
    private StandardProductListMapper standardProductListMapper;
    private StandardProductListService standardProductListService;
    private StandardTemplateService standardTemplateService;
    private StructureTestObjectService structureTestObjectService;
    @Override
    public List<FactoryDto> selectStandardTreeList() {
        List<FactoryDto> factoryDtos = standardTreeMapper.selectStandardTreeList();
        for (FactoryDto factoryDto : factoryDtos) {
            for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
                laboratoryDto.getChildren().sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
                        - (o2.getSort() == null ? 0 : o2.getSort()));
                for (SampleTypeDto sampleTypeDto : laboratoryDto.getChildren()) {
//                    if (sampleTypeDto.getChildren().size() == 0) {
                        sampleTypeDto.getChildren().addAll(standardTreeMapper.getStandardTree3(sampleTypeDto.getValue()));
//                    }
                    if (sampleTypeDto.getChildren().size() == 0) {
                        sampleTypeDto.setChildren(standardTreeMapper.getStandardTree3(sampleTypeDto.getValue()));
                    }
                }
            }
        }
@@ -80,19 +74,14 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addStandardTree(StandardTree standardTree) {
        LambdaQueryWrapper<StandardTree> wrapper = Wrappers.<StandardTree>lambdaQuery()
        StandardTree tree = standardTreeMapper.selectOne(Wrappers.<StandardTree>lambdaQuery()
                .eq(StandardTree::getFactory, standardTree.getFactory())
                .eq(StandardTree::getLaboratory, standardTree.getLaboratory())
                .eq(StandardTree::getSampleType, standardTree.getSampleType())
                .eq(StandardTree::getSample, standardTree.getSample())
                .eq(StandardTree::getModel, standardTree.getModel());
        if (StringUtils.isNotBlank(standardTree.getSample())) {
            wrapper.eq(StandardTree::getSample, standardTree.getSample());
        }
        StandardTree tree = standardTreeMapper.selectOne(wrapper);
                .eq(StandardTree::getModel, standardTree.getModel()));
        if (tree != null) {
            throw new BaseException("该型号已存在");
            throw new ErrorException("该型号已存在");
        }
        return standardTreeMapper.insert(standardTree);
    }
@@ -109,18 +98,6 @@
                    standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3]).eq(StandardTree::getModel, trees[4]));
                }
                break;
            /*case 4:
                standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3]));
                break;
            case 3:
                standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]));
                break;
            case 2:
                standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]).eq(StandardTree::getLaboratory, trees[1]));
                break;
            case 1:
                standardTreeMapper.delete(Wrappers.<StandardTree>lambdaUpdate().eq(StandardTree::getFactory, trees[0]));
                break;*/
        }
        return 1;
    }
@@ -166,10 +143,6 @@
        StandardProductList productList = JSON.parseObject(JSON.toJSONString(product.get("standardProductList")), StandardProductList.class);
        if (productList.getMethodS() != null) {
            standardProductListMapper.update(productList, Wrappers.<StandardProductList>lambdaUpdate().in(StandardProductList::getId, ids).like(StandardProductList::getMethod, productList.getMethodS()));
            return 1;
        }
        if (productList.getRadiusList() != null) {
            standardProductListMapper.update(productList, Wrappers.<StandardProductList>lambdaUpdate().in(StandardProductList::getId, ids).like(StandardProductList::getRadiusList, productList.getRadius()));
            return 1;
        }
        standardProductListMapper.update(productList, Wrappers.<StandardProductList>lambdaUpdate().in(StandardProductList::getId, ids));
@@ -442,70 +415,6 @@
    }
    @Override
    public boolean updateTreeSort(List<FactoryDto> list) {
        List<StructureTestObject> testObjects = new ArrayList<>();
        for (FactoryDto factoryDto : list) {
            for (LaboratoryDto laboratoryDto : factoryDto.getChildren()) {
                List<SampleTypeDto> children = laboratoryDto.getChildren();
                int sort = 0;
                // 循环第三层
                for (SampleTypeDto child : children) {
                    StructureTestObject structureTestObject = new StructureTestObject();
                    structureTestObject.setSort(sort);
                    structureTestObject.setId(child.getSampleTypeId());
                    testObjects.add(structureTestObject);
                    sort++;
                }
            }
        }
        structureTestObjectService.updateBatchById(testObjects);
        return true;
    }
    /**
     * 修改标准数
     * @param standardTree
     * @return
     */
    @Override
    public int updateStandardTree(StandardTree standardTree) {
        // 修改名称匹配的标准树下的检验项目
        // 查询所有对象+名称的树
        List<StandardProductList> standardProductLists = standardProductListService.list(Wrappers.<StandardProductList>lambdaUpdate()
                .eq(StandardProductList::getSample, standardTree.getSample())
                .eq(StandardProductList::getSampleType, standardTree.getSampleType())
                .eq(StandardProductList::getModel, standardTree.getOldModel()));
        if (CollectionUtils.isNotEmpty(standardProductLists)) {
            for (StandardProductList standardProductList : standardProductLists) {
                // 修改样品名称
                standardProductList.setModel(standardTree.getModel());
                // 修改树名称
                // 需要截取第四级, 避免三四级名称一样修改错误
                String[] trees = standardProductList.getTree().split(" - ");
                trees[4] = standardTree.getModel();
                List<String> list = CollUtil.newArrayList(trees);
                String newName = CollUtil.join(list, " - ");
                standardProductList.setTree(newName);
            }
            standardProductListService.updateBatchById(standardProductLists);
        }
        // 修改标准数检验项目
        LambdaUpdateWrapper<StandardTree> wrapper = Wrappers.<StandardTree>lambdaUpdate()
                .eq(StandardTree::getFactory, standardTree.getFactory())
                .eq(StandardTree::getLaboratory, standardTree.getLaboratory())
                .eq(StandardTree::getSampleType, standardTree.getSampleType())
                .eq(StandardTree::getModel, standardTree.getOldModel())
                .set(StandardTree::getModel, standardTree.getModel());
        if (StringUtils.isNotBlank(standardTree.getSample())) {
            wrapper.eq(StandardTree::getSample, standardTree.getSample());
        }
        return standardTreeMapper.update(null, wrapper);
    }
    @Override
    public void resetTreeOfPrice(String tree, Integer standardId) {
        standardProductListMapper.update(null, Wrappers.<StandardProductList>lambdaUpdate().like(StandardProductList::getTree, tree).eq(StandardProductList::getStandardMethodListId, standardId).set(StandardProductList::getPrice, null));
    }
@@ -521,9 +430,6 @@
                .set(StandardProductList::getAsk, null)
                .set(StandardProductList::getTell, null)
                .set(StandardProductList::getSection, null)
                .set(StandardProductList::getCores, null)
                .set(StandardProductList::getConductorMaterial, null)
                .set(StandardProductList::getConductorType, null)
                .set(StandardProductList::getPrice, null)
                .set(StandardProductList::getManHour, null));
    }