zss
2025-03-05 578bfcb3f58c5458d2c60fe37c3e56ebcda98e18
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
ÎļþÃû´Ó basic-server/src/main/java/com/ruoyi/inspect/service/impl/StandardTreeServiceImpl.java ÐÞ¸Ä
@@ -1,4 +1,4 @@
package com.ruoyi.inspect.service.impl;
package com.ruoyi.basic.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.ExcelUtil;
@@ -10,17 +10,18 @@
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.dto.FactoryDto;
import com.ruoyi.basic.dto.LaboratoryDto;
import com.ruoyi.basic.dto.SampleTypeDto;
import com.ruoyi.basic.mapper.StandardProductListMapper;
import com.ruoyi.basic.mapper.StandardTreeMapper;
import com.ruoyi.basic.pojo.StandardProductList;
import com.ruoyi.basic.pojo.StandardTemplate;
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.inspect.dto.FactoryDto;
import com.ruoyi.inspect.dto.LaboratoryDto;
import com.ruoyi.inspect.dto.SampleTypeDto;
import com.ruoyi.inspect.mapper.StandardProductListMapper;
import com.ruoyi.inspect.mapper.StandardTreeMapper;
import com.ruoyi.inspect.pojo.StandardProductList;
import com.ruoyi.inspect.pojo.StandardTemplate;
import com.ruoyi.inspect.pojo.StandardTree;
import com.ruoyi.inspect.pojo.StructureTestObject;
import com.ruoyi.inspect.service.*;
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));
    }