| | |
| | | package com.gkhy.exam.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.gkhy.exam.common.api.CommonPage; |
| | | import com.gkhy.exam.common.api.CommonResult; |
| | |
| | | import com.gkhy.exam.system.domain.RiskContent; |
| | | import com.gkhy.exam.system.domain.RiskContentMess; |
| | | import com.gkhy.exam.system.domain.RiskManage; |
| | | import com.gkhy.exam.system.domain.RiskMonitor; |
| | | import com.gkhy.exam.system.domain.req.CopyReq; |
| | | import com.gkhy.exam.system.mapper.RiskContentMapper; |
| | | import com.gkhy.exam.system.mapper.RiskManageMapper; |
| | | import com.gkhy.exam.system.mapper.RiskMonitorMapper; |
| | | import com.gkhy.exam.system.service.RiskManageService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.time.LocalDateTime; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | | public class RiskManageServiceImpl extends ServiceImpl<RiskManageMapper, RiskManage> implements RiskManageService { |
| | |
| | | |
| | | @Autowired |
| | | private RiskContentMapper riskContentMapper; |
| | | |
| | | @Autowired |
| | | private RiskMonitorMapper riskMonitorMapper; |
| | | |
| | | |
| | | @Override |
| | |
| | | riskManageMapper.updateById(riskManage); |
| | | return CommonResult.success(); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public CommonResult copyRiskMonitor(CopyReq copyReq) { |
| | | // 参数校验 |
| | | if (copyReq.getCompanyId() == null) { |
| | | throw new ApiException("企业ID不能为空"); |
| | | } |
| | | if (copyReq.getCopyYear() == null || copyReq.getCopyYear().isEmpty()) { |
| | | throw new ApiException("选择年份不能为空"); |
| | | } |
| | | if (copyReq.getTargetYear() == null || copyReq.getTargetYear().isEmpty()) { |
| | | throw new ApiException("目标年份不能为空"); |
| | | } |
| | | |
| | | // 查询源数据:根据企业ID和选择年份查询风险管理记录 |
| | | RiskManage queryParam = new RiskManage(); |
| | | queryParam.setCompanyId(Long.valueOf(copyReq.getCompanyId())); |
| | | queryParam.setYear(copyReq.getCopyYear()); |
| | | |
| | | List<RiskManage> sourceRiskManages = riskManageMapper.selectRiskManageList(queryParam); |
| | | |
| | | if (sourceRiskManages == null || sourceRiskManages.isEmpty()) { |
| | | throw new ApiException("未找到源年份[" + copyReq.getCopyYear() + "]的风险管理数据"); |
| | | } |
| | | |
| | | // 检查目标年份是否已存在数据 |
| | | RiskManage targetCheck = new RiskManage(); |
| | | targetCheck.setCompanyId(Long.valueOf(copyReq.getCompanyId())); |
| | | targetCheck.setYear(copyReq.getTargetYear()); |
| | | List<RiskManage> existingTargetData = riskManageMapper.selectRiskManageList(targetCheck); |
| | | |
| | | if (existingTargetData != null && !existingTargetData.isEmpty()) { |
| | | RiskManage updateEntity = new RiskManage(); |
| | | updateEntity.setDelFlag(2); |
| | | updateEntity.setUpdateTime(LocalDateTime.now()); |
| | | updateEntity.setUpdateBy(SecurityUtils.getUsername()); |
| | | UpdateWrapper<RiskManage> objectUpdateWrapper = new UpdateWrapper<>(); |
| | | objectUpdateWrapper.eq("company_id", targetCheck.getCompanyId()) |
| | | .eq("year", targetCheck.getYear()); |
| | | riskManageMapper.update(updateEntity, objectUpdateWrapper); |
| | | |
| | | List<Integer> collect = existingTargetData.stream().map(RiskManage::getId).collect(Collectors.toList()); |
| | | riskMonitorMapper.deletedByManageIds(collect); |
| | | } |
| | | |
| | | // 遍历源数据进行复制 |
| | | for (RiskManage sourceManage : sourceRiskManages) { |
| | | // 创建新的风险管理记录 |
| | | RiskManage newRiskManage = new RiskManage(); |
| | | newRiskManage.setCompanyId(sourceManage.getCompanyId()); |
| | | newRiskManage.setDeptId(sourceManage.getDeptId()); |
| | | newRiskManage.setYear(copyReq.getTargetYear()); |
| | | newRiskManage.setDocument(sourceManage.getDocument()); |
| | | newRiskManage.setFictionId(sourceManage.getFictionId()); |
| | | newRiskManage.setCheckId(sourceManage.getCheckId()); |
| | | newRiskManage.setRatifyId(sourceManage.getRatifyId()); |
| | | newRiskManage.setDelFlag(1); |
| | | newRiskManage.setCreateBy(SecurityUtils.getUsername()); |
| | | newRiskManage.setCreateTime(LocalDateTime.now()); |
| | | |
| | | // 插入新的风险管理记录 |
| | | riskManageMapper.insert(newRiskManage); |
| | | |
| | | // 查询源风险管理的内容 |
| | | List<RiskContent> sourceContents = riskContentMapper.selectRiskContent(sourceManage.getId()); |
| | | RiskMonitor riskMonitor = new RiskMonitor(); |
| | | riskMonitor.setRiskManageId(sourceManage.getId()); |
| | | List<RiskMonitor> riskMonitors = riskMonitorMapper.selectMonitor(riskMonitor); |
| | | for (RiskMonitor monitor : riskMonitors) { |
| | | RiskMonitor newMonitor = new RiskMonitor(); |
| | | newMonitor.setRiskManageId(newRiskManage.getId()); |
| | | newMonitor.setCompanyId(monitor.getCompanyId()); |
| | | newMonitor.setFictionId(monitor.getFictionId()); |
| | | newMonitor.setCheckId(monitor.getCheckId()); |
| | | newMonitor.setRatifyId(monitor.getRatifyId()); |
| | | newMonitor.setCheckTime(monitor.getCheckTime()); |
| | | newMonitor.setCreateBy(SecurityUtils.getUsername()); |
| | | newMonitor.setCreateTime(LocalDateTime.now()); |
| | | riskMonitorMapper.insert(newMonitor); |
| | | } |
| | | |
| | | if (sourceContents != null && !sourceContents.isEmpty()) { |
| | | List<RiskContentMess> allContentMesses = new ArrayList<>(); |
| | | |
| | | // 遍历风险内容进行复制 |
| | | for (RiskContent sourceContent : sourceContents) { |
| | | // 创建新的风险内容 |
| | | RiskContent newContent = new RiskContent(); |
| | | newContent.setRiskManageId(newRiskManage.getId()); |
| | | newContent.setProcess(sourceContent.getProcess()); |
| | | |
| | | // 插入新的风险内容 |
| | | riskContentMapper.insert(newContent); |
| | | |
| | | // 查询源风险内容的详细信息 |
| | | List<RiskContentMess> sourceMesses = riskContentMapper.selectContentMess(sourceContent.getId()); |
| | | |
| | | if (sourceMesses != null && !sourceMesses.isEmpty()) { |
| | | // 复制详细信息并关联到新的风险内容 |
| | | for (RiskContentMess sourceMess : sourceMesses) { |
| | | RiskContentMess newMess = new RiskContentMess(); |
| | | newMess.setRiskContentId(newContent.getId()); |
| | | newMess.setRiskEvent(sourceMess.getRiskEvent()); |
| | | newMess.setRiskConsequence(sourceMess.getRiskConsequence()); |
| | | newMess.setSeverity(sourceMess.getSeverity()); |
| | | newMess.setFrequency(sourceMess.getFrequency()); |
| | | newMess.setRpn(sourceMess.getRpn()); |
| | | newMess.setRiskLevel(sourceMess.getRiskLevel()); |
| | | newMess.setMeasures(sourceMess.getMeasures()); |
| | | newMess.setChargeUser(sourceMess.getChargeUser()); |
| | | newMess.setMonitorTime(sourceMess.getMonitorTime()); |
| | | newMess.setReview(sourceMess.getReview()); |
| | | |
| | | allContentMesses.add(newMess); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 批量插入风险详细内容 |
| | | if (!allContentMesses.isEmpty()) { |
| | | riskContentMapper.insertRiskContentMess(allContentMesses); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return CommonResult.success("成功从年份[" + copyReq.getCopyYear() + "]复制到年份[" + copyReq.getTargetYear() + "]"); |
| | | } |
| | | |
| | | } |