“djh”
2025-12-03 e32ac074e0cdc07b7551155e2e1c24684857f2b7
multi-system/src/main/java/com/gkhy/exam/system/service/impl/InternalAuditCheckServiceImpl.java
@@ -79,13 +79,6 @@
                .map(InternalAuditCheckCatalogue::getId)
                .collect(Collectors.toList());
        //批量查询所有内容
        List<InternalAuditCheckContent> allContents = checkContentMapper.selectByCatalogueIds(catalogueIds);
        //按目录ID分组内容
        Map<Integer, List<InternalAuditCheckContent>> contentMap = allContents.stream()
                .collect(Collectors.groupingBy(InternalAuditCheckContent::getCheckCatalogueId));
        //按检查ID分组目录
        Map<Integer, List<InternalAuditCheckCatalogue>> catalogueMap = allCatalogues.stream()
                .collect(Collectors.groupingBy(InternalAuditCheckCatalogue::getCheckId));
@@ -94,10 +87,6 @@
        for (InternalAuditCheck check : checks) {
            List<InternalAuditCheckCatalogue> catalogues = catalogueMap.get(check.getId());
            if (!CollectionUtils.isEmpty(catalogues)) {
                for (InternalAuditCheckCatalogue catalogue : catalogues) {
                    List<InternalAuditCheckContent> contents = contentMap.get(catalogue.getId());
                    catalogue.setCheckContents(contents != null ? contents : new ArrayList<>());
                }
                check.setCheckCatalogues(catalogues);
            }
        }
@@ -117,7 +106,6 @@
            return CommonResult.failed("当前部门存在,请勿重复添加");
        }
        internalAuditCheck.setCreateBy(SecurityUtils.getUsername());
        internalAuditCheck.setCreateTime(LocalDateTime.now());
        int insert = internalAuditCheckMapper.insert(internalAuditCheck);
@@ -130,44 +118,18 @@
            return CommonResult.success();
        }
        //批量处理目录和内容
        batchInsertCataloguesAndContents(internalAuditCheck.getId(), checkCatalogues);
        return CommonResult.success();
    }
    private void batchInsertCataloguesAndContents(Integer checkId, List<InternalAuditCheckCatalogue> catalogues) {
        // 1. 设置目录的检查ID并批量插入
        for (InternalAuditCheckCatalogue catalogue : catalogues) {
            catalogue.setCheckId(checkId);
        for (InternalAuditCheckCatalogue catalogue : checkCatalogues) {
            catalogue.setCheckId(internalAuditCheck.getId());
        }
        // 批量插入目录
        int catalogueInsertCount = checkCatalogueMapper.insertBatch(catalogues);
        if (catalogueInsertCount != catalogues.size()) {
        int catalogueInsertCount = checkCatalogueMapper.insertBatch(checkCatalogues);
        if (catalogueInsertCount != checkCatalogues.size()) {
            throw new RuntimeException("插入目录记录数量不匹配");
        }
        return CommonResult.success();
        // 2. 收集所有内容并设置目录ID
        List<InternalAuditCheckContent> allContents = new ArrayList<>();
        for (int i = 0; i < catalogues.size(); i++) {
            InternalAuditCheckCatalogue catalogue = catalogues.get(i);
            List<InternalAuditCheckContent> contents = catalogue.getCheckContents();
            if (!CollectionUtils.isEmpty(contents)) {
                for (InternalAuditCheckContent content : contents) {
                    content.setCheckCatalogueId(catalogue.getId());
                }
                allContents.addAll(contents);
            }
        }
        // 3. 批量插入内容
        if (!CollectionUtils.isEmpty(allContents)) {
            int contentInsertCount = checkContentMapper.insertBatchs(allContents);
            if (contentInsertCount != allContents.size()) {
                throw new RuntimeException("插入内容记录数量不匹配");
            }
        }
    }
    @Override
@@ -176,14 +138,17 @@
        internalAuditCheck.setUpdateTime(LocalDateTime.now());
        int update = internalAuditCheckMapper.updateById(internalAuditCheck);
        if (update>0){
            checkCatalogueMapper.updatebyCheckId(internalAuditCheck.getId());
            List<InternalAuditCheckCatalogue> checkCatalogues = internalAuditCheck.getCheckCatalogues();
            if (CollectionUtils.isEmpty(checkCatalogues)) {
                return CommonResult.success();
            }
            for (InternalAuditCheckCatalogue catalogue : checkCatalogues) {
                catalogue.setCheckId(internalAuditCheck.getId());
            }
            batchInsertCataloguesAndContents(internalAuditCheck.getId(), checkCatalogues);
            // 批量插入目录
             checkCatalogueMapper.updateCheckCatalogues(checkCatalogues);
            return CommonResult.success();
        }
        return CommonResult.failed();
@@ -210,7 +175,16 @@
        if (update>0){
            checkCatalogueMapper.updatebyCheckId(internalAuditCheck.getId());
            List<InternalAuditCheckCatalogue> checkCatalogues = internalAuditCheck.getCheckCatalogues();
            batchInsertCataloguesAndContents(internalAuditCheck.getId(), checkCatalogues);
            for (InternalAuditCheckCatalogue catalogue : checkCatalogues) {
                catalogue.setCheckId(internalAuditCheck.getId());
            }
            // 批量插入目录
            int catalogueInsertCount = checkCatalogueMapper.saveBatch(checkCatalogues);
            if (catalogueInsertCount != checkCatalogues.size()) {
                throw new RuntimeException("插入目录记录数量不匹配");
            }
        }
        return CommonResult.success();
    }