liding
2025-04-11 804c80b0fd284c7464066efbd5e5833ddacfb635
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -14,13 +14,10 @@
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;
import com.ruoyi.basic.service.StandardProductListService;
import lombok.AllArgsConstructor;
import org.aspectj.weaver.ast.Var;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -50,33 +47,24 @@
    private ProductPartMapper productPartMapper;
    private StructureTestObjectPartMapper  structureTestObjectPartMapper;
    private StructureTestObjectPartMapper structureTestObjectPartMapper;
    @Autowired
    private StandardMethodListService standardMethodListService;
    @Autowired
    private StructureItemParameterMapper structureItemParameterMapper;
    @Autowired
    private ModelMapper modelMapper;
    @Autowired
    private StandardProductListBackupRelMapper standardProductListBackupRelMapper;
    @Autowired
    private StandardProductListUpdateRecordMapper standardProductListUpdateRecordMapper;
    @Autowired
    private StandardProductListUpdateRecordRelMapper standardProductListUpdateRecordRelMapper;
    @Autowired
    private StandardProductListSupplierAskService standardProductListSupplierAskService;
    @Autowired
    private StandardProductListSupplierAskBackupRelMapper  standardProductListSupplierAskBackupRelMapper;
    private StandardProductListSupplierAskBackupRelMapper standardProductListSupplierAskBackupRelMapper;
    @Autowired
    private StandardMethodMapper standardMethodMapper;
@@ -84,25 +72,25 @@
    public int upStandardProductList(StandardProductList list) {
        // 根据id 查询到原始值
        StandardProductList standardProductList = standardProductListMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductList)){
        if (ObjectUtils.isEmpty(standardProductList)) {
            throw new RuntimeException("更新失败,未查找到检查项");
        }
        // 判断当前状态 如果是审核中
        if(StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())){
        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())){
        if (!ObjectUtils.isEmpty(structureItemParameter) && "1".equals(structureItemParameter.getDelegateRequestFlag())) {
            return standardProductListMapper.updateById(list);
        }
        // 判断是否为生效的修改如果是不做备份
        if(null != list.getState()){
        if (null != list.getState()) {
            return standardProductListMapper.updateById(list);
        }
        // 查询最新的一次关联备份 如果存在说明未审核完继续修改了。不做数据处理。
        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductListBackupRel)){
        if (ObjectUtils.isEmpty(standardProductListBackupRel)) {
            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
            BeanUtils.copyProperties(standardProductList, productListBackupRel);
            standardProductListBackupRelMapper.insert(productListBackupRel);
@@ -127,7 +115,7 @@
        standardProductListDto.setStandardMethodListIds(insSample.getStandardMethodListIds());
        standardProductListDto.setState(insSample.getState());
        List<StandardProductList> list = new ArrayList<>();
        if(CollectionUtils.isEmpty(standardProductListDto.getStandardMethodListIds())) {
        if (CollectionUtils.isEmpty(standardProductListDto.getStandardMethodListIds())) {
            return list;
        }
        list = standardProductListMapper.standardProductListNoPage(standardProductListDto);
@@ -145,18 +133,54 @@
                                if (Objects.equals(a.getBsm(), "1")) {
                                    return true;
                                } else {
                                    if (sections.get(i).contains("&")) {
                                        String[] split = sections.get(i).split("&");
                                        isIf = getIsIf(split[0], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample)
                                                && getIsIf(split[1], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
                                    } else {
                                        isIf = getIsIf(sections.get(i), modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
                                    int firstIndex = a.getTree().indexOf(" - ");
                                    String result2 = null;
                                    if (firstIndex != -1) {
                                        int secondIndex = a.getTree().indexOf(" - ", firstIndex + 3);
                                        if (secondIndex != -1) {
                                            int thirdIndex = a.getTree().indexOf(" - ", secondIndex + 3);
                                            if (thirdIndex != -1) {
                                                result2 = a.getTree().substring(secondIndex + 3, thirdIndex);
                                            }
                                        }
                                    }
                                    if (isIf) {
                                        a.setSection(sections.get(i));
                                        a.setAsk(asks.get(i));
                                        a.setTell(tells.get(i));
                                        return true;
                                    // 判断  原辅材  包材
                                    Set<String> targetStrings = new HashSet<>();
                                    targetStrings.add("原辅材");
                                    targetStrings.add("包材");
                                    boolean isType;
                                    isType = targetStrings.contains(result2);
                                    if (isType) {
                                        if (StringUtils.isNotEmpty(modelNum)){
                                            String currentSection = sections.get(i);
                                            String sectionValue = currentSection;
                                            int equalIndex = currentSection.indexOf("=");
                                            if (equalIndex != -1) {
                                                sectionValue = currentSection.substring(equalIndex + 1);
                                            }
                                            if (modelNum.equals(sectionValue)) {
                                                a.setSection(sections.get(i));
                                                a.setAsk(asks.get(i));
                                                a.setTell(tells.get(i));
                                                return true;
                                            }
                                        }else {
                                            return false;
                                        }
                                    } else {
                                        if (sections.get(i).contains("&")) {
                                            String[] split = sections.get(i).split("&");
                                            isIf = getIsIf(split[0], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample)
                                                    && getIsIf(split[1], modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
                                        } else {
                                            isIf = getIsIf(sections.get(i), modelNum, cores.get(i), conductorMaterials.get(i), conductorTypes.get(i), insSample);
                                        }
                                        if (isIf) {
                                            a.setSection(sections.get(i));
                                            a.setAsk(asks.get(i));
                                            a.setTell(tells.get(i));
                                            return true;
                                        }
                                    }
                                }
                            }
@@ -221,18 +245,18 @@
        }
        ProductPart productPart = productPartMapper.selectOne(new LambdaQueryWrapper<ProductPart>().eq(ProductPart::getPartNo, insSample.getPartNo()));
        if (productPart != null){
            if (StringUtils.isNotEmpty(productPart.getInspectionItem())){
        if (productPart != null) {
            if (StringUtils.isNotEmpty(productPart.getInspectionItem())) {
                String inspectionItem = productPart.getInspectionItem();
                list = list.stream()
                        .filter(standardProductList -> inspectionItem.equals(standardProductList.getInspectionItem()))
                        .filter(standardProductList -> inspectionItem.contains(standardProductList.getInspectionItem()))
                        .collect(Collectors.toList());
            }
        }
        StructureTestObjectPart structureTestObjectPart = structureTestObjectPartMapper.selectOne(new LambdaQueryWrapper<StructureTestObjectPart>().eq(StructureTestObjectPart::getPartNo, insSample.getPartNo()));
        if (structureTestObjectPart != null){
            if (StringUtils.isNotEmpty(structureTestObjectPart.getInspectionItem())){
        if (structureTestObjectPart != null) {
            if (StringUtils.isNotEmpty(structureTestObjectPart.getInspectionItem())) {
                String inspectionItem = structureTestObjectPart.getInspectionItem();
                list = list.stream()
                        .filter(standardProductList -> inspectionItem.equals(standardProductList.getInspectionItem()))
@@ -243,16 +267,15 @@
    }
    /**
     *
     * @param str                 判定公式
     * @param model               型号
     * @param standardCores       芯数
     * @param conductorMaterial   导体材质
     * @param conductorType       导体类型
     * @param str               判定公式
     * @param model             型号
     * @param standardCores     芯数
     * @param conductorMaterial 导体材质
     * @param conductorType     导体类型
     * @param insSample
     * @return
     */
    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType,InsSampleReceiveDto insSample) {
    private boolean getIsIf(String str, String model, String standardCores, String conductorMaterial, String conductorType, InsSampleReceiveDto insSample) {
        Matcher matcher = Pattern.compile("\\d+(\\.\\d+)?").matcher(model);
        String model2 = "";
        while (matcher.find()) {
@@ -325,11 +348,11 @@
        boolean existWorkShopFlag = standardMethodListService.existWorkShop(tree);
        // 拼接树
        String[] trees = tree.split(" - ");
        if(trees == null && trees.length < 4){
        if (trees == null && trees.length < 4) {
            return map;
        }
        // 车间层级多一层级
        if(existWorkShopFlag){
        if (existWorkShopFlag) {
            switch (trees.length) {
                case 7:
                    sampleType = trees[4];
@@ -347,7 +370,7 @@
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\"").append("]");
                    break;
            }
        }else {
        } else {
            switch (trees.length) {
                case 6:
                    sampleType = trees[3];
@@ -366,18 +389,18 @@
                    break;
            }
        }
        if(StringUtils.isEmpty(checkItemQueryTree.toString())){
        if (StringUtils.isEmpty(checkItemQueryTree.toString())) {
            return map;
        }
        // 判断是否为委托要求标准
        StandardMethod standardMethod = standardMethodMapper.selectById(id);
        if(ObjectUtils.isEmpty(standardMethod)){
        if (ObjectUtils.isEmpty(standardMethod)) {
            return map;
        }
        StructureItemParameterDto structureItemParameterDto = new StructureItemParameterDto();
        if(standardMethod.getName().equals("委托要求")){
        if (standardMethod.getName().equals("委托要求")) {
            structureItemParameterDto.setDelegateRequestFlag("1");
        }else {
        } else {
            structureItemParameterDto.setDelegateRequestFlag("0");
        }
        structureItemParameterDto.setTree(checkItemQueryTree.toString());
@@ -385,7 +408,7 @@
        // 根据检验对象/产品查询检验项
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
        // 如果是产品的检查项为空向上推
        if(CollectionUtils.isEmpty(structureItemParameterList)){
        if (CollectionUtils.isEmpty(structureItemParameterList)) {
            String query = "[\"" + sampleType + "\"]";
            structureItemParameterDto.setTree(query);
            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
@@ -403,14 +426,14 @@
            boolean existFlag = false;
            // 判断是否已绑定
            for (StandardProductList productList : standardProductList) {
                if(structureItemParameter.getId().equals(productList.getStructureItemParameterId())) {
                if (structureItemParameter.getId().equals(productList.getStructureItemParameterId())) {
                    BeanUtils.copyProperties(productList, addStandProductList);
                    existFlag = true;
                    break;
                }
            }
            // 如果未绑定
            if(!existFlag){
            if (!existFlag) {
                BeanUtils.copyProperties(structureItemParameter, addStandProductList);
                addStandProductList.setTell(structureItemParameter.getAskTell());
                addStandProductList.setStructureItemParameterId(structureItemParameter.getId());
@@ -495,6 +518,7 @@
    /**
     * 修改标准库区间
     *
     * @param list
     * @return
     */
@@ -502,16 +526,16 @@
    public boolean updateSection(StandardProductList list) {
        // 根据id 查询到原始值
        StandardProductList standardProductList = standardProductListMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductList)){
        if (ObjectUtils.isEmpty(standardProductList)) {
            throw new RuntimeException("更新失败,未查找到检查项");
        }
        // 判断当前状态 如果是审核中
        if(StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())){
        if (StandardProductListChcekTypeEnums.CHECK_ING.getCode().equals(list.getCheckStatus())) {
            throw new RuntimeException("审核中不支持修改");
        }
        // 查询最新的一次关联备份 如果存在说明未审核完继续修改了。不做数据处理。
        StandardProductListBackupRel standardProductListBackupRel = standardProductListBackupRelMapper.selectById(list.getId());
        if(ObjectUtils.isEmpty(standardProductListBackupRel)){
        if (ObjectUtils.isEmpty(standardProductListBackupRel)) {
            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
            BeanUtils.copyProperties(standardProductList, productListBackupRel);
            standardProductListBackupRelMapper.insert(productListBackupRel);
@@ -529,6 +553,7 @@
    /**
     * 标准库拖拽
     *
     * @param resetTreeDragDTO
     */
    @Override
@@ -547,7 +572,7 @@
                    resetTreeDragDTO.getTree());
            // 从下往上
        } else if (beginIndex > endIndex){
        } else if (beginIndex > endIndex) {
            standardProductListMapper.updateSortDown(beginIndex,
                    endIndex,
                    methodId,
@@ -568,6 +593,7 @@
    /**
     * 检验项要求值对比
     *
     * @param copyDto
     * @return
     */
@@ -611,6 +637,7 @@
    /**
     * 检验项复制对比一个
     *
     * @param dto
     * @return
     */
@@ -645,6 +672,7 @@
    /**
     * 检验项复制排序
     *
     * @param copyDto
     * @return
     */
@@ -683,9 +711,9 @@
    public void productListSubmit(StandardProductListUpdateRecord standardProductListUpdateRecord) {
        // 查询所有待审核的数据
        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        List<StandardProductList> unCheckStandardProductListArray = standardProductListMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(unCheckStandardProductListArray)){
        if (CollectionUtils.isEmpty(unCheckStandardProductListArray)) {
            throw new RuntimeException("暂无修改数据");
        }
        List<Long> standardProductListIds = new ArrayList<>();
@@ -705,11 +733,12 @@
        }
        // 修改标准树下检查项状态为审核中
        standardProductListMapper.updateProductListCheckStatus(standardProductListIds,StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        standardProductListMapper.updateProductListCheckStatus(standardProductListIds, StandardProductListChcekTypeEnums.CHECK_ING.getCode());
    }
    /**
     * 标准树下检验项审核
     *
     * @param standardProductListUpdateRecord
     */
    @Override
@@ -717,9 +746,9 @@
    public void productListCheck(StandardProductListUpdateRecord standardProductListUpdateRecord) {
        // 查询所有审核中的数据
        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        List<StandardProductList> standardProductListArray = standardProductListMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(standardProductListArray)){
        if (CollectionUtils.isEmpty(standardProductListArray)) {
            return;
        }
        List<Long> standardProductListIds = new ArrayList<>();
@@ -727,12 +756,12 @@
            standardProductListIds.add(standardProductList.getId());
        }
        // 审核通过
        if(StandardProductListChcekTypeEnums.PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())){
        if (StandardProductListChcekTypeEnums.PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())) {
            // 修改状态
            standardProductListMapper.updateProductListCheckStatus(standardProductListIds,StandardProductListChcekTypeEnums.PASS_CHECK.getCode());
            standardProductListMapper.updateProductListCheckStatus(standardProductListIds, StandardProductListChcekTypeEnums.PASS_CHECK.getCode());
        }
        // 审核未通过
        if(StandardProductListChcekTypeEnums.NO_PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())){
        if (StandardProductListChcekTypeEnums.NO_PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())) {
            // 查询所有标准树下的检验项目备份数据
            List<StandardProductListBackupRel> standardProductListBackupRelList = standardProductListBackupRelMapper.selectBatchIds(standardProductListIds);
            // 回滚标准树下的检验项目数据
@@ -743,11 +772,11 @@
            }
            // 回滚检验项目厂家密度绑定表数据
            QueryWrapper<StandardProductListSupplierAskBackupRel> supplierAskBackupRelQueryWrapper = new QueryWrapper<>();
            supplierAskBackupRelQueryWrapper.in("product_list_id",standardProductListIds);
            supplierAskBackupRelQueryWrapper.in("product_list_id", standardProductListIds);
            List<StandardProductListSupplierAskBackupRel> standardProductListSupplierAskBackupRelList = standardProductListSupplierAskBackupRelMapper.selectList(supplierAskBackupRelQueryWrapper);
            if(!CollectionUtils.isEmpty(standardProductListSupplierAskBackupRelList)){
            if (!CollectionUtils.isEmpty(standardProductListSupplierAskBackupRelList)) {
                QueryWrapper<StandardProductListSupplierAsk> deleteWrapper = new QueryWrapper<>();
                deleteWrapper.in("product_list_id",standardProductListIds);
                deleteWrapper.in("product_list_id", standardProductListIds);
                standardProductListSupplierAskMapper.delete(deleteWrapper);
                ArrayList<StandardProductListSupplierAsk> supplierAskRollBackList = new ArrayList<>();
                for (StandardProductListSupplierAskBackupRel standardProductListSupplierAskBackupRel : standardProductListSupplierAskBackupRelList) {
@@ -774,11 +803,11 @@
    @Override
    public boolean existCheckingRecord() {
        QueryWrapper<StandardProductListUpdateRecord> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        queryWrapper.eq("check_status", StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        List<StandardProductListUpdateRecord> standardProductListUpdateRecordList = standardProductListUpdateRecordMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(standardProductListUpdateRecordList)){
        if (CollectionUtils.isEmpty(standardProductListUpdateRecordList)) {
            return false;
        }else {
        } else {
            return true;
        }
    }