chenrui
2025-03-25 fffa63eb736609e53c1d6b4d1ca9d353d639a532
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardTreeServiceImpl.java
@@ -6,7 +6,6 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
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.*;
@@ -16,6 +15,7 @@
import com.ruoyi.basic.pojo.*;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.basic.service.*;
import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.BeanUtils;
@@ -208,23 +208,30 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int addStandardTree(StandardTree standardTree) {
        LambdaQueryWrapper<StandardTree> wrapper = 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());
    public int addStandardTree(ModelAddDto modelAddDto) {
        // 校验
        if(StringUtils.isEmpty(modelAddDto.getParentId())){
            throw new RuntimeException("缺少父层级绑定关系");
        }
        StandardTree tree = standardTreeMapper.selectOne(wrapper);
        if (tree != null) {
            throw new BaseException("该型号已存在");
        Model model = new Model();
        String parentLevel = modelAddDto.getParentLevel();
        if(BasicTreeEnums.PRODUCT_TYPE.getCode().equals(parentLevel)){
            model.setProductId(Integer.valueOf(parentLevel));
        }else if(BasicTreeEnums.STRUCTURE_TEST_OBJECT_TYPE.getCode().equals(parentLevel)){
            model.setStructureTestObjectId(Integer.valueOf(parentLevel));
        }else {
            throw new RuntimeException("型号只能绑定对象和产品");
        }
        return standardTreeMapper.insert(standardTree);
        // 名称重读性校验
        QueryWrapper<Model> modelQueryWrapper = new QueryWrapper<>();
        modelQueryWrapper.eq("product_id", model.getProductId());
        modelQueryWrapper.eq("structure_test_object_id", model.getStructureTestObjectId());
        modelQueryWrapper.eq("model_name", model.getModelName());
        Model modelResult = modelMapper.selectOne(modelQueryWrapper);
        if(ObjectUtils.isNotEmpty(modelResult)){
            throw new RuntimeException("请勿添加重复型号");
        }
        return modelMapper.insert(model);
    }
    @Override