| | |
| | | package com.gkhy.exam.system.service.impl; |
| | | |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | |
| | | import com.gkhy.exam.common.exception.ApiException; |
| | | import com.gkhy.exam.common.utils.PageUtils; |
| | | import com.gkhy.exam.common.utils.SecurityUtils; |
| | | import com.gkhy.exam.system.domain.InternalAuditCarry; |
| | | import com.gkhy.exam.system.domain.InternalAuditCarryDept; |
| | | import com.gkhy.exam.system.domain.*; |
| | | import com.gkhy.exam.system.domain.vo.DeptDetialVo; |
| | | import com.gkhy.exam.system.mapper.InternalAuditCarryMapper; |
| | | import com.gkhy.exam.system.mapper.InternalAuditCheckCatalogueMapper; |
| | | import com.gkhy.exam.system.mapper.InternalAuditCheckContentMapper; |
| | | import com.gkhy.exam.system.mapper.SysClauseManagementMapper; |
| | | import com.gkhy.exam.system.service.ExStudentService; |
| | | import com.gkhy.exam.system.service.InternalAuditCarryService; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import com.gkhy.exam.system.service.InternalAuditCheckService; |
| | | 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.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.LocalTime; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class InternalAuditCarryServiceImpl extends ServiceImpl<InternalAuditCarryMapper, InternalAuditCarry> implements InternalAuditCarryService { |
| | |
| | | |
| | | @Autowired |
| | | private InternalAuditCarryMapper carryMapper; |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckService internalAuditCheckService; |
| | | |
| | | @Autowired |
| | | private SysClauseManagementMapper sysClauseManagementMapper; |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckCatalogueMapper checkCatalogueMapper; |
| | | |
| | | @Autowired |
| | | private InternalAuditCheckContentMapper checkContentMapper; |
| | | |
| | | @Autowired |
| | | private SysDeptServiceImpl sysDeptService; |
| | | |
| | | @Override |
| | | public CommonPage selectCarryList(InternalAuditCarry carry) { |
| | |
| | | .eq(InternalAuditCarry::getYear, carry.getYear()) |
| | | .eq(InternalAuditCarry::getDelFlag,1)); |
| | | if (internalAuditCarries.size()>0){ |
| | | throw new ApiException("当前企业已有相关数据"); |
| | | return CommonResult.failed("当前企业已有相关数据"); |
| | | } |
| | | carry.setCreateBy(SecurityUtils.getUsername()); |
| | | carry.setCreateTime(LocalDateTime.now()); |
| | |
| | | internalAuditCarryDept.setCarryId(carry.getId()); |
| | | } |
| | | carryMapper.insertCarryDept(deptList); |
| | | |
| | | saveInternalAuditCheck(carry); |
| | | |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | private CommonResult saveInternalAuditCheck(InternalAuditCarry carry) { |
| | | // 2. 空指针防护:避免deptList为null导致循环NPE |
| | | List<InternalAuditCarryDept> deptList = carry.getDeptList(); |
| | | if (CollectionUtils.isEmpty(deptList)) { |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | for (InternalAuditCarryDept internalAuditCarryDept : deptList) { |
| | | // 3. 跳过空的部门项,避免后续NPE |
| | | if (internalAuditCarryDept == null) { |
| | | continue; |
| | | } |
| | | |
| | | InternalAuditCheck internalAuditCheck = new InternalAuditCheck(); |
| | | // 基础字段赋值(保留原逻辑,无改动) |
| | | internalAuditCheck.setCompanyId(carry.getCompanyId()); |
| | | internalAuditCheck.setYear(carry.getYear()); |
| | | internalAuditCheck.setDeptId(internalAuditCarryDept.getDeptId()); |
| | | internalAuditCheck.setPersonId(internalAuditCarryDept.getCheckId()); |
| | | internalAuditCheck.setCheckTime(internalAuditCarryDept.getDate()); |
| | | |
| | | // 4. 时间字段安全赋值:避免date/startTime/endTime为null导致atTime()报错 |
| | | LocalDate checkDate = internalAuditCarryDept.getDate(); |
| | | LocalTime startTime = internalAuditCarryDept.getStartTime(); |
| | | LocalTime endTime = internalAuditCarryDept.getEndTime(); |
| | | if (checkDate != null && startTime != null) { |
| | | internalAuditCheck.setStartTime(checkDate.atTime(startTime)); |
| | | } |
| | | if (checkDate != null && endTime != null) { |
| | | internalAuditCheck.setEndTime(checkDate.atTime(endTime)); |
| | | } |
| | | |
| | | // 查询结果空防护:避免deptDetialVo为null导致后续getSysDeptResponsibilitys()报错 |
| | | DeptDetialVo deptDetialVo = sysDeptService.selectDeptById(Long.valueOf(internalAuditCarryDept.getDeptId())); |
| | | if (deptDetialVo == null) { |
| | | continue; |
| | | } |
| | | |
| | | List<SysDeptResponsibility> sysDeptResponsibilitys = deptDetialVo.getSysDeptResponsibilitys(); |
| | | List<InternalAuditCheckCatalogue> internalAuditCheckCatalogues = new ArrayList<>(); |
| | | // 7. 责任项列表空防护:避免循环null集合 |
| | | if (!CollectionUtils.isEmpty(sysDeptResponsibilitys)) { |
| | | for (SysDeptResponsibility sysDeptResponsibility : sysDeptResponsibilitys) { |
| | | if (sysDeptResponsibility == null) { |
| | | continue; |
| | | } |
| | | |
| | | InternalAuditCheckCatalogue internalAuditCheckCatalogue = new InternalAuditCheckCatalogue(); |
| | | // 8. clauseId安全转换:避免null导致Math.toIntExact()报错 |
| | | Long clauseId = sysDeptResponsibility.getClauseId(); |
| | | |
| | | // 9. 条款查询结果空防护:避免sysClauseManagement为null导致getPoints()报错 |
| | | SysClauseManagement sysClauseManagement = sysClauseManagementMapper.selectById(clauseId); |
| | | if (sysClauseManagement == null) { |
| | | continue; |
| | | } |
| | | internalAuditCheckCatalogue.setCatalogueId(Math.toIntExact(clauseId)); |
| | | internalAuditCheckCatalogue.setPointKey(sysClauseManagement.getPoints()); |
| | | internalAuditCheckCatalogues.add(internalAuditCheckCatalogue); |
| | | } |
| | | } |
| | | |
| | | internalAuditCheck.setCheckCatalogues(internalAuditCheckCatalogues); |
| | | |
| | | internalAuditCheckService.insertInternalAuditCheck(internalAuditCheck); |
| | | } |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | |
| | | } |
| | | Integer i = carryMapper.deletedCarryDeptByCarryId(carry.getId()); |
| | | carryMapper.insertCarryDept(deptList); |
| | | |
| | | updateInternalAuditCheck(carry); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | private CommonResult updateInternalAuditCheck(InternalAuditCarry carry) { |
| | | List<InternalAuditCarryDept> deptList = carry.getDeptList(); |
| | | if (CollectionUtils.isEmpty(deptList)) { |
| | | return CommonResult.success(); |
| | | } |
| | | for (InternalAuditCarryDept internalAuditCarryDept : deptList) { |
| | | if (internalAuditCarryDept == null) { |
| | | continue; |
| | | } |
| | | InternalAuditCheck internalAuditCheck = new InternalAuditCheck(); |
| | | internalAuditCheck.setCompanyId(carry.getCompanyId()); |
| | | internalAuditCheck.setYear(carry.getYear()); |
| | | internalAuditCheck.setDeptId(internalAuditCarryDept.getDeptId()); |
| | | internalAuditCheck.setPersonId(internalAuditCarryDept.getCheckId()); |
| | | internalAuditCheck.setCheckTime(internalAuditCarryDept.getDate()); |
| | | LocalDate checkDate = internalAuditCarryDept.getDate(); |
| | | LocalTime startTime = internalAuditCarryDept.getStartTime(); |
| | | LocalTime endTime = internalAuditCarryDept.getEndTime(); |
| | | if (checkDate != null && startTime != null) { |
| | | internalAuditCheck.setStartTime(checkDate.atTime(startTime)); |
| | | } |
| | | if (checkDate != null && endTime != null) { |
| | | internalAuditCheck.setEndTime(checkDate.atTime(endTime)); |
| | | } |
| | | // 6. 查询部门详情空防护:避免deptDetialVo为null导致后续NPE |
| | | DeptDetialVo deptDetialVo = sysDeptService.selectDeptById(Long.valueOf(internalAuditCarryDept.getDeptId())); |
| | | if (deptDetialVo == null) { |
| | | continue; |
| | | } |
| | | List<SysDeptResponsibility> sysDeptResponsibilitys = deptDetialVo.getSysDeptResponsibilitys(); |
| | | List<InternalAuditCheckCatalogue> internalAuditCheckCatalogues = new ArrayList<>(); |
| | | // 7. 构建查询条件(保留原逻辑,仅优化日志) |
| | | Map<String, Object> queryMap = new HashMap<>(); |
| | | queryMap.put("dept_id", internalAuditCheck.getDeptId()); |
| | | queryMap.put("year", internalAuditCheck.getYear()); |
| | | queryMap.put("company_id", internalAuditCheck.getCompanyId()); |
| | | queryMap.put("del_flag", 0); |
| | | List<InternalAuditCheck> internalAuditChecks = internalAuditCheckService.selectByMap(queryMap); |
| | | List<InternalAuditCheckCatalogue> checkCatalogues = new ArrayList<>(); |
| | | if (!CollectionUtils.isEmpty(internalAuditChecks)){ |
| | | batchLoadCheckDetails(internalAuditChecks); |
| | | checkCatalogues = internalAuditChecks.get(0).getCheckCatalogues(); |
| | | } |
| | | // 循环构建新检查项 |
| | | if (!CollectionUtils.isEmpty(sysDeptResponsibilitys)) { |
| | | for (SysDeptResponsibility sysDeptResponsibility : sysDeptResponsibilitys) { |
| | | if (sysDeptResponsibility == null) { |
| | | continue; |
| | | } |
| | | InternalAuditCheckCatalogue catalogue = new InternalAuditCheckCatalogue(); |
| | | catalogue.setCatalogueId(Math.toIntExact(sysDeptResponsibility.getClauseId())); |
| | | SysClauseManagement clauseManagement = sysClauseManagementMapper.selectById(sysDeptResponsibility.getClauseId()); |
| | | if (clauseManagement == null) { |
| | | continue; |
| | | } |
| | | catalogue.setPointKey(clauseManagement.getPoints()); |
| | | if (!CollectionUtils.isEmpty(checkCatalogues)){ |
| | | for (InternalAuditCheckCatalogue checkCatalogue : checkCatalogues) { |
| | | if (checkCatalogue.getCatalogueId().equals(catalogue.getCatalogueId())){ |
| | | catalogue.setFind(checkCatalogue.getFind()); |
| | | // catalogue.setPointKey(checkCatalogue.getPointKey()); |
| | | catalogue.setResult(checkCatalogue.getResult()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | internalAuditCheckCatalogues.add(catalogue); |
| | | } |
| | | } |
| | | internalAuditCheck.setCheckCatalogues(internalAuditCheckCatalogues); |
| | | // 新增/更新判断(保留原逻辑,增加日志) |
| | | if (CollectionUtils.isEmpty(internalAuditChecks)) { |
| | | internalAuditCheckService.insertInternalAuditCheck(internalAuditCheck); |
| | | } else { |
| | | InternalAuditCheck existingCheck = internalAuditChecks.get(0); |
| | | internalAuditCheck.setId(existingCheck.getId()); |
| | | internalAuditCheckService.updateByYearAndDeptId(internalAuditCheck); |
| | | } |
| | | } |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | |
| | | private void batchLoadCheckDetails(List<InternalAuditCheck> checks) { |
| | | //收集所有检查ID |
| | | List<Integer> checkIds = checks.stream() |
| | | .map(InternalAuditCheck::getId) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (CollectionUtils.isEmpty(checkIds)){ |
| | | return; |
| | | } |
| | | //批量查询所有目录 |
| | | List<InternalAuditCheckCatalogue> allCatalogues = checkCatalogueMapper.selectByCheckIds(checkIds); |
| | | if (CollectionUtils.isEmpty(allCatalogues)) { |
| | | return; |
| | | } |
| | | //按检查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)) { |
| | | check.setCheckCatalogues(catalogues); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public CommonResult deletedCarry(Integer carryId) { |
| | |
| | | carryMapper.updateById(internalAuditCarry); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | |
| | | @Override |
| | | @Transactional |
| | | public CommonResult copyInternalAuditCarry(Integer companyId, String sourceYear, String targetYear) { |
| | | if (companyId == null) { |
| | | companyId = SecurityUtils.getCompanyId().intValue(); |
| | | } |
| | | |
| | | if (sourceYear == null || sourceYear.trim().isEmpty()) { |
| | | return CommonResult.failed("源年份不能为空"); |
| | | } |
| | | |
| | | if (targetYear == null || targetYear.trim().isEmpty()) { |
| | | return CommonResult.failed("目标年份不能为空"); |
| | | } |
| | | |
| | | LambdaUpdateWrapper<InternalAuditCarry> deleteWrapper = new LambdaUpdateWrapper<>(); |
| | | deleteWrapper.eq(InternalAuditCarry::getCompanyId, companyId) |
| | | .eq(InternalAuditCarry::getYear, targetYear) |
| | | .eq(InternalAuditCarry::getDelFlag, 1) |
| | | .set(InternalAuditCarry::getDelFlag, 2) |
| | | .set(InternalAuditCarry::getUpdateBy, SecurityUtils.getUsername()) |
| | | .set(InternalAuditCarry::getUpdateTime, LocalDateTime.now()); |
| | | carryMapper.update(new InternalAuditCarry(), deleteWrapper); |
| | | |
| | | LambdaQueryWrapper<InternalAuditCarry> queryWrapperSource = new LambdaQueryWrapper<>(); |
| | | queryWrapperSource.eq(InternalAuditCarry::getCompanyId, companyId) |
| | | .eq(InternalAuditCarry::getYear, sourceYear) |
| | | .eq(InternalAuditCarry::getDelFlag, 1); |
| | | List<InternalAuditCarry> sourceCarries = carryMapper.selectList(queryWrapperSource); |
| | | |
| | | if (ObjectUtil.isEmpty(sourceCarries)) { |
| | | return CommonResult.success("源年份无相关数据"); |
| | | } |
| | | |
| | | for (InternalAuditCarry sourceCarry : sourceCarries) { |
| | | InternalAuditCarry newCarry = new InternalAuditCarry(); |
| | | newCarry.setCompanyId(sourceCarry.getCompanyId()); |
| | | newCarry.setYear(targetYear); |
| | | newCarry.setAuditPurpose(sourceCarry.getAuditPurpose()); |
| | | newCarry.setReviewBasis(sourceCarry.getReviewBasis()); |
| | | newCarry.setReviewScope(sourceCarry.getReviewScope()); |
| | | newCarry.setReviewStart(sourceCarry.getReviewStart()); |
| | | newCarry.setReviewEnd(sourceCarry.getReviewEnd()); |
| | | newCarry.setReviewPerson(sourceCarry.getReviewPerson()); |
| | | newCarry.setFirstStarttime(sourceCarry.getFirstStarttime()); |
| | | newCarry.setFirstEndtime(sourceCarry.getFirstEndtime()); |
| | | newCarry.setLastStarttime(sourceCarry.getLastStarttime()); |
| | | newCarry.setLastEndtime(sourceCarry.getLastEndtime()); |
| | | newCarry.setCompilationId(sourceCarry.getCompilationId()); |
| | | newCarry.setProofreadId(sourceCarry.getProofreadId()); |
| | | newCarry.setCheckId(sourceCarry.getCheckId()); |
| | | newCarry.setRatifyId(sourceCarry.getRatifyId()); |
| | | newCarry.setDelFlag(1); |
| | | newCarry.setCreateBy(SecurityUtils.getUsername()); |
| | | newCarry.setCreateTime(LocalDateTime.now()); |
| | | newCarry.setUpdateBy(SecurityUtils.getUsername()); |
| | | newCarry.setUpdateTime(LocalDateTime.now()); |
| | | |
| | | int insert = carryMapper.insert(newCarry); |
| | | if (insert <= 0) { |
| | | throw new RuntimeException("复制内审计划实施主表数据失败"); |
| | | } |
| | | |
| | | List<InternalAuditCarryDept> sourceDeptList = carryMapper.selectCarryDeptList(sourceCarry.getId()); |
| | | if (ObjectUtil.isNotEmpty(sourceDeptList)) { |
| | | List<InternalAuditCarryDept> newDeptList = new ArrayList<>(); |
| | | for (InternalAuditCarryDept sourceDept : sourceDeptList) { |
| | | InternalAuditCarryDept newDept = new InternalAuditCarryDept(); |
| | | newDept.setCarryId(newCarry.getId()); |
| | | newDept.setDeptId(sourceDept.getDeptId()); |
| | | newDept.setCheckId(sourceDept.getCheckId()); |
| | | newDept.setDate(sourceDept.getDate()); |
| | | newDept.setStartTime(sourceDept.getStartTime()); |
| | | newDept.setEndTime(sourceDept.getEndTime()); |
| | | newDeptList.add(newDept); |
| | | } |
| | | carryMapper.insertCarryDept(newDeptList); |
| | | } |
| | | } |
| | | |
| | | return CommonResult.success("成功从年份[" + sourceYear + "]复制到年份[" + targetYear + "]"); |
| | | } |
| | | |
| | | } |