chenrui
2025-04-08 fed01a2550b0d62855ec6f76dad32bc15a57da94
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -12,6 +12,7 @@
import com.ruoyi.basic.mapper.*;
import com.ruoyi.basic.pojo.*;
import com.ruoyi.basic.service.StandardMethodListService;
import com.ruoyi.basic.service.StandardProductListSupplierAskService;
import com.ruoyi.common.exception.base.BaseException;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.common.utils.SecurityUtils;
@@ -68,6 +69,15 @@
    @Autowired
    private StandardProductListUpdateRecordRelMapper standardProductListUpdateRecordRelMapper;
    @Autowired
    private StandardProductListSupplierAskService standardProductListSupplierAskService;
    @Autowired
    private StandardProductListSupplierAskBackupRelMapper  standardProductListSupplierAskBackupRelMapper;
    @Autowired
    private StandardMethodMapper standardMethodMapper;
    @Override
    public int upStandardProductList(StandardProductList list) {
@@ -80,6 +90,15 @@
        if(StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())){
            throw new RuntimeException("审核中不支持修改");
        }
        // 判断检验项是否为是否委托要求 是的话不需要做备份和状态修改直接更新
        StructureItemParameter structureItemParameter = structureItemParameterMapper.selectById(standardProductList.getStructureItemParameterId());
        if(!ObjectUtils.isEmpty(structureItemParameter) && "1".equals(structureItemParameter.getDelegateRequestFlag())){
            return standardProductListMapper.updateById(list);
        }
        // 判断是否为生效的修改如果是不做备份
        if(null != list.getState()){
            return standardProductListMapper.updateById(list);
        }
        // 查询最新的一次关联备份 如果存在说明未审核完继续修改了。不做数据处理。
        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductListBackupRel)){
@@ -87,6 +106,10 @@
            BeanUtils.copyProperties(standardProductList, productListBackupRel);
            standardProductListBackupRelMapper.insert(productListBackupRel);
        }
        // 关联商家备份
        StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
        standardProductListSupplierAsk.setProductListId(list.getId());
        standardProductListSupplierAskService.backupSupplierAsk(standardProductListSupplierAsk);
        // 修改状态
        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        return standardProductListMapper.updateById(list);
@@ -372,14 +395,27 @@
        if(StringUtils.isEmpty(checkItemQueryTree.toString())){
            return map;
        }
        // 判断是否为委托要求标准
        StandardMethod standardMethod = standardMethodMapper.selectById(id);
        if(ObjectUtils.isEmpty(standardMethod)){
            return map;
        }
        StructureItemParameterDto structureItemParameterDto = new StructureItemParameterDto();
        if(standardMethod.getName().equals("委托要求")){
            structureItemParameterDto.setDelegateRequestFlag("1");
        }else {
            structureItemParameterDto.setDelegateRequestFlag("0");
        }
        structureItemParameterDto.setTree(checkItemQueryTree.toString());
        // 根据检验对象/产品查询检验项
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(checkItemQueryTree.toString());
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
        // 如果是产品的检查项为空向上推
        if(CollectionUtils.isEmpty(structureItemParameterList)){
            String query = "[\"" + sampleType + "\"]";
            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(query);
            structureItemParameterDto.setTree(query);
            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
        }
        // 查询标准库已绑定检查项目
        List<StandardProductList> standardProductList = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                .eq(StandardProductList::getStandardMethodListId, id)
@@ -505,6 +541,10 @@
            BeanUtils.copyProperties(standardProductList, productListBackupRel);
            standardProductListBackupRelMapper.insert(productListBackupRel);
        }
        // 关联商家备份
        StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
        standardProductListSupplierAsk.setProductListId(list.getId());
        standardProductListSupplierAskService.backupSupplierAsk(standardProductListSupplierAsk);
        // 修改状态
        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        standardProductListMapper.updateSection(list);
@@ -670,7 +710,9 @@
        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        List<StandardProductList> unCheckStandardProductListArray = standardProductListMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(unCheckStandardProductListArray)){
            throw new RuntimeException("暂无修改数据");
        }
        List<Long> standardProductListIds = new ArrayList<>();
        // 插入修改记录
        standardProductListUpdateRecordMapper.insert(standardProductListUpdateRecord);
@@ -711,27 +753,60 @@
        }
        // 审核通过
        if(StandardProductListChcekTypeEnums.PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())){
            // 删除备份数据
            standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
            // 修改状态
            standardProductListMapper.updateProductListCheckStatus(standardProductListIds,StandardProductListChcekTypeEnums.PASS_CHECK.getCode());
        }
        // 审核未通过
        if(StandardProductListChcekTypeEnums.NO_PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())){
            // 查询所有的备份数据
            // 查询所有标准树下的检验项目备份数据
            List<StandardProductListBackupRel> standardProductListBackupRelList = standardProductListBackupRelMapper.selectBatchIds(standardProductListIds);
            // 回滚数据
            // 回滚标准树下的检验项目数据
            for (StandardProductListBackupRel standardProductListBackupRel : standardProductListBackupRelList) {
                StandardProductList standardProductList = new StandardProductList();
                BeanUtils.copyProperties(standardProductListBackupRel, standardProductList);
                standardProductList.setCheckStatus("");
                standardProductListMapper.updateById(standardProductList);
            }
            // 删除备份数据
            standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
            // 回滚检验项目厂家密度绑定表数据
            QueryWrapper<StandardProductListSupplierAskBackupRel> supplierAskBackupRelQueryWrapper = new QueryWrapper<>();
            supplierAskBackupRelQueryWrapper.in("product_list_id",standardProductListIds);
            List<StandardProductListSupplierAskBackupRel> standardProductListSupplierAskBackupRelList = standardProductListSupplierAskBackupRelMapper.selectList(supplierAskBackupRelQueryWrapper);
            if(!CollectionUtils.isEmpty(standardProductListSupplierAskBackupRelList)){
                QueryWrapper<StandardProductListSupplierAsk> deleteWrapper = new QueryWrapper<>();
                deleteWrapper.in("product_list_id",standardProductListIds);
                standardProductListSupplierAskMapper.delete(deleteWrapper);
                ArrayList<StandardProductListSupplierAsk> supplierAskRollBackList = new ArrayList<>();
                for (StandardProductListSupplierAskBackupRel standardProductListSupplierAskBackupRel : standardProductListSupplierAskBackupRelList) {
                    StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
                    BeanUtils.copyProperties(standardProductListSupplierAskBackupRel, standardProductListSupplierAsk);
                    supplierAskRollBackList.add(standardProductListSupplierAsk);
                }
                standardProductListSupplierAskMapper.batchInsertSupplierAsk(supplierAskRollBackList);
            }
        }
        // 删除标准树下的检验项目备份数据
        standardProductListBackupRelMapper.deleteBatchIds(standardProductListIds);
        // 删除绑定厂家备份数据
        standardProductListSupplierAskBackupRelMapper.batchDeleteByProductIds(standardProductListIds);
        standardProductListUpdateRecordMapper.updateById(standardProductListUpdateRecord);
    }
    /**
     * 查询标准库是否存在审核中状态
     *
     * @return
     */
    @Override
    public boolean existCheckingRecord() {
        QueryWrapper<StandardProductListUpdateRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        List<StandardProductListUpdateRecord> standardProductListUpdateRecordList = standardProductListUpdateRecordMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(standardProductListUpdateRecordList)){
            return false;
        }else {
            return true;
        }
    }
}