package com.gkhy.labRiskManage.domain.riskReport.service.impl; import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportReqBO; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportExperimentSiteQueryRespDTO; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportPersonQueryRespDTO; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportRiskSourceQueryRespDTO; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportSourceTypeQueryRespDTO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportAppQueryBO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportAppUpdateBO; import com.gkhy.labRiskManage.application.riskReport.dto.dto.ReportAppQueryDTO; import com.gkhy.labRiskManage.commons.domain.SearchResult; import com.gkhy.labRiskManage.commons.enums.ResultCode; import com.gkhy.labRiskManage.commons.enums.StatusEnum; import com.gkhy.labRiskManage.commons.enums.UserTagEnum; import com.gkhy.labRiskManage.commons.enums.UserRoleEnum; import com.gkhy.labRiskManage.commons.exception.BusinessException; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.account.model.dto.SysUserRoleBindDomainDTO; import com.gkhy.labRiskManage.domain.account.model.dto.UserInfoDomainDTO; import com.gkhy.labRiskManage.domain.account.service.UserDomainService; import com.gkhy.labRiskManage.domain.basic.entity.BasicRiskUnitType; import com.gkhy.labRiskManage.domain.basic.model.dto.PersonQueryDTO; import com.gkhy.labRiskManage.domain.basic.model.dto.SiteQueryDTO; import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService; import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentSiteService; import com.gkhy.labRiskManage.domain.basic.service.BasicRiskUnitTypeService; import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAndSite; import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentInfo; import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentApprovalStatusEnum; import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentRectifyStatusEnum; import com.gkhy.labRiskManage.domain.experiment.model.dto.ExperimentInfoDTO; import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndSiteService; import com.gkhy.labRiskManage.domain.experiment.service.ExperimentInfoService; import com.gkhy.labRiskManage.domain.riskReport.entity.*; import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportQueryBO; import com.gkhy.labRiskManage.domain.riskReport.model.bo.UpdateExperimentInfoBO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.*; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportRiskAssessInfoRepository; import com.gkhy.labRiskManage.domain.riskReport.service.*; import com.gkhy.labRiskManage.domain.riskReport.utils.GetRoleTagUtils; import com.gkhy.labRiskManage.domain.riskReport.utils.RiskSourceTypeUtils; import lombok.Data; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * 风险评估报告 */ @Service public class ReportRiskAssessInfoServiceImpl implements ReportRiskAssessInfoService { @Autowired private ReportRiskAssessInfoRepository reportRepository; @Autowired private ExperimentInfoService experimentInfoService; @Autowired private RiskAssessPlanService assessPlanService; @Autowired private BasicExperimentPersonService basicPersonService; @Autowired private BasicExperimentSiteService basicSiteService; @Autowired private RiskUnitService riskUnitService; @Autowired private ExperimentAndSiteService experimentAndSiteService; @Autowired private ReportExperimentSiteService reportExperimentSiteService; @Autowired private BasicRiskUnitTypeService basicRiskUnitTypeService; @Autowired private ReportRiskAssessPersonService reportPersonService; @Autowired private ReportExperimentRiskSourceTypeService reportSourceTypeService; @Autowired private ReportExperimentRiskSourceService reportSourceService; @Autowired private UserDomainService userDomainService; @Autowired private RiskAssessPlanEvaluateLecService lecService; @Autowired private RiskAssessPlanEvaluateLsService lsService; @Autowired private RiskAssessPlanEvaluateMesService mesService; @Autowired private RiskAssessPlanEvaluateRsService rsService; /** * 风险评估报告 - 查询 */ @Override public SearchResult selectRiskReportPage(Long currentUserId, ReportAppQueryBO queryBO) { //校验参数 if (ObjectUtils.isEmpty(queryBO.getPageSize())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空"); } if (ObjectUtils.isEmpty(queryBO.getPageIndex())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"分页信息不能为空"); } if (ObjectUtils.isEmpty(queryBO.getTag())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"查询报告类别参数缺失"); } if (queryBO.getExperimentName() == "null"){ queryBO.setExperimentName(null); } UserInfoDomainDTO user = userDomainService.getUserById(currentUserId); if (ObjectUtils.isEmpty(user)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在"); } int roleTag = GetRoleTagUtils.GetRoleTagUtils(user); ReportQueryBO queryParam = BeanCopyUtils.copyBean(queryBO, ReportQueryBO.class); SearchResult searchResult = new SearchResult<>(); searchResult.setPageIndex(queryParam.getPageIndex()); searchResult.setPageSize(queryParam.getPageSize()); // ExperimentInfoDTO experimentByName = experimentInfoService.getExperimentByName(queryBO.getExperimentName()); //封装查询参数 Specification specification = new Specification() { @Override public Predicate toPredicate(Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) { List predicateList = new ArrayList<>(); if (queryParam.getAssessLevel() != null && !queryParam.getAssessLevel().equals("")){ predicateList.add(criteriaBuilder.equal(root.get("assessLevel"),queryParam.getAssessLevel())); } if (queryParam.getApprovePlanStatus() != null && !queryParam.getApprovePlanStatus().equals("")){ predicateList.add(criteriaBuilder.equal(root.get("approvePlanStatus"), queryParam.getApprovePlanStatus())); } if (queryParam.getExperimentType() != null && !queryParam.getExperimentType().equals("")){ predicateList.add(criteriaBuilder.equal(root.get("experimentType"),queryParam.getExperimentType())); } if (!ObjectUtils.isEmpty(queryParam.getExperimentId())){ predicateList.add(criteriaBuilder.equal(root.get("experimentId"),queryParam.getExperimentId())); } if (!ObjectUtils.isEmpty(queryParam.getExperimentName())){ predicateList.add(criteriaBuilder.equal(root.get("experimentName"), queryParam.getExperimentName())); } if (roleTag == UserTagEnum.USER_TAG_0.getCode()){ predicateList.add(criteriaBuilder.equal(root.get("personUserId"), currentUserId)); } if (queryParam.getTag() == 1){ predicateList.add(criteriaBuilder.isNull(root.get("assessPerson"))); }else if (queryParam.getTag() == 2){ predicateList.add(criteriaBuilder.isNotNull(root.get("assessPerson"))); } //现在领导能查看所有的报告 // if (roleTag == UserTagEnum.USER_TAG_2.getCode()){ // predicateList.add(criteriaBuilder.or( // criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_APPROVED.getCode()), // criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_NOT_APPROVED.getCode()), // criteriaBuilder.equal(root.get("approvePlanStatus"), StatusEnum.REPORT_APPROVED_LEAD.getCode()) // ) // ); // } predicateList.add(criteriaBuilder.equal(root.get("deleteStatus"),StatusEnum.DELETE_NOT.getCode())); return criteriaBuilder.and(predicateList.toArray(new Predicate[0])); } }; PageRequest pageParam = PageRequest.of(queryParam.getPageIndex() - 1, queryParam.getPageSize(), Sort.Direction.DESC, "updateTime"); Page pageResult = reportRepository.findAll(specification, pageParam); List reportQueryDTOS = BeanCopyUtils.copyBeanList(pageResult.getContent(), ReportQueryDTO.class); List reportAppQueryDTOS = BeanCopyUtils.copyBeanList(reportQueryDTOS, ReportAppQueryDTO.class); List userList = userDomainService.getUserList(); for (ReportAppQueryDTO reportQueryDTO : reportAppQueryDTOS) { //获取审批人员 List personByReportId = reportPersonService.listPersonByReportId(reportQueryDTO.getId()); //获取实验风险源 List riskSourceByReportId = reportSourceService.getRiskSourceByReportId(reportQueryDTO.getId()); //获取风险类型 List sourceTypeByReportId = reportSourceTypeService.getSourceTypeByReportId(reportQueryDTO.getId()); //获取风险类型 List siteByReportId = reportExperimentSiteService.getSiteByReportId(reportQueryDTO.getId()); //获取实验信息 ExperimentInfoDTO experimentById = experimentInfoService.getExperimentById(reportQueryDTO.getExperimentId()); //获取评估计划 List assessPlanByExperimentId = assessPlanService.getAssessPlanByExperimentId(reportQueryDTO.getExperimentId()); reportQueryDTO.setEvaluateTime(experimentById.getCreateTime()); if (!ObjectUtils.isEmpty(assessPlanByExperimentId)){ for (AssessPlanQueryDTO assessPlan : assessPlanByExperimentId) { if (reportQueryDTO.getEvaluateTime().isBefore(assessPlan.getEvaluateTime())){ reportQueryDTO.setEvaluateTime(assessPlan.getEvaluateTime()); } } } if (!ObjectUtils.isEmpty(riskSourceByReportId)){ reportQueryDTO.setRiskSource(riskSourceByReportId); } if (!ObjectUtils.isEmpty(sourceTypeByReportId)){ reportQueryDTO.setRiskSourceType(sourceTypeByReportId); } if (!ObjectUtils.isEmpty(personByReportId)){ reportQueryDTO.setPerson(personByReportId); } if (!ObjectUtils.isEmpty(siteByReportId)){ reportQueryDTO.setExperimentSite(BeanCopyUtils.copyBeanList(siteByReportId, ReportExperimentSiteQueryRespDTO.class)); } reportQueryDTO.setExperimentCode(experimentById.getExperimentCode()); for (UserInfoDomainDTO userInfo : userList) { if (userInfo.getId() == reportQueryDTO.getCreateByUserId()){ reportQueryDTO.setCreateByUserName(userInfo.getRealName()); } if (userInfo.getId() == reportQueryDTO.getUpdateByUserId()){ reportQueryDTO.setUpdateByUserName(userInfo.getRealName()); } } } searchResult.setData(reportAppQueryDTOS); searchResult.setTotal(pageResult.getTotalElements()); return searchResult; } /** * 风险评估报告 - 生成报告信息 */ @Transactional @Override public ReportInsertDTO insertRiskReport(Long currentUserId, Long id) { if (currentUserId < 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆"); } UserInfoDomainDTO userInfoById = userDomainService.getUserInfoById(currentUserId); if (ObjectUtils.isEmpty(userInfoById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除"); } int roleTag = GetRoleTagUtils.GetRoleTagUtils(userInfoById); if (ObjectUtils.isEmpty(id)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"实验id不能为空"); } //获取实验id,查询实验 ExperimentInfoDTO experimentById = experimentInfoService.getExperimentById(id); if (ObjectUtils.isEmpty(experimentById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "实验不存在"); } if (roleTag == 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"不是管理员,无权生成报告"); } if (experimentById.getStage() == StatusEnum.EXPERIMENT_STATUS_REPORT.getCode().byteValue()){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"该实验已经生成报告,无需重复操作"); } //定义初始风险等级0级 Byte level = 0; //获取该实验的所有计划信息 List assessPlanList = assessPlanService.getAssessPlanByExperimentId(id); int tag = 0; StringBuilder info = new StringBuilder(); List assessPlanIds = new ArrayList<>(); //如果有计划未评价完成,不可生成报告 for (AssessPlanQueryDTO assessPlanQueryDTO : assessPlanList) { if (assessPlanQueryDTO.getPlanExecStatus() != StatusEnum.PLAN_EXEC_OVER.getCode().byteValue()){ info.append(assessPlanQueryDTO.getAssessPlanName() + ";"); tag = 1; } assessPlanIds.add(assessPlanQueryDTO.getId()); } if (tag == 1){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"该实验有未完成的评估计划" + info); } UserInfoDomainDTO liabilityUser = userDomainService.getUserInfoById(experimentById.getLiabilityUserId()); if (ObjectUtils.isEmpty(liabilityUser)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"实验责任人信息不存在"); } //检查该实验所有的评价结果,遍历评价结果等级 int a = 1; StringBuilder analysis = new StringBuilder(); List lecByIds = lecService.getLecByIds(assessPlanIds); List lsByIds = lsService.getLsByIds(assessPlanIds); List mesByIds = mesService.getMesByIds(assessPlanIds); List rsByIds = rsService.getRsByIds(assessPlanIds); if (lecByIds .size() > 0){ for (RiskAssessPlanEvaluateLec lecById : lecByIds) { if (lecById.getRiskLevel() > level){ level = lecById.getRiskLevel(); analysis.append(a + lecById.getSafeRiskAnalysis() + ";");//todo 安全风险分析 a++; } } } if (lsByIds .size() > 0){ for (RiskAssessPlanEvaluateLs lsById : lsByIds) { if (lsById.getRiskLevel() > level){ level = lsById.getRiskLevel(); analysis.append(a + lsById.getSafeRiskAnalysis() + ";"); a++; } } } if (mesByIds .size() > 0){ for (RiskAssessPlanEvaluateMes mesById : mesByIds) { if (mesById.getRiskLevel() > level){ level = mesById.getRiskLevel(); analysis.append(a + mesById.getSafeRiskAnalysis() + ";"); a++; } } } if (rsByIds .size() > 0){ for (RiskAssessPlanEvaluateRs rsById : rsByIds) { if (rsById.getRiskLevel() > level){ level = rsById.getRiskLevel(); analysis.append(a + rsById.getSafeRiskAnalysis() + ";"); a++; } } } //封装报告主体信息 LocalDateTime date = LocalDateTime.now(); ReportRiskAssessInfo reportInfo = new ReportRiskAssessInfo(); reportInfo.setExperimentId(experimentById.getId()); reportInfo.setExperimentName(experimentById.getExperimentName()); reportInfo.setExperimentType(experimentById.getExperimentType()); reportInfo.setExperimentDesc(experimentById.getNote()); reportInfo.setPersonUserId(experimentById.getLiabilityUserId());//todo 确定实验负责人,安全负责人来源 reportInfo.setPersonUser(experimentById.getLiabilityUser()); reportInfo.setPersonUserPhone(Long.valueOf(experimentById.getLiabilityUserPhone())); //从实验用户表查询 reportInfo.setSafePersonUserId(experimentById.getSafeLiabilityUserId()); reportInfo.setSafePersonUser(experimentById.getSafeLiabilityUser()); reportInfo.setSafePersonUserPhone(Long.valueOf(experimentById.getSafeLiabilityUserPhone())); reportInfo.setEmergencyMeasure(experimentById.getMeasure()); reportInfo.setDep(experimentById.getDep()); reportInfo.setCreateTime(date); reportInfo.setUpdateTime(date); reportInfo.setCreateByUserId(userInfoById.getId()); reportInfo.setUpdateByUserId(userInfoById.getId()); reportInfo.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); reportInfo.setApprovePlanStatus(StatusEnum.REPORT_NOT_START.getCode().byteValue()); reportInfo.setSafeRiskAnalysis(analysis.toString()); reportInfo.setAssessPerson(null); reportInfo.setAssessLevel(null); reportInfo.setDepId(null); //todo 不确定是否需要部门 reportInfo.setSafeRiskAnalysis(null); //todo 安全风险分析,暂时不知道数据来源,先设空 //修改实验 4 生成报告, ExperimentInfoDTO experimentInfoDTO = experimentInfoService.updateExperimentStage(id, StatusEnum.EXPERIMENT_STATUS_REPORT.getCode().byteValue()); if (ObjectUtils.isEmpty(experimentInfoDTO)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"实验状态修改失败"); } //修改实验所有评估计划状态 int result = assessPlanService.assessPlanSellStatus(id, StatusEnum.PLAN_EXEC_OVER.getCode().byteValue()); if (result == 0){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估计划状态修改失败"); } //生成报告主体信息 ReportRiskAssessInfo saveResult = reportRepository.save(reportInfo); if (ObjectUtils.isEmpty(saveResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告基本信息失败,请稍后尝试"); } //封装实验场所信息 List reportSiteList = new ArrayList<>(); List experimentAndSiteList = experimentAndSiteService.getByExperimentId(id); for (ExperimentAndSite experimentAndSite : experimentAndSiteList) { SiteQueryDTO siteInfo = basicSiteService.getBasicExperimentSiteById(experimentAndSite.getSiteId()); ReportExperimentSite reportSite = BeanCopyUtils.copyBean(siteInfo, ReportExperimentSite.class); reportSite.setReportId(saveResult.getId()); reportSite.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); reportSite.setSiteId(siteInfo.getId()); reportSiteList.add(reportSite); } List reportExperimentSites = reportExperimentSiteService.insertAll(reportSiteList); if (reportExperimentSites.size() < reportSiteList.size()){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告实验场所信息时失败,请稍后尝试"); } //封装风险源类型信息 List riskSourceTypeList = RiskSourceTypeUtils.RiskSourceType(currentUserId, saveResult.getId()); //封装风 List riskUnitList = riskUnitService.getRiskUnitByExperimentId(id); List riskSourceList = new ArrayList<>(); int i = 1; for (RiskUnit riskUnit : riskUnitList) { //封装风险源信息 todo -- 需要确认 此处封装风险单元?辨识出的每一项结果 ReportExperimentRiskSource riskSource = new ReportExperimentRiskSource(); riskSource.setReportId(saveResult.getId()); riskSource.setRiskSourceIndex(i); riskSource.setRiskSource(riskUnit.getRiskName()); riskSource.setRiskCharacteristic(riskUnit.getDescription()); riskSource.setDescription(riskUnit.getDescription()); riskSource.setNumber(1); riskSource.setCreateByUserId(currentUserId); riskSource.setCreateTime(date); riskSource.setUpdateByUserId(currentUserId); riskSource.setUpdateTime(date); riskSource.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); riskSourceList.add(riskSource); i++; //检查风险源类型是否存在 BasicRiskUnitType riskUnitTypeById = basicRiskUnitTypeService.getRiskUnitTypeById(riskUnit.getRiskUnitTypeId()); for (ReportExperimentRiskSourceType riskSourceType : riskSourceTypeList) { if (riskSourceType.getRiskSourceType().equals(riskUnitTypeById.getRiskType())){ riskSourceType.setStatus((byte) 1);//1-存在;2-不存在 } } } //todo 改为手写,----- 暂时弃用 写入风险源 // List riskSources = reportSourceService.insertAllReportSource(riskSourceList); // if (riskSources.size() < riskSourceList.size()){ // throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源信息时失败,请稍后尝试"); // } //写入风险源类型 List riskSourceTypes = reportSourceTypeService.insertAllReportSource(riskSourceTypeList); if (riskSourceTypes.size() < riskSourceTypeList.size()){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源类型信息时失败,请稍后尝试"); } return BeanCopyUtils.copyBean(saveResult, ReportInsertDTO.class); } /** * 风险评估报告 - 填报信息 */ @Override public ReportUpdateDTO updateReportInfo(Long currentUserId, ReportAppUpdateBO reportUpdateBO) { if (currentUserId < 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆"); } int roleTag = 0; UserInfoDomainDTO user = userDomainService.getUserById(currentUserId); for (SysUserRoleBindDomainDTO role : user.getRoles()) { if (role.getRoleId() == UserRoleEnum.USER_ROLE_4.getCode().byteValue()){ roleTag = 1; } } if (ObjectUtils.isEmpty(user)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在"); } if (roleTag == 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无权生成评估报告"); } if (ObjectUtils.isEmpty(reportUpdateBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行提交"); } ReportRiskAssessInfo reportById = reportRepository.getReportById(reportUpdateBO.getId()); if (ObjectUtils.isEmpty(reportById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode() ,"选择的报告不存在"); } if (!ObjectUtils.isEmpty(reportById.getAssessLevel())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告已经填写完成"); } if (ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"安全风险分析内容不能为空"); } if (ObjectUtils.isEmpty(reportUpdateBO.getAssessLevel())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不能为空"); } if (!(reportUpdateBO.getAssessLevel() == 1 || reportUpdateBO.getAssessLevel() == 2 || reportUpdateBO.getAssessLevel() == 3 || reportUpdateBO.getAssessLevel() == 4)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不合法,请选择:低风险,一般风险,较大风险,重大风险"); } reportById.setAssessPerson(reportUpdateBO.getAssessPerson()); reportById.setAssessLevel(reportUpdateBO.getAssessLevel()); reportById.setSafeRiskAnalysis(reportUpdateBO.getSafeRiskAnalysis()); reportById.setDescription(reportUpdateBO.getDescription()); reportById.setUpdateTime(LocalDateTime.now()); reportById.setUpdateByUserId(currentUserId); ReportRiskAssessInfo updateResult = reportRepository.save(reportById); if (ObjectUtils.isEmpty(updateResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估报告信息写入失败"); } return BeanCopyUtils.copyBean(updateResult, ReportUpdateDTO.class); } /** * 风险评估报告 - 修改填报信息 */ @Override public ReportUpdateDTO updateReportInfoById(Long currentUserId, ReportAppUpdateBO reportUpdateBO) { if (currentUserId < 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆"); } int roleTag = 0; UserInfoDomainDTO user = userDomainService.getUserById(currentUserId); for (SysUserRoleBindDomainDTO role : user.getRoles()) { if (role.getRoleId() == UserRoleEnum.USER_ROLE_4.getCode().byteValue()){ roleTag = 1; } } if (ObjectUtils.isEmpty(user)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"用户不存在"); } if (roleTag == 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无权生成评估报告"); } if (ObjectUtils.isEmpty(reportUpdateBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行提交"); } ReportRiskAssessInfo reportById = reportRepository.getReportById(reportUpdateBO.getId()); if (ObjectUtils.isEmpty(reportById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode() ,"选择的报告不存在"); } // if (ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){ // throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"安全风险分析内容不能为空"); // } if (ObjectUtils.isEmpty(reportUpdateBO.getAssessLevel())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不能为空"); } if (!(reportUpdateBO.getAssessLevel() == 1 || reportUpdateBO.getAssessLevel() == 2 || reportUpdateBO.getAssessLevel() == 3 || reportUpdateBO.getAssessLevel() == 4)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"项目风险评估等级不合法,请选择:低风险,一般风险,较大风险,重大风险"); } reportById.setAssessPerson(reportUpdateBO.getAssessPerson()); reportById.setAssessLevel(reportUpdateBO.getAssessLevel()); // reportById.setSafeRiskAnalysis(reportUpdateBO.getSafeRiskAnalysis()); reportById.setDescription(reportUpdateBO.getDescription()); reportById.setUpdateTime(LocalDateTime.now()); reportById.setUpdateByUserId(currentUserId); ReportRiskAssessInfo updateResult = reportRepository.save(reportById); if (ObjectUtils.isEmpty(updateResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"评估报告信息写入失败"); } return BeanCopyUtils.copyBean(updateResult, ReportUpdateDTO.class); } /** * 风险评估报告 - 报告审核 - 旧 - 两层审核 */ @Transactional @Override public int report(Long currentUserId, ReportReqBO reportReqBO) { if (currentUserId < 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆"); } UserInfoDomainDTO user = userDomainService.getUserById(currentUserId); if (ObjectUtils.isEmpty(user)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除"); } int roleTag = GetRoleTagUtils.GetRoleTagUtils(user); if (roleTag == 0){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"非管理人员,无权操作"); } if (ObjectUtils.isEmpty(reportReqBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行审核"); } ReportRiskAssessInfo reportById = reportRepository.getReportById(reportReqBO.getId()); if (ObjectUtils.isEmpty(reportById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告不存在"); } if (ObjectUtils.isEmpty(reportReqBO.getApproveDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审核意见不能为空"); } /** * 方案 * 1、管理部门审核报告后,领导可见 * 2、管理部门-->领导,任意审核不通过,否决实验,改变报告、实验状态 * 3、管理部门审核通过,改变报告状态(管理审核),不改变实验状态; * 4、领导审核通过,改变报告(领导审核)、实验状态; * */ LocalDateTime date = LocalDateTime.now(); ReportRiskAssessPerson approvePerson = new ReportRiskAssessPerson(); approvePerson.setReportId(reportReqBO.getId()); approvePerson.setApprovePerson(user.getRealName()); approvePerson.setApproveDesc(reportReqBO.getApproveDesc()); approvePerson.setApproveTime(date); approvePerson.setCreateTime(date); approvePerson.setUpdateTime(date); approvePerson.setApprovePersonId(currentUserId); approvePerson.setCreateByUserId(currentUserId); approvePerson.setUpdateByUserId(currentUserId); approvePerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); //1、审核通过 if (reportReqBO.getApproveStatus() == 2){ approvePerson.setApproveStatus(StatusEnum.APPROVED_PASS.getCode().byteValue()); if (roleTag == 1){ List personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId()); if (!ObjectUtils.isEmpty(personByReportId)){ for (ReportPersonInsertDTO person : personByReportId) { if (person.getApproveIndex() == 1){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被管理人员审核,无需重复操作"); } } } //保存审核人员信息 approvePerson.setApproveIndex(1); approvePerson.setApproveStage("管理人员审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } //修改报告信息-管理审核 reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED.getCode().byteValue()); ReportRiskAssessInfo reportReject = reportRepository.save(reportById); if (ObjectUtils.isEmpty(reportReject)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); } } if (roleTag == 2){ List personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId()); if (!ObjectUtils.isEmpty(personByReportId)){ for (ReportPersonInsertDTO person : personByReportId) { if (person.getApproveIndex() == 2){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被领导审核,无需重复操作"); } } } //保存审核人员信息 approvePerson.setApproveIndex(2); approvePerson.setApproveStage("领导审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } //修改报告状态-领导审核 reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED_LEAD.getCode().byteValue()); ReportRiskAssessInfo reportReject = reportRepository.save(reportById); if (ObjectUtils.isEmpty(reportReject)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); } //修改实验状态-通过实验 UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO(); updateBO.setExperimentId(reportById.getExperimentId()); updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_SUCCESS.getValue()); updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue()); ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO); if (ObjectUtils.isEmpty(experimentInfo)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败"); } } } //2、任意审核不通过 if (reportReqBO.getApproveStatus() == 3){ approvePerson.setApproveStatus(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue()); if (roleTag == 1){ //保存审核人员信息 approvePerson.setApproveIndex(1); approvePerson.setApproveStage("管理人员审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } } if (roleTag == 2){ //保存审核人员信息 approvePerson.setApproveIndex(2); approvePerson.setApproveStage("领导审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } } //修改报告状态 reportById.setApprovePlanStatus(StatusEnum.REPORT_NOT_APPROVED.getCode().byteValue()); ReportRiskAssessInfo reportReject = reportRepository.save(reportById); if (ObjectUtils.isEmpty(reportReject)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); } //修改实验状态,否决实验 UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO(); updateBO.setExperimentId(reportById.getExperimentId()); updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_FAIL.getValue()); updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue()); ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO); if (ObjectUtils.isEmpty(experimentInfo)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败"); } } return StatusEnum.SUCCESS.getCode(); } /** * 风险评估报告 - 报告审核 - 新 - 单次审核 */ @Override public int reportNew(Long currentUserId, ReportReqBO reportReqBO) { if (currentUserId < 0){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户无效,请重新登陆"); } UserInfoDomainDTO user = userDomainService.getUserById(currentUserId); if (ObjectUtils.isEmpty(user)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"当前用户不存在或已被删除"); } int roleTag = GetRoleTagUtils.GetRoleTagUtils(user); if (roleTag != 2){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"非综合办工作人员,无权操作"); } if (ObjectUtils.isEmpty(reportReqBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"请选择正确的报告进行审核"); } ReportRiskAssessInfo reportById = reportRepository.getReportById(reportReqBO.getId()); if (ObjectUtils.isEmpty(reportById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告不存在"); } if (ObjectUtils.isEmpty(reportReqBO.getApproveDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审核意见不能为空"); } LocalDateTime date = LocalDateTime.now(); ReportRiskAssessPerson approvePerson = new ReportRiskAssessPerson(); approvePerson.setReportId(reportReqBO.getId()); approvePerson.setApprovePerson(user.getRealName()); approvePerson.setApproveDesc(reportReqBO.getApproveDesc()); approvePerson.setApproveTime(date); approvePerson.setCreateTime(date); approvePerson.setUpdateTime(date); approvePerson.setApprovePersonId(currentUserId); approvePerson.setCreateByUserId(currentUserId); approvePerson.setUpdateByUserId(currentUserId); approvePerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); //1、审核通过 if (reportReqBO.getApproveStatus() == 2){ approvePerson.setApproveStatus(StatusEnum.APPROVED_PASS.getCode().byteValue()); // if (roleTag == 1){ // List personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId()); // if (!ObjectUtils.isEmpty(personByReportId)){ // for (ReportPersonInsertDTO person : personByReportId) { // if (person.getApproveIndex() == 1){ // throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被管理人员审核,无需重复操作"); // } // } // } // //保存审核人员信息 // approvePerson.setApproveIndex(1); // approvePerson.setApproveStage("管理人员审核"); // ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); // if (ObjectUtils.isEmpty(assessPerson)){ // throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); // } // //修改报告信息-管理审核 // reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED.getCode().byteValue()); // ReportRiskAssessInfo reportReject = reportRepository.save(reportById); // if (ObjectUtils.isEmpty(reportReject)){ // throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); // } // } if (roleTag == 2){ List personByReportId = reportPersonService.getPersonByReportId(reportReqBO.getId()); if (!ObjectUtils.isEmpty(personByReportId)){ for (ReportPersonInsertDTO person : personByReportId) { if (person.getApproveIndex() == 2){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告已被综合办审核,无需重复操作"); } } } //保存审核人员信息 approvePerson.setApproveIndex(2); approvePerson.setApproveStage("综合办审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } //修改报告状态-领导审核 reportById.setApprovePlanStatus(StatusEnum.REPORT_APPROVED_LEAD.getCode().byteValue()); ReportRiskAssessInfo reportReject = reportRepository.save(reportById); if (ObjectUtils.isEmpty(reportReject)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); } //修改实验状态-通过实验 UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO(); updateBO.setExperimentId(reportById.getExperimentId()); updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_SUCCESS.getValue()); updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.NOT_RECTIFY.getValue()); ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO); if (ObjectUtils.isEmpty(experimentInfo)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败"); } } } //2、任意审核不通过 if (reportReqBO.getApproveStatus() == 3){ approvePerson.setApproveStatus(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue()); // if (roleTag == 1){ // //保存审核人员信息 // approvePerson.setApproveIndex(1); // approvePerson.setApproveStage("管理人员审核"); // ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); // if (ObjectUtils.isEmpty(assessPerson)){ // throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); // } // } if (roleTag == 2){ //保存审核人员信息 approvePerson.setApproveIndex(2); approvePerson.setApproveStage("综合办审核"); ReportRiskAssessPerson assessPerson = reportPersonService.insertOneReportPerson(approvePerson); if (ObjectUtils.isEmpty(assessPerson)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"审核信息保存失败"); } } //修改报告状态 reportById.setApprovePlanStatus(StatusEnum.REPORT_NOT_APPROVED.getCode().byteValue()); ReportRiskAssessInfo reportReject = reportRepository.save(reportById); if (ObjectUtils.isEmpty(reportReject)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"报告状态修改失败"); } //修改实验状态,否决实验 UpdateExperimentInfoBO updateBO = new UpdateExperimentInfoBO(); updateBO.setExperimentId(reportById.getExperimentId()); updateBO.setApprovalStatus(ExperimentApprovalStatusEnum.APPROVAL_FAIL.getValue()); updateBO.setRectifyStatus(ExperimentRectifyStatusEnum.WAIT_RECTIFY.getValue()); ExperimentInfo experimentInfo = experimentInfoService.updateExperimentStatus(updateBO); if (ObjectUtils.isEmpty(experimentInfo)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息状态修改失败"); } } return StatusEnum.SUCCESS.getCode(); } /** * 风险评估报告 - list */ @Override public List listRiskReport(List idList) { List reportRiskAssessList = reportRepository.listRiskReport(idList); if (reportRiskAssessList.size() <= 0){ return null; } return BeanCopyUtils.copyBeanList(reportRiskAssessList, ReportAppQueryDTO.class); } @Override public ReportRiskAssessInfo getByExperimentId(Long id) { return reportRepository.getByExperimentId(id); } }