chenrui
2025-04-08 4e5d5dbb194f097a19ad8ed0ebb8b0d2247230f3
basic-server/src/main/java/com/ruoyi/basic/service/impl/StandardProductListServiceImpl.java
@@ -1,26 +1,26 @@
package com.ruoyi.basic.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
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.StandardProductListChcekTypeEnums;
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;
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.mapper.IfsInventoryQuantityMapper;
import com.ruoyi.basic.mapper.StandardProductListMapper;
import com.ruoyi.basic.mapper.StandardProductListSupplierAskMapper;
import com.ruoyi.basic.mapper.StandardTreeMapper;
import com.ruoyi.basic.pojo.StandardProductList;
import com.ruoyi.basic.pojo.StandardProductListSupplierAsk;
import com.ruoyi.basic.pojo.StandardTree;
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;
@@ -48,54 +48,89 @@
    private StandardProductListSupplierAskMapper standardProductListSupplierAskMapper;
    private ProductPartMapper productPartMapper;
    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;
    @Autowired
    private StandardMethodMapper standardMethodMapper;
    @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("审核中不支持修改");
        }
        // 判断检验项是否为是否委托要求 是的话不需要做备份和状态修改直接更新
        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)){
            StandardProductListBackupRel productListBackupRel = new StandardProductListBackupRel();
            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);
    }
    @Override
    public List<StandardProductList> selectStandardProductList(InsSampleReceiveDto insSample) {
        // 是否没有产品
        boolean isNoSample = false;
//        String[] models = insSample.getModel().split("-(?=[^-]*$)");//拆分最后一个【-】
        String model = insSample.getModel();
        String modelNum = insSample.getModelNum();
        List<StandardProductList> list = standardProductListMapper.selectDetail(insSample.getStandardMethodListId(), 1, model, insSample.getIsCableTag());
        if (list.size() == 0) {
            if (Objects.equals(insSample.getFactory(), "") || insSample.getFactory() == null) {
                return null;
            }
            String[] split = insSample.getFactory().split(" - ");
            split[3] = split[3].replace("- ", "");
            String tree = split[0] + " - " + split[1] + " - " + split[2] + " - " + split[3] + " - null";
            list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree, insSample.getIsCableTag());
            if (list.size() == 0) {
                String tree1 = split[0] + " - " + split[1] + " - " + split[2] + " - null - " + split[3];
                list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree1, insSample.getIsCableTag());
                // 只有对象的一层
                if (list.size() == 0) {
                    String tree2 = split[0] + " - " + split[1] + " - " + split[2] + " - null - null";
                    list = standardProductListMapper.selectDetail2(insSample.getStandardMethodListId(), 1, tree2, insSample.getIsCableTag());
                    // 样品直接赋值样品分类
                    list.forEach(standardProductList -> standardProductList.setSample(standardProductList.getSampleType()));
                    isNoSample = true;
                }
            }
        // 查询检查项目
        StandardProductListDto standardProductListDto = new StandardProductListDto();
        standardProductListDto.setTree(insSample.getFactory());
        standardProductListDto.setStandardMethodListIds(insSample.getStandardMethodListIds());
        standardProductListDto.setState(insSample.getState());
        List<StandardProductList> list = new ArrayList<>();
        if(CollectionUtils.isEmpty(standardProductListDto.getStandardMethodListIds())) {
            return list;
        }
        String[] split1 = insSample.getFactory().split(" - ");
        if (!isNoSample) {
            //判断长度
            if (split1.length > 4) {
                if (ObjectUtils.isNotEmpty(split1[3])) {
                    list = list.stream().filter(list1 -> Objects.nonNull(list1.getSample()) && Objects.equals(list1.getSample(), split1[3])).collect(Collectors.toList());
                } else if (split1[3].equals("")) {
                    list = list.stream().filter(list1 -> Objects.nonNull(list1.getSampleType()) && Objects.equals(list1.getSampleType(), split1[2])).collect(Collectors.toList());
                }
            }
        }
        list = standardProductListMapper.standardProductListNoPage(standardProductListDto);
        list = list.stream().filter(a -> {
                    try {
                        if (a.getSection() != null && !Objects.equals(a.getSection(), "")) {
@@ -185,6 +220,25 @@
            }
        }
        ProductPart productPart = productPartMapper.selectOne(new LambdaQueryWrapper<ProductPart>().eq(ProductPart::getPartNo, insSample.getPartNo()));
        if (productPart != null){
            if (StringUtils.isNotEmpty(productPart.getInspectionItem())){
                String inspectionItem = productPart.getInspectionItem();
                list = list.stream()
                        .filter(standardProductList -> inspectionItem.equals(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())){
                String inspectionItem = structureTestObjectPart.getInspectionItem();
                list = list.stream()
                        .filter(standardProductList -> inspectionItem.equals(standardProductList.getInspectionItem()))
                        .collect(Collectors.toList());
            }
        }
        return list;
    }
@@ -257,208 +311,142 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> selectStandardProductListByMethodId(Integer id, String tree) {
        String sampleType = "";
        String sample = "";
        String model = "";
        StringBuilder checkItemQueryTree = new StringBuilder();   // 检查项查询 只拼接 检查对象-产品
        // 返回结果
        Map<String, Object> map = new HashMap<>();
        map.put("productList", null);
        map.put("total", 0);
        // 判断是否包含车间
        boolean existWorkShopFlag = standardMethodListService.existWorkShop(tree);
        // 拼接树
        String[] trees = tree.split(" - ");
        // 判断是否拖拽
        boolean isDrag = false;
        List<StandardProductList> list = new ArrayList<>();
        if (trees.length == 3) {
            List<StandardTree> treeList = new ArrayList<>();
            StandardTree standardTree = new StandardTree();
            standardTree.setFactory(trees[0]);
            standardTree.setLaboratory(trees[1]);
            standardTree.setSampleType(trees[2]);
            List<ProductDto> pList = standardTreeMapper.selectPList(trees[2]);
            if (pList.size() == 0 || pList.get(0) == null) {
                List<StandardTree> treeList1 = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]));
                if (treeList1.size() == 0) {
                    treeList.add(standardTree);
                } else {
                    treeList.addAll(treeList1);
                }
            } else {
                for (ProductDto p : pList) {
                    standardTree.setSample(p.getName());
                    List<StandardTree> treeList1 = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, p.getName()));
                    if (treeList1.size() == 0) {
                        treeList.add(JSON.parseObject(JSON.toJSONString(standardTree), StandardTree.class));
                    } else {
                        treeList.addAll(treeList1);
                    }
                }
            }
            for (StandardTree standardTree2 : treeList) {
                String tree2 = trees[0] + " - " + trees[1] + " - " + trees[2] + " - " + standardTree2.getSample() + " - " + standardTree2.getModel();
                list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1]));
                list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + standardTree2.getSample() + "\"", standardTree2.getSample(), standardTree2.getModel(), tree2, trees[1]));
            }
        } else if (trees.length == 4) {
            // 判断第四层是否有型号
            Long count = standardProductListMapper.selectCount(Wrappers.<StandardProductList>lambdaQuery()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .isNull(StandardProductList::getModel)
                    .like(StandardProductList::getTree, tree));
            if (count == 0) {
                isDrag = true;
            }
            isDrag = true;
            List<StandardTree> treeList = standardTreeMapper.selectList(Wrappers.<StandardTree>lambdaQuery().eq(StandardTree::getLaboratory, trees[1]).eq(StandardTree::getSampleType, trees[2]).eq(StandardTree::getSample, trees[3]));
            if (treeList.size() == 0) {
                StandardTree standardTree = new StandardTree();
                standardTree.setFactory(trees[0]);
                standardTree.setLaboratory(trees[1]);
                standardTree.setSampleType(trees[2]);
                standardTree.setSample(trees[3]);
                treeList.add(standardTree);
            }
            for (StandardTree standardTree : treeList) {
                String str = tree + " - " + standardTree.getModel();
                list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1]));
                list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", standardTree.getSample(), standardTree.getModel(), str, trees[1]));
            }
        } else {
            isDrag = true;
            list.addAll(standardTreeMapper.selectStandardProductListByTree("\"" + trees[2] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1]));
            list.addAll(standardTreeMapper.selectStandardProductListByTree2("\"" + trees[2] + "\",\"" + trees[3] + "\"", trees[3].equals("null") ? null : trees[3], trees[4], tree, trees[1]));
        if(trees == null && trees.length < 4){
            return map;
        }
        for (StandardProductList productList : list) {
            productList.setId(IdWorker.getId());
        // 车间层级多一层级
        if(existWorkShopFlag){
            switch (trees.length) {
                case 7:
                    sampleType = trees[4];
                    sample = trees[5];
                    model = trees[6];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    break;
                case 6:
                    sampleType = trees[4];
                    sample = trees[5];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\",\"").append(trees[5]).append("\"").append("]");
                    break;
                case 5:
                    sampleType = trees[4];
                    checkItemQueryTree.append("[").append("\"").append(trees[4]).append("\"").append("]");
                    break;
            }
        }else {
            switch (trees.length) {
                case 6:
                    sampleType = trees[3];
                    sample = trees[4];
                    model = trees[5];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                    break;
                case 5:
                    sampleType = trees[3];
                    sample = trees[4];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\",\"").append(trees[4]).append("\"").append("]");
                    break;
                case 4:
                    sampleType = trees[3];
                    checkItemQueryTree.append("[").append("\"").append(trees[3]).append("\"").append("]");
                    break;
            }
        }
        List<StandardProductList> standardProductLists;
        if (isDrag) {
            standardProductLists = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .like(StandardProductList::getTree, tree)
                    .orderByAsc(StandardProductList::getSort));
            // 判断是否有没有序号的, 没有序号重置
            boolean b = standardProductLists.stream().anyMatch(standardProductList -> standardProductList.getSort() == null);
        } else {
            standardProductLists = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .like(StandardProductList::getTree, tree));
        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());
        for (StandardProductList sp : standardProductLists) {
            for (StandardProductList pl : list) {
                // 判断条件是否只有一个, 有一个的话默认第一个
                String radiusList = pl.getRadiusList();
                if (StringUtils.isNotBlank(radiusList) && !radiusList.equals("null") && !radiusList.equals("\"\"")) {
                    JSONArray jsonArray = JSON.parseArray(radiusList);
                    List<String> radius = jsonArray.toJavaList(String.class);
                    if (CollectionUtils.isNotEmpty(radius) && radius.size() == 1) {
                        pl.setRadius(radius.get(0));
                    }
                }
                if (Objects.equals(sp.getInspectionItem(), pl.getInspectionItem())
                        && Objects.equals((sp.getInspectionItemSubclass() == null) ? "" : sp.getInspectionItemSubclass(), pl.getInspectionItemSubclass() == null ? "" : pl.getInspectionItemSubclass())
//                        && Objects.equals(sp.getSample(), pl.getSample())
                        && Objects.equals(sp.getModel(), pl.getModel())
                        && sp.getTree().indexOf(pl.getSample() == null ? "null" : pl.getSample()) > -1
                        && Objects.equals(sp.getStructureItemParameterId(), pl.getStructureItemParameterId())) {
                    pl.setId(sp.getId());
                    // 添加排序字段
                    pl.setSort(sp.getSort());
                    if (sp.getState() != null && !sp.getState().equals("")) {
                        pl.setState(sp.getState());
                    } else {
                        pl.setState(id == 0 ? 1 : 0);
                    }
                    if (sp.getMethodS() != null && !sp.getMethodS().equals("")) {
                        pl.setMethod(sp.getMethodS());
                    }
                    if (sp.getRadius() != null && !sp.getRadius().equals("")) {
                        pl.setRadius(sp.getRadius());
                    }
                    if (sp.getRates() != null && !sp.getRates().equals("")) {
                        pl.setRates(sp.getRates());
                    }
                    if (sp.getAsk() != null && !sp.getAsk().equals("")) {
                        pl.setAsk(sp.getAsk());
                    }
                    if (sp.getTell() != null && !sp.getTell().equals("")) {
                        pl.setTell(sp.getTell());
                    }
                    if (sp.getPrice() != null && !sp.getPrice().equals("")) {
                        pl.setPrice(sp.getPrice());
                    }
                    if (sp.getManHour() != null && !sp.getManHour().equals("")) {
                        pl.setManHour(sp.getManHour());
                    }
                    if (sp.getSection() != null && !sp.getSection().equals("")) {
                        pl.setSection(sp.getSection());
                    }
                    if (sp.getCores() != null && !sp.getCores().equals("")) {
                        pl.setCores(sp.getCores());
                    }
                    if (sp.getConductorMaterial() != null && !sp.getConductorMaterial().equals("")) {
                        pl.setConductorMaterial(sp.getConductorMaterial());
                    }
                    if (sp.getConductorType() != null && !sp.getConductorType().equals("")) {
                        pl.setConductorType(sp.getConductorType());
                    }
                    if (sp.getTemplateId() != null && !sp.getTemplateId().equals("")) {
                        pl.setTemplateId(sp.getTemplateId());
                    }
        // 根据检验对象/产品查询检验项
        List<StructureItemParameter> structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
        // 如果是产品的检查项为空向上推
        if(CollectionUtils.isEmpty(structureItemParameterList)){
            String query = "[\"" + sampleType + "\"]";
            structureItemParameterDto.setTree(query);
            structureItemParameterList = structureItemParameterMapper.selectItemParameterBySample(structureItemParameterDto);
        }
        // 查询标准库已绑定检查项目
        List<StandardProductList> standardProductList = standardProductListMapper.selectList(Wrappers.<StandardProductList>lambdaQuery()
                .eq(StandardProductList::getStandardMethodListId, id)
                .like(StandardProductList::getTree, tree)
                .orderByAsc(StandardProductList::getSort));
        // 封装参数
        List<StandardProductList> batchInsertStandardProductListArray = new ArrayList<>();
        for (StructureItemParameter structureItemParameter : structureItemParameterList) {
            StandardProductList addStandProductList = new StandardProductList();
            boolean existFlag = false;
            // 判断是否已绑定
            for (StandardProductList productList : standardProductList) {
                if(structureItemParameter.getId().equals(productList.getStructureItemParameterId())) {
                    BeanUtils.copyProperties(productList, addStandProductList);
                    existFlag = true;
                    break;
                }
            }
        }
            // 如果未绑定
            if(!existFlag){
                BeanUtils.copyProperties(structureItemParameter, addStandProductList);
                addStandProductList.setStructureItemParameterId(structureItemParameter.getId());
        Integer userId = SecurityUtils.getUserId().intValue();
        if (trees.length == 5) {
            standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .eq(StandardProductList::getTree, tree));
        } else {
            standardProductListMapper.delete(Wrappers.<StandardProductList>lambdaUpdate()
                    .eq(StandardProductList::getStandardMethodListId, id)
                    .like(StandardProductList::getTree, tree));
        }
        List<StandardProductList> productLists = list.stream().map(a -> {
            a.setFactory(trees[0]);
            a.setLaboratory(trees[1]);
            a.setSampleType(trees[2]);
            a.setCreateUser(userId);
            a.setUpdateUser(userId);
            a.setStandardMethodListId(id);
            return a;
        }).collect(Collectors.toList());
//            this.saveBatch(productLists);
        // 批量添加标准
        baseMapper.saveBatchProductLists(productLists);
        Collections.sort(list, (o1, o2) -> {
            String field1 = o1.getManHourGroup();
            String field2 = o2.getManHourGroup();
            boolean isEmpty1 = field1 == null || field1.isEmpty();
            boolean isEmpty2 = field2 == null || field2.isEmpty();
            if (isEmpty1 && isEmpty2) {
                return 0;
            } else if (isEmpty1) {
                return 1;
            } else if (isEmpty2) {
                return -1;
            } else {
                int num1 = extractNumber(field1);
                int num2 = extractNumber(field2);
                return Integer.compare(num1, num2);
            }
        });
          // 按照索引排序
        if (isDrag) {
            list.sort((o1, o2) -> (o1.getSort() == null ? 0 : o1.getSort())
                    - (o2.getSort() == null ? 0 : o2.getSort()));
        }
            addStandProductList.setId(addStandProductList.getId() != null ? addStandProductList.getId() : IdWorker.getId());
            batchInsertStandardProductListArray.add(addStandProductList);
        Map<String, Object> map = new HashMap<>();
        map.put("productList", list);
        map.put("total", list.size());
        }
        // 排序处理 已有顺序按照原顺序 没有顺序的按照检验项的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));
        for (int i = 0; i < batchInsertStandardProductListArray.size(); i++) {
            StandardProductList productList = batchInsertStandardProductListArray.get(i);
            productList.setTree(tree);
            productList.setFactory(trees[0]);
            productList.setLaboratory(trees[1]);
            productList.setSampleType(sampleType);
            productList.setSample(sample);
            productList.setModel(model);
            productList.setCreateUser(SecurityUtils.getUserId().intValue());
            productList.setUpdateUser(SecurityUtils.getUserId().intValue());
            productList.setStandardMethodListId(id);
            productList.setSort(i);
        }
        // 批量添加标准
        if (CollectionUtils.isNotEmpty(batchInsertStandardProductListArray)) {
            baseMapper.saveBatchProductLists(batchInsertStandardProductListArray);
        }
        map.put("productList", batchInsertStandardProductListArray);
        map.put("total", batchInsertStandardProductListArray.size());
        return map;
    }
@@ -511,6 +499,28 @@
     */
    @Override
    public boolean updateSection(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);
        }
        // 关联商家备份
        StandardProductListSupplierAsk standardProductListSupplierAsk = new StandardProductListSupplierAsk();
        standardProductListSupplierAsk.setProductListId(list.getId());
        standardProductListSupplierAskService.backupSupplierAsk(standardProductListSupplierAsk);
        // 修改状态
        list.setCheckStatus(StandardProductListChcekTypeEnums.WAIT_CHECK.getCode());
        standardProductListMapper.updateSection(list);
        return true;
    }
@@ -663,6 +673,114 @@
        this.updateBatchById(productLists);
        return false;
    }
    /**
     * 标准树下检验项提交
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void productListSubmit(StandardProductListUpdateRecord standardProductListUpdateRecord) {
        // 查询所有待审核的数据
        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);
        // 插入修改记录关联表
        List<StandardProductListUpdateRecordRel> standardProductListUpdateRecordRelList = new ArrayList<>();
        for (StandardProductList standardProductList : unCheckStandardProductListArray) {
            StandardProductListUpdateRecordRel standardProductListUpdateRecordRel = new StandardProductListUpdateRecordRel();
            BeanUtils.copyProperties(standardProductList, standardProductListUpdateRecordRel);
            standardProductListUpdateRecordRel.setId(null);
            standardProductListUpdateRecordRel.setStandardProductListId(standardProductList.getId());
            standardProductListUpdateRecordRel.setStandardProductListUpdateRecordId(standardProductListUpdateRecord.getId());
            standardProductListUpdateRecordRelList.add(standardProductListUpdateRecordRel);
            standardProductListUpdateRecordRelMapper.insert(standardProductListUpdateRecordRel);
            standardProductListIds.add(standardProductList.getId());
        }
        // 修改标准树下检查项状态为审核中
        standardProductListMapper.updateProductListCheckStatus(standardProductListIds,StandardProductListChcekTypeEnums.CHECK_ING.getCode());
    }
    /**
     * 标准树下检验项审核
     * @param standardProductListUpdateRecord
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void productListCheck(StandardProductListUpdateRecord standardProductListUpdateRecord) {
        // 查询所有审核中的数据
        QueryWrapper<StandardProductList> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("check_status",StandardProductListChcekTypeEnums.CHECK_ING.getCode());
        List<StandardProductList> standardProductListArray = standardProductListMapper.selectList(queryWrapper);
        if(CollectionUtils.isEmpty(standardProductListArray)){
            return;
        }
        List<Long> standardProductListIds = new ArrayList<>();
        for (StandardProductList standardProductList : standardProductListArray) {
            standardProductListIds.add(standardProductList.getId());
        }
        // 审核通过
        if(StandardProductListChcekTypeEnums.PASS_CHECK.getCode().equals(standardProductListUpdateRecord.getCheckStatus())){
            // 修改状态
            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);
                standardProductListMapper.updateById(standardProductList);
            }
            // 回滚检验项目厂家密度绑定表数据
            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;
        }
    }
}