| | |
| | | import com.gkhy.exam.common.utils.PageUtils; |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.system.domain.InternalAuditCheck; |
| | | import com.gkhy.exam.system.domain.InternalAuditCheckCatalogue; |
| | | import com.gkhy.exam.system.domain.InternalAuditCheckContent; |
| | | import com.gkhy.exam.system.domain.InternalAuditCheckPerson; |
| | | import com.gkhy.exam.system.domain.vo.InternalAuditCheckVo; |
| | | import com.gkhy.exam.system.mapper.InternalAuditCheckMapper; |
| | | import com.gkhy.exam.system.mapper.InternalAuditCheckPersonMapper; |
| | | import com.gkhy.exam.system.mapper.SysDeptMapper; |
| | | import com.gkhy.exam.system.mapper.SysUserMapper; |
| | | import com.gkhy.exam.system.mapper.*; |
| | | import com.gkhy.exam.system.service.InternalAuditCheckService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | 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.stream.Collectors; |
| | | |
| | |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckMapper internalAuditCheckMapper; |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckPersonMapper internalAuditCheckPersonMapper; |
| | | private InternalAuditCheckCatalogueMapper checkCatalogueMapper; |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckContentMapper checkContentMapper; |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | @Autowired |
| | |
| | | public CommonPage selectInternalAuditCheckList(Integer companyId) { |
| | | PageUtils.startPage(); |
| | | List<InternalAuditCheck> internalAuditChecks = internalAuditCheckMapper.selectInternalAuditCheckList(companyId); |
| | | if (!CollectionUtils.isEmpty(internalAuditChecks)) { |
| | | batchLoadCheckDetails(internalAuditChecks); |
| | | } |
| | | return CommonPage.restPage(internalAuditChecks); |
| | | } |
| | | |
| | | private void batchLoadCheckDetails(List<InternalAuditCheck> checks) { |
| | | //收集所有检查ID |
| | | List<Integer> checkIds = checks.stream() |
| | | .map(InternalAuditCheck::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | //批量查询所有目录 |
| | | List<InternalAuditCheckCatalogue> allCatalogues = checkCatalogueMapper.selectByCheckIds(checkIds); |
| | | |
| | | if (CollectionUtils.isEmpty(allCatalogues)) { |
| | | return; |
| | | } |
| | | |
| | | //收集所有目录ID |
| | | List<Integer> catalogueIds = allCatalogues.stream() |
| | | .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(InternalAuditCheckVo internalAuditCheck) { |
| | | InternalAuditCheck internalAuditCheck1 = new InternalAuditCheck(); |
| | | BeanUtils.copyProperties(internalAuditCheck,internalAuditCheck1); |
| | | internalAuditCheck1.setCreateTime(LocalDateTime.now()); |
| | | internalAuditCheck1.setCreateBy(SecurityUtils.getUsername()); |
| | | |
| | | int insert = internalAuditCheckMapper.insert(internalAuditCheck1); |
| | | if (insert > 0) { |
| | | if (ObjectUtil.isNotEmpty(internalAuditCheck.getInternalAuditCheckPeople())){ |
| | | batchInsert(internalAuditCheck.getInternalAuditCheckPeople(),internalAuditCheck1.getId()); |
| | | public CommonResult insertInternalAuditCheck(InternalAuditCheck internalAuditCheck) { |
| | | internalAuditCheck.setCreateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheck.setCreateTime(LocalDateTime.now()); |
| | | int insert = internalAuditCheckMapper.insert(internalAuditCheck); |
| | | if (insert <= 0) { |
| | | return CommonResult.failed("新增内审检查失败"); |
| | | } |
| | | //处理目录和内容的插入 |
| | | List<InternalAuditCheckCatalogue> checkCatalogues = internalAuditCheck.getCheckCatalogues(); |
| | | if (CollectionUtils.isEmpty(checkCatalogues)) { |
| | | return CommonResult.success(); |
| | | } |
| | | return CommonResult.failed(); |
| | | //批量处理目录和内容 |
| | | batchInsertCataloguesAndContents(internalAuditCheck.getId(), checkCatalogues); |
| | | return CommonResult.success(); |
| | | |
| | | } |
| | | |
| | | private void batchInsert(List<InternalAuditCheckPerson> internalAuditCheckPeople,Long auditId) { |
| | | internalAuditCheckPeople.forEach(e -> { |
| | | e.setAuditId(auditId); |
| | | e.setCreateTime(LocalDateTime.now()); |
| | | e.setCreateBy(SecurityUtils.getUsername()); |
| | | }); |
| | | internalAuditCheckPersonMapper.batchInsert(internalAuditCheckPeople); |
| | | private void batchInsertCataloguesAndContents(Integer checkId, List<InternalAuditCheckCatalogue> catalogues) { |
| | | // 1. 设置目录的检查ID并批量插入 |
| | | for (InternalAuditCheckCatalogue catalogue : catalogues) { |
| | | catalogue.setCheckId(checkId); |
| | | } |
| | | |
| | | private void batchUpdate(List<InternalAuditCheckPerson> internalAuditCheckPeople) { |
| | | internalAuditCheckPeople.forEach(e -> { |
| | | e.setUpdateTime(LocalDateTime.now()); |
| | | e.setUpdateBy(SecurityUtils.getUsername()); |
| | | }); |
| | | internalAuditCheckPersonMapper.batchUpdate(internalAuditCheckPeople); |
| | | // 批量插入目录 |
| | | int catalogueInsertCount = checkCatalogueMapper.insertBatch(catalogues); |
| | | if (catalogueInsertCount != catalogues.size()) { |
| | | throw new RuntimeException("插入目录记录数量不匹配"); |
| | | } |
| | | |
| | | // 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 |
| | | public CommonResult updateInternalAuditCheck(InternalAuditCheckVo internalAuditCheck) { |
| | | InternalAuditCheck internalAuditCheck1 = new InternalAuditCheck(); |
| | | BeanUtils.copyProperties(internalAuditCheck,internalAuditCheck1); |
| | | internalAuditCheck1.setUpdateTime(LocalDateTime.now()); |
| | | internalAuditCheck1.setUpdateBy(SecurityUtils.getUsername()); |
| | | |
| | | int update = internalAuditCheckMapper.updateById(internalAuditCheck1); |
| | | public CommonResult updateInternalAuditCheck(InternalAuditCheck internalAuditCheck) { |
| | | internalAuditCheck.setUpdateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheck.setUpdateTime(LocalDateTime.now()); |
| | | int update = internalAuditCheckMapper.updateById(internalAuditCheck); |
| | | if (update > 0) { |
| | | List<InternalAuditCheckPerson> internalAuditCheckPeople = internalAuditCheck.getInternalAuditCheckPeople(); |
| | | if (ObjectUtil.isNotEmpty(internalAuditCheckPeople)){ |
| | | Set<Long> collect = internalAuditCheckPeople.stream().map(InternalAuditCheckPerson::getAuditUserId) |
| | | .collect(Collectors.toSet()); |
| | | if (collect.size() != internalAuditCheckPeople.size()){ |
| | | throw new ApiException("受审人员重复"); |
| | | } |
| | | LambdaQueryWrapper<InternalAuditCheckPerson> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getAuditId, internalAuditCheck.getId()); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getDelFlag, 0); |
| | | List<InternalAuditCheckPerson> internalAuditCheckPeople1 = internalAuditCheckPersonMapper.selectList(queryWrapper); |
| | | checkCatalogueMapper.updatebyCheckId(internalAuditCheck.getId()); |
| | | |
| | | List<Long> idsAll = internalAuditCheckPeople1.stream() |
| | | .map(InternalAuditCheckPerson::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | |
| | | List<Long> idsUpdate = internalAuditCheckPeople.stream() |
| | | .map(InternalAuditCheckPerson::getId) |
| | | .filter(id -> id != null) // 过滤掉 null 值 |
| | | .collect(Collectors.toList()); |
| | | if (!idsUpdate.isEmpty() && !idsAll.isEmpty()){ |
| | | //不存在的删除 |
| | | List<Long> result = idsAll.stream() |
| | | .filter(id -> !idsUpdate.contains(id)) |
| | | .collect(Collectors.toList()); |
| | | if (!result.isEmpty()){ |
| | | batchDel(internalAuditCheck.getId(),result); |
| | | } |
| | | List<InternalAuditCheckCatalogue> checkCatalogues = internalAuditCheck.getCheckCatalogues(); |
| | | if (CollectionUtils.isEmpty(checkCatalogues)) { |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | |
| | | |
| | | List<InternalAuditCheckPerson> withId = internalAuditCheckPeople.stream() |
| | | .filter(e -> e.getId() != null) |
| | | .collect(Collectors.toList()); |
| | | //修改的 |
| | | if (!withId.isEmpty()){ |
| | | batchUpdate(withId); |
| | | } |
| | | |
| | | List<InternalAuditCheckPerson> withoutId = internalAuditCheckPeople.stream() |
| | | .filter(e -> e.getId() == null) |
| | | .collect(Collectors.toList()); |
| | | |
| | | //新增的 |
| | | if (!withoutId.isEmpty()){ |
| | | batchInsert(withoutId,internalAuditCheck.getId()); |
| | | } |
| | | }else { |
| | | batchDel(internalAuditCheck.getId(),null); |
| | | } |
| | | |
| | | |
| | | return CommonResult.success(update); |
| | | batchInsertCataloguesAndContents(internalAuditCheck.getId(), checkCatalogues); |
| | | return CommonResult.success(); |
| | | } |
| | | return CommonResult.failed(); |
| | | } |
| | | |
| | | private void batchDel(Long id,List<Long> ids){ |
| | | LambdaQueryWrapper<InternalAuditCheckPerson> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getAuditId, id); |
| | | if (ObjectUtil.isNotEmpty(ids)){ |
| | | queryWrapper.in(InternalAuditCheckPerson::getId, ids); |
| | | } |
| | | InternalAuditCheckPerson internalAuditCheckPerson = new InternalAuditCheckPerson(); |
| | | internalAuditCheckPerson.setDelFlag(1); |
| | | internalAuditCheckPerson.setUpdateTime(LocalDateTime.now()); |
| | | internalAuditCheckPerson.setUpdateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheckPersonMapper.update(internalAuditCheckPerson,queryWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public CommonResult deletedInternalAuditCheck(Integer id) { |
| | | int delete = internalAuditCheckMapper.deleteById(id); |
| | | LambdaQueryWrapper<InternalAuditCheckPerson> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getAuditId, id); |
| | | InternalAuditCheckPerson internalAuditCheckPerson = new InternalAuditCheckPerson(); |
| | | internalAuditCheckPerson.setDelFlag(1); |
| | | internalAuditCheckPerson.setUpdateTime(LocalDateTime.now()); |
| | | internalAuditCheckPerson.setUpdateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheckPersonMapper.update(internalAuditCheckPerson,queryWrapper); |
| | | InternalAuditCheck internalAuditCheck = new InternalAuditCheck(); |
| | | internalAuditCheck.setId(id); |
| | | internalAuditCheck.setUpdateBy(SecurityUtils.getUsername()); |
| | | internalAuditCheck.setUpdateTime(LocalDateTime.now()); |
| | | internalAuditCheck.setDelFlag(2); |
| | | int update = internalAuditCheckMapper.updateById(internalAuditCheck); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | public CommonResult internalAuditCheckInfo(Integer id) { |
| | | InternalAuditCheck internalAuditCheck = internalAuditCheckMapper.selectById(id); |
| | | |
| | | InternalAuditCheckVo internalAuditCheckVo = new InternalAuditCheckVo(); |
| | | BeanUtils.copyProperties(internalAuditCheck,internalAuditCheckVo); |
| | | internalAuditCheckVo.setDeptName(sysDeptMapper.selectDeptById(internalAuditCheck.getDeptId()).getDeptName()); |
| | | internalAuditCheckVo.setAuditName(sysUserMapper.selectById(internalAuditCheck.getAuditId()).getName()); |
| | | LambdaQueryWrapper<InternalAuditCheckPerson> queryWrapper = new LambdaQueryWrapper<>(); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getAuditId, id); |
| | | queryWrapper.eq(InternalAuditCheckPerson::getDelFlag, 0); |
| | | List<InternalAuditCheckPerson> internalAuditCheckPeople = internalAuditCheckPersonMapper.selectList(queryWrapper); |
| | | internalAuditCheckVo.setInternalAuditCheckPeople(internalAuditCheckPeople); |
| | | |
| | | return CommonResult.success(internalAuditCheckVo); |
| | | } |
| | | // @Override |
| | | // public CommonResult internalAuditCheckInfo(Integer id) { |
| | | // InternalAuditCheck internalAuditCheck = internalAuditCheckMapper.selectById(id); |
| | | // |
| | | // InternalAuditCheckVo internalAuditCheckVo = new InternalAuditCheckVo(); |
| | | // BeanUtils.copyProperties(internalAuditCheck,internalAuditCheckVo); |
| | | // internalAuditCheckVo.setDeptName(sysDeptMapper.selectDeptById(internalAuditCheck.getDeptId()).getDeptName()); |
| | | // internalAuditCheckVo.setAuditName(sysUserMapper.selectById(internalAuditCheck.getAuditId()).getName()); |
| | | // LambdaQueryWrapper<InternalAuditCheckPerson> queryWrapper = new LambdaQueryWrapper<>(); |
| | | // queryWrapper.eq(InternalAuditCheckPerson::getAuditId, id); |
| | | // queryWrapper.eq(InternalAuditCheckPerson::getDelFlag, 0); |
| | | // List<InternalAuditCheckPerson> internalAuditCheckPeople = internalAuditCheckPersonMapper.selectList(queryWrapper); |
| | | // internalAuditCheckVo.setInternalAuditCheckPeople(internalAuditCheckPeople); |
| | | // |
| | | // return CommonResult.success(internalAuditCheckVo); |
| | | // } |
| | | } |