| | |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | .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)); |
| | |
| | | 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); |
| | | } |
| | | } |
| | |
| | | @Override |
| | | @Transactional |
| | | public CommonResult insertInternalAuditCheck(InternalAuditCheck internalAuditCheck) { |
| | | |
| | | Map<String, Object> stringObjectHashMap = new HashMap<>(); |
| | | stringObjectHashMap.put("dept_id",internalAuditCheck.getDeptId()); |
| | | stringObjectHashMap.put("year",internalAuditCheck.getYear()); |
| | | stringObjectHashMap.put("company_id",internalAuditCheck.getCompanyId()); |
| | | stringObjectHashMap.put("del_flag",0); |
| | | List<InternalAuditCheck> internalAuditChecks = internalAuditCheckMapper.selectByMap(stringObjectHashMap); |
| | | if (!CollectionUtils.isEmpty(internalAuditChecks)){ |
| | | return CommonResult.failed("当前部门存在,请勿重复添加"); |
| | | } |
| | | |
| | | internalAuditCheck.setCreateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheck.setCreateTime(LocalDateTime.now()); |
| | | int insert = internalAuditCheckMapper.insert(internalAuditCheck); |
| | |
| | | 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 |
| | |
| | | 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(); |
| | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult updateByYearAndDeptId(InternalAuditCheck internalAuditCheck) { |
| | | |
| | | internalAuditCheck.setUpdateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheck.setUpdateTime(LocalDateTime.now()); |
| | | Integer update = internalAuditCheckMapper.updateByYearAndDeptId(internalAuditCheck); |
| | | if (update>0){ |
| | | checkCatalogueMapper.updatebyCheckId(internalAuditCheck.getId()); |
| | | List<InternalAuditCheckCatalogue> checkCatalogues = internalAuditCheck.getCheckCatalogues(); |
| | | for (InternalAuditCheckCatalogue catalogue : checkCatalogues) { |
| | | catalogue.setCheckId(internalAuditCheck.getId()); |
| | | } |
| | | |
| | | // 批量插入目录 |
| | | int catalogueInsertCount = checkCatalogueMapper.saveBatch(checkCatalogues); |
| | | |
| | | if (catalogueInsertCount != checkCatalogues.size()) { |
| | | throw new RuntimeException("插入目录记录数量不匹配"); |
| | | } |
| | | } |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public List<InternalAuditCheck> selectByMap(Map<String, Object> stringObjectHashMap) { |
| | | return internalAuditCheckMapper.selectByMap(stringObjectHashMap); |
| | | } |
| | | |
| | | // @Override |
| | | // public CommonResult internalAuditCheckInfo(Integer id) { |
| | | // InternalAuditCheck internalAuditCheck = internalAuditCheckMapper.selectById(id); |