chenrui
2025-04-01 0a305b633bb743f01cbb636670c2fc02620168d0
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -7,16 +7,17 @@
import com.baomidou.mybatisplus.core.toolkit.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.*;
import com.ruoyi.basic.enums.BasicTreeEnums;
import com.ruoyi.basic.enums.StandardProductListChcekTypeEnums;
import com.ruoyi.basic.enums.StandardProductListOperationTypeEnums;
import com.ruoyi.basic.mapper.*;
import com.ruoyi.basic.pojo.*;
import com.ruoyi.basic.service.StandardMethodListService;
import com.ruoyi.basic.service.StandardMethodService;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.basic.dto.CopyStandardProductListDto;
import com.ruoyi.basic.dto.InsSampleReceiveDto;
import com.ruoyi.basic.dto.ProductDto;
import com.ruoyi.basic.dto.ResetTreeDragDTO;
import com.ruoyi.basic.service.StandardProductListService;
import lombok.AllArgsConstructor;
import org.apache.catalina.security.SecurityUtil;
@@ -59,9 +60,36 @@
    @Autowired
    private StructureItemParameterMapper structureItemParameterMapper;
    @Autowired
    private ModelMapper modelMapper;
    @Autowired
    private StandardProductListBackupRelMapper standardProductListBackupRelMapper;
    @Autowired
    private StandardProductListUpdateRecordMapper standardProductListUpdateRecordMapper;
    @Override
    public int upStandardProductList(StandardProductList list) {
        // 根据id 查询到原始值
        StandardProductList standardProductList = standardProductListMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductList)){
            throw new RuntimeException("更新失败,未查找到检查项");
        }
        // 判断当前状态 如果是审核中
        if(StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())){
            throw new RuntimeException("审核中不支持修改");
        }
        // 查询最新的一次关联备份 如果存在说明未审核完继续修改了。不做数据处理。
        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductListBackupRel)){
            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
            BeanUtils.copyProperties(standardProductList, productListBackupRel);
            standardProductListBackupRelMapper.insert(productListBackupRel);
        }
        // 修改状态
        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        return standardProductListMapper.updateById(list);
    }
@@ -290,6 +318,7 @@
        String sampleType = "";
        String sample = "";
        String model = "";
        StringBuilder checkItemQueryTree = new StringBuilder();   // 检查项查询 只拼接 检查对象-产品
        // 返回结果
        Map<String, Object> map = new HashMap<>();
@@ -303,57 +332,60 @@
        if(trees == null && trees.length < 4){
            return map;
        }
        StringBuilder queryTreeBuilder = new StringBuilder();
        // 车间层级多一层级
        if(existWorkShopFlag){
            switch (trees.length) {
                case 7:
                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\",\"").append(trees[6]).append("\"").append("]");
                    sampleType = trees[4];
                    sample = trees[5];
                    model = trees[6];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    break;
                case 6:
                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    sampleType = trees[4];
                    sample = trees[5];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    break;
                case 5:
                    queryTreeBuilder.append("[").append("\"").append(trees[4]).append("\"").append("]");
                    sampleType = trees[4];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\"").append("]");
                    break;
            }
        }else {
            switch (trees.length) {
                case 6:
                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    sampleType = trees[3];
                    sample = trees[4];
                    model = trees[5];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                    break;
                case 5:
                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                    sampleType = trees[3];
                    sample = trees[4];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                    break;
                case 4:
                    queryTreeBuilder.append("[").append("\"").append(trees[3]).append("\"").append("]");
                    sampleType = trees[3];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\"").append("]");
                    break;
            }
        }
        if(StringUtils.isEmpty(queryTreeBuilder.toString())){
        if(StringUtils.isEmpty(checkItemQueryTree.toString())){
            return map;
        }
        // 根据检验对象/产品/型号查询检验项
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(queryTreeBuilder.toString());
        // 根据检验对象/产品查询检验项
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(checkItemQueryTree.toString());
        // 如果是产品的检查项为空向上推
        if(CollectionUtils.isEmpty(structureItemParameterList)){
            String query = "[\"" + sampleType + "\"]";
            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(query);
        }
        // 查询标准库已绑定检查项目
        List<StandardProductList> standardProductList = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                .eq(StandardProductList::getStandardMethodListId, id)
                .like(StandardProductList::getTree, tree)
                .orderByAsc(StandardProductList::getSort));
        // 封装参数
        List<StandardProductList> batchInsertStandardProductListArray = new ArrayList<>();
@@ -374,19 +406,18 @@
                addStandProductList.setStructureItemParameterId(structureItemParameter.getId());
            }
            addStandProductList.setId(null);
            addStandProductList.setId(addStandProductList.getId() != null ? addStandProductList.getId() : IdWorker.getId());
            batchInsertStandardProductListArray.add(addStandProductList);
        }
        // 排序处理 已有顺序按照原顺序 没有顺序的按照检验项的id升序,默认排在最后
        batchInsertStandardProductListArray.sort(Comparator.comparing((StandardProductList item) -> item.getSort() != null ? item.getSort() : Integer.MAX_VALUE)
                .thenComparing(StandardProductList::getStructureItemParameterId));
        // 删除原绑定数据
        standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .eq(StandardProductList::getTree, tree));
                .eq(StandardProductList::getStandardMethodListId, id)
                .eq(StandardProductList::getTree, tree));
        for (int i = 0; i < batchInsertStandardProductListArray.size(); i++) {
            StandardProductList productList = batchInsertStandardProductListArray.get(i);
@@ -611,6 +642,59 @@
        this.updateBatchById(productLists);
        return false;
    }
    /**
     * 标准树下检验项处理
     * @param standardProductListDto
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void productListOperate(StandardProductListDto standardProductListDto) {
        StandardProductList standardProductList = new StandardProductList();
        standardProductList.setId(standardProductListDto.getId());
        StandardProductListUpdateRecord standardProductListUpdateRecord = new StandardProductListUpdateRecord();
        // 审核通过
        if(StandardProductListOperationTypeEnums.PASS_CHECK_OP.getCode().equals(standardProductListDto.getOperationStatus())){
            // 删除备份数据
            standardProductListBackupRelMapper.deleteById(standardProductListDto.getId());
            standardProductList.setCheckStatus(StandardProductListChcekTypeEnums.PASS_CHECK.getCode());
        // 审核不通过
        }else if(StandardProductListOperationTypeEnums.NO_PASS_CHECK_OP.getCode().equals(standardProductListDto.getOperationStatus())) {
            // 还原数据
            StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(standardProductListDto.getId());
            if(ObjectUtils.isEmpty(standardProductListBackupRel)){
                throw new RuntimeException("备份数据查找失败");
            }
            BeanUtils.copyProperties(standardProductListBackupRel, standardProductList);
            standardProductList.setCheckStatus(StandardProductListChcekTypeEnums.NO_PASS_CHECK.getCode());
        // 提交
        }else if(StandardProductListOperationTypeEnums.SUBMIT_OP.getCode().equals(standardProductListDto.getOperationStatus())) {
            standardProductListUpdateRecord.setOperationType(StandardProductListOperationTypeEnums.PASS_CHECK_OP.getCode());
            standardProductList.setCheckStatus(StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        } else {
            throw new RuntimeException("操作有误");
        }
        // 新增操作记录
        standardProductListUpdateRecord.setStandardProductListId(standardProductListDto.getId());
        standardProductListUpdateRecord.setOperationType(standardProductListDto.getOperationStatus());
        standardProductListUpdateRecordMapper.insert(standardProductListUpdateRecord);
        // 修改审核状态
        standardProductList.setCheckStatus(standardProductListDto.getOperationStatus());
        standardProductListMapper.updateById(standardProductList);
    }
    /**
     * 标准树下检验项修改记录分页查询
     * @param page
     * @param record
     * @return
     */
    @Override
    public IPage<StandardProductListUpdateRecord> standardProductListRecordPage(Page page, StandardProductListUpdateRecord record) {
        return standardProductListUpdateRecordMapper.standardProductListRecordPage(page,QueryWrappers.queryWrappers(record));
    }
}