package com.gkhy.labRiskManage.domain.riskReport.service.impl;
|
|
import com.gkhy.labRiskManage.api.controller.basic.dto.respDto.OldRiskAssessResDTO;
|
import com.gkhy.labRiskManage.api.controller.experiment.dto.req.ExperimentAndPersonInsertReqBO;
|
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.entity.OldRiskAssess;
|
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.basic.service.OldRiskAssessService;
|
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAndSite;
|
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAssessLog;
|
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.ExperimentAndTypeService;
|
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAssessLogService;
|
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.RiskPlanMethodBO;
|
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 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 org.springframework.util.StringUtils;
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
import javax.persistence.criteria.CriteriaQuery;
|
import javax.persistence.criteria.Predicate;
|
import javax.persistence.criteria.Root;
|
import java.time.LocalDateTime;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 风险评估报告
|
*/
|
@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 ExperimentAssessLogService experimentAssessLogService;
|
|
@Autowired
|
private UserDomainService userDomainService;
|
|
@Autowired
|
private RiskAssessPlanEvaluateLecService lecService;
|
@Autowired
|
private RiskAssessPlanEvaluateLsService lsService;
|
@Autowired
|
private RiskAssessPlanEvaluateMesService mesService;
|
@Autowired
|
private RiskAssessPlanEvaluateRsService rsService;
|
|
@Autowired
|
private ExperimentAndTypeService experimentAndTypeService;
|
|
@Autowired
|
private OldRiskAssessService oldRiskAssessService;
|
|
|
@Autowired
|
private RiskAssessPlanIdentificationAnalogyService analogyService;
|
@Autowired
|
private RiskAssessPlanIdentificationHazopService hazopService;
|
@Autowired
|
private RiskAssessPlanIdentificationJhaService jhaService;
|
@Autowired
|
private RiskAssessPlanIdentificationPhaService phaService;
|
@Autowired
|
private RiskAssessPlanIdentificationSclService sclService;
|
|
|
/**
|
* 风险评估报告 - 查询
|
*/
|
@Override
|
public SearchResult<ReportAppQueryDTO> 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() == ""){
|
queryBO.setExperimentName(null);
|
}
|
if (queryBO.getExportTag() == null){
|
queryBO.setExportTag(false);
|
}
|
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<ReportRiskAssessInfo> specification = new Specification<ReportRiskAssessInfo>() {
|
@Override
|
public Predicate toPredicate(Root<ReportRiskAssessInfo> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
|
List<Predicate> 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.like(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<ReportRiskAssessInfo> pageResult = reportRepository.findAll(specification, pageParam);
|
|
List<ReportQueryDTO> reportQueryDTOS = BeanCopyUtils.copyBeanList(pageResult.getContent(), ReportQueryDTO.class);
|
|
List<ReportAppQueryDTO> reportAppQueryDTOS = BeanCopyUtils.copyBeanList(reportQueryDTOS, ReportAppQueryDTO.class);
|
|
List<UserInfoDomainDTO> userList = userDomainService.getUserList();
|
|
|
for (ReportAppQueryDTO reportQueryDTO : reportAppQueryDTOS) {
|
//获取审批人员
|
List<ReportPersonQueryRespDTO> personByReportId = reportPersonService.listPersonByReportId(reportQueryDTO.getId());
|
//获取实验风险源
|
List<ReportRiskSourceQueryRespDTO> riskSourceByReportId = reportSourceService.getRiskSourceByReportId(reportQueryDTO.getId());
|
//获取风险类型
|
List<ReportSourceTypeQueryRespDTO> sourceTypeByReportId = reportSourceTypeService.getSourceTypeByReportId(reportQueryDTO.getId());
|
//获取风险类型
|
List<ReportExperimentSite> siteByReportId = reportExperimentSiteService.getSiteByReportId(reportQueryDTO.getId());
|
//获取实验信息
|
ExperimentInfoDTO experimentById = experimentInfoService.getExperimentById(reportQueryDTO.getExperimentId());
|
//获取评估计划
|
List<AssessPlanQueryDTO> assessPlanByExperimentId = assessPlanService.getAssessPlanByExperimentId(reportQueryDTO.getExperimentId());
|
reportQueryDTO.setEvaluateTime(experimentById.getCreateTime());
|
if (!ObjectUtils.isEmpty(experimentById.getProcess())){
|
reportQueryDTO.setProcess(experimentById.getProcess());
|
}
|
|
|
|
if (!ObjectUtils.isEmpty(assessPlanByExperimentId)){
|
//导出 查询辨识方法塞入数据
|
if (queryBO.getExportTag()){
|
reportQueryDTO.setRiskPlanMethodBO(getRiskPlanMethodBO(assessPlanByExperimentId));
|
}
|
for (AssessPlanQueryDTO assessPlan : assessPlanByExperimentId) {
|
|
if (assessPlan.getEvaluateTime() != null){
|
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));
|
if (queryBO.getExperimentId() != null){
|
List<ReportExperimentSiteQueryRespDTO> experimentSite = reportQueryDTO.getExperimentSite();
|
List<String> collect = experimentSite.stream().map(ReportExperimentSiteQueryRespDTO::getSiteName).collect(Collectors.toList());
|
List<OldRiskAssessResDTO> oldRiskAssessListByRegion = oldRiskAssessService.getOldRiskAssessListByRegion(collect);
|
if (!ObjectUtils.isEmpty(oldRiskAssessListByRegion)){
|
|
reportQueryDTO.setOldRiskAssess(oldRiskAssessListByRegion);
|
}
|
reportQueryDTO.setExperimentAndType(experimentAndTypeService.getByExperimentId(reportQueryDTO.getExperimentId()));
|
}
|
}
|
reportQueryDTO.setExperimentCode(experimentById.getExperimentCode());
|
|
for (UserInfoDomainDTO userInfo : userList) {
|
if (Objects.equals(userInfo.getId(), reportQueryDTO.getCreateByUserId())){
|
reportQueryDTO.setCreateByUserName(userInfo.getRealName());
|
}
|
if (Objects.equals(userInfo.getId(), reportQueryDTO.getUpdateByUserId())){
|
reportQueryDTO.setUpdateByUserName(userInfo.getRealName());
|
}
|
}
|
|
|
}
|
|
searchResult.setData(reportAppQueryDTOS);
|
searchResult.setTotal(pageResult.getTotalElements());
|
return searchResult;
|
}
|
|
private List<RiskPlanMethodBO> getRiskPlanMethodBO(List<AssessPlanQueryDTO> assessPlanByExperimentId) {
|
|
List<RiskPlanMethodBO> riskPlanMethodBOList = new ArrayList<>();
|
for (AssessPlanQueryDTO assessPlanQueryDTO : assessPlanByExperimentId) {
|
//辨识方法 1-PHA;
|
if (assessPlanQueryDTO.getIdentificationMethod() == 1) {
|
List<PhaQueryDTO> phaQueryDTOS = phaService.listPhaByPlanId(assessPlanQueryDTO.getId());
|
if (ObjectUtils.isEmpty(phaQueryDTOS)){
|
continue;
|
}
|
for (PhaQueryDTO phaQueryDTO : phaQueryDTOS) {
|
RiskPlanMethodBO riskPlanMethodBO = new RiskPlanMethodBO();
|
riskPlanMethodBO.setAssessPlanName(assessPlanQueryDTO.getAssessPlanName());
|
riskPlanMethodBO.setCheckItem(phaQueryDTO.getPhaCheckItem());
|
riskPlanMethodBO.setRiskFactor(phaQueryDTO.getPhaRiskFactor());
|
riskPlanMethodBO.setResult(phaQueryDTO.getPhaResult());
|
riskPlanMethodBO.setIdentificationMethod(assessPlanQueryDTO.getIdentificationMethod());
|
riskPlanMethodBO.setEvaluateMethod(assessPlanQueryDTO.getEvaluateMethod());
|
dealRiskPlanMethodBO(assessPlanQueryDTO,riskPlanMethodBO,phaQueryDTO.getId());
|
riskPlanMethodBOList.add(riskPlanMethodBO);
|
}
|
|
//辨识方法 2-JHA;
|
} else if (assessPlanQueryDTO.getIdentificationMethod() == 2) {
|
List<JhaQueryDTO> jhaQueryDTOS = jhaService.listJhaByPlanId(assessPlanQueryDTO.getId());
|
if (ObjectUtils.isEmpty(jhaQueryDTOS)){
|
continue;
|
}
|
for (JhaQueryDTO jhaQueryDTO : jhaQueryDTOS) {
|
RiskPlanMethodBO riskPlanMethodBO = new RiskPlanMethodBO();
|
riskPlanMethodBO.setAssessPlanName(assessPlanQueryDTO.getAssessPlanName());
|
riskPlanMethodBO.setCheckItem(jhaQueryDTO.getJhaCheckItem());
|
riskPlanMethodBO.setRiskFactor(jhaQueryDTO.getJhaRiskFactor());
|
riskPlanMethodBO.setResult(jhaQueryDTO.getJhaResult());
|
riskPlanMethodBO.setIdentificationMethod(assessPlanQueryDTO.getIdentificationMethod());
|
riskPlanMethodBO.setEvaluateMethod(assessPlanQueryDTO.getEvaluateMethod());
|
dealRiskPlanMethodBO(assessPlanQueryDTO,riskPlanMethodBO,jhaQueryDTO.getId());
|
riskPlanMethodBOList.add(riskPlanMethodBO);
|
}
|
|
//辨识方法 3-SCL;
|
} else if (assessPlanQueryDTO.getIdentificationMethod() == 3) {
|
List<SclQueryDTO> sclQueryDTOS = sclService.listSclByPlanId(assessPlanQueryDTO.getId());
|
if (ObjectUtils.isEmpty(sclQueryDTOS)){
|
continue;
|
}
|
for (SclQueryDTO sclQueryDTO : sclQueryDTOS) {
|
RiskPlanMethodBO riskPlanMethodBO = new RiskPlanMethodBO();
|
riskPlanMethodBO.setAssessPlanName(assessPlanQueryDTO.getAssessPlanName());
|
riskPlanMethodBO.setCheckItem(sclQueryDTO.getSclCheckItem());
|
riskPlanMethodBO.setRiskFactor(sclQueryDTO.getSclCheckStandard());
|
riskPlanMethodBO.setResult(sclQueryDTO.getSclCheckResult());
|
riskPlanMethodBO.setIdentificationMethod(assessPlanQueryDTO.getIdentificationMethod());
|
riskPlanMethodBO.setEvaluateMethod(assessPlanQueryDTO.getEvaluateMethod());
|
dealRiskPlanMethodBO(assessPlanQueryDTO,riskPlanMethodBO,sclQueryDTO.getId());
|
riskPlanMethodBOList.add(riskPlanMethodBO);
|
}
|
//辨识方法 4-HAZOP;
|
} else if (assessPlanQueryDTO.getIdentificationMethod() == 4) {
|
List<HazopQueryDTO> hazopQueryDTOS = hazopService.listHazopByPlanId(assessPlanQueryDTO.getId());
|
if (ObjectUtils.isEmpty(hazopQueryDTOS)){
|
continue;
|
}
|
for (HazopQueryDTO hazopQueryDTO : hazopQueryDTOS) {
|
RiskPlanMethodBO riskPlanMethodBO = new RiskPlanMethodBO();
|
riskPlanMethodBO.setAssessPlanName(assessPlanQueryDTO.getAssessPlanName());
|
riskPlanMethodBO.setCheckItem(hazopQueryDTO.getHazopNode());
|
riskPlanMethodBO.setRiskFactor(hazopQueryDTO.getHazopParam());
|
riskPlanMethodBO.setResult(hazopQueryDTO.getHazopResult());
|
riskPlanMethodBO.setIdentificationMethod(assessPlanQueryDTO.getIdentificationMethod());
|
riskPlanMethodBO.setEvaluateMethod(assessPlanQueryDTO.getEvaluateMethod());
|
dealRiskPlanMethodBO(assessPlanQueryDTO,riskPlanMethodBO,hazopQueryDTO.getId());
|
riskPlanMethodBOList.add(riskPlanMethodBO);
|
}
|
//5-类比法 analogy;
|
} else if (assessPlanQueryDTO.getIdentificationMethod() == 5) {
|
List<AnalogyQueryDTO> analogyQueryDTOS = analogyService.listAnalogyByPlanId(assessPlanQueryDTO.getId());
|
if (ObjectUtils.isEmpty(analogyQueryDTOS)){
|
continue;
|
}
|
for (AnalogyQueryDTO analogyQueryDTO : analogyQueryDTOS) {
|
RiskPlanMethodBO riskPlanMethodBO = new RiskPlanMethodBO();
|
riskPlanMethodBO.setAssessPlanName(assessPlanQueryDTO.getAssessPlanName());
|
riskPlanMethodBO.setCheckItem(analogyQueryDTO.getAnalogyCheckItem());
|
riskPlanMethodBO.setRiskFactor(analogyQueryDTO.getAnalogyRiskFactor());
|
riskPlanMethodBO.setResult(analogyQueryDTO.getAnalogyResult());
|
riskPlanMethodBO.setIdentificationMethod(assessPlanQueryDTO.getIdentificationMethod());
|
riskPlanMethodBO.setEvaluateMethod(assessPlanQueryDTO.getEvaluateMethod());
|
dealRiskPlanMethodBO(assessPlanQueryDTO,riskPlanMethodBO,analogyQueryDTO.getId());
|
riskPlanMethodBOList.add(riskPlanMethodBO);
|
}
|
}
|
}
|
return riskPlanMethodBOList;
|
}
|
|
private void dealRiskPlanMethodBO(AssessPlanQueryDTO assessPlanQueryDTO, RiskPlanMethodBO riskPlanMethodBO,Long dataId) {
|
//lec 方法
|
if (assessPlanQueryDTO.getEvaluateMethod() == 1){
|
List<RiskAssessPlanEvaluateLec> riskAssessPlanEvaluateLecs =
|
lecService.listLecByParam(assessPlanQueryDTO.getId(), dataId, assessPlanQueryDTO.getIdentificationMethod());
|
if (!ObjectUtils.isEmpty(riskAssessPlanEvaluateLecs)){
|
riskPlanMethodBO.setRiskLevel(riskAssessPlanEvaluateLecs.get(0).getRiskLevel());
|
riskPlanMethodBO.setEvaluateDesc(riskAssessPlanEvaluateLecs.get(0).getEvaluateDesc());
|
}
|
}else if (assessPlanQueryDTO.getEvaluateMethod() == 2){
|
List<RiskAssessPlanEvaluateLs> riskAssessPlanEvaluateLs = lsService.listLsByParam(assessPlanQueryDTO.getId(), dataId, assessPlanQueryDTO.getIdentificationMethod());
|
if (!ObjectUtils.isEmpty(riskAssessPlanEvaluateLs)){
|
riskPlanMethodBO.setRiskLevel(riskAssessPlanEvaluateLs.get(0).getRiskLevel());
|
riskPlanMethodBO.setEvaluateDesc(riskAssessPlanEvaluateLs.get(0).getEvaluateDesc());
|
}
|
}else if (assessPlanQueryDTO.getEvaluateMethod() == 3){
|
List<RiskAssessPlanEvaluateMes> riskAssessPlanEvaluateMes = mesService.listMesByParam(assessPlanQueryDTO.getId(), dataId, assessPlanQueryDTO.getIdentificationMethod());
|
if (!ObjectUtils.isEmpty(riskAssessPlanEvaluateMes)){
|
riskPlanMethodBO.setRiskLevel(riskAssessPlanEvaluateMes.get(0).getRiskLevel());
|
riskPlanMethodBO.setEvaluateDesc(riskAssessPlanEvaluateMes.get(0).getEvaluateDesc());
|
}
|
|
}else if (assessPlanQueryDTO.getEvaluateMethod() == 4){
|
List<RiskAssessPlanEvaluateRs> riskAssessPlanEvaluateRs = rsService.listRsByParam(assessPlanQueryDTO.getId(), dataId, assessPlanQueryDTO.getIdentificationMethod());
|
if (!ObjectUtils.isEmpty(riskAssessPlanEvaluateRs)){
|
riskPlanMethodBO.setRiskLevel(riskAssessPlanEvaluateRs.get(0).getRiskLevel());
|
riskPlanMethodBO.setEvaluateDesc(riskAssessPlanEvaluateRs.get(0).getEvaluateDesc());
|
}
|
}
|
}
|
|
|
/**
|
* 风险评估报告 - 生成报告信息
|
*/
|
@Transactional
|
@Override
|
public ReportInsertDTO insertRiskReport(Long currentUserId, Long id,String reSubmit) {
|
|
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 (!ObjectUtils.isEmpty(reSubmit) && "1".equals(reSubmit) && experimentById.getStage() >= StatusEnum.EXPERIMENT_STATUS_FINISH.getCode().byteValue()){
|
//删除已生成的报告数据
|
delReportData(id,currentUserId);
|
}else {
|
if (experimentById.getStage() == StatusEnum.EXPERIMENT_STATUS_REPORT.getCode().byteValue()){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"该实验已经生成报告,无需重复操作");
|
}
|
}
|
|
ReportRiskAssessInfo byExperimentId = reportRepository.getByExperimentId(id);
|
if (!ObjectUtils.isEmpty(byExperimentId)){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"该实验已经生成报告,请勿重复操作");
|
}
|
|
//定义初始风险等级0级
|
Byte level = 0;
|
//获取该实验的所有计划信息
|
List<AssessPlanQueryDTO> assessPlanList = assessPlanService.getAssessPlanByExperimentId(id);
|
Map<Long, String> assessPlanMap = assessPlanList.stream()
|
.collect(Collectors.toMap(
|
AssessPlanQueryDTO::getId,
|
AssessPlanQueryDTO::getAssessPlanName
|
));
|
int tag = 0;
|
StringBuilder info = new StringBuilder();
|
List<Long> 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);
|
}
|
//20250520实验责任人去掉验证
|
// UserInfoDomainDTO liabilityUser = userDomainService.getUserInfoById(experimentById.getLiabilityUserId());
|
// if (ObjectUtils.isEmpty(liabilityUser)){
|
// throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"实验责任人信息不存在");
|
// }
|
|
|
//检查该实验所有的评价结果,遍历评价结果等级
|
|
Set<Byte> riskLevelList = new HashSet<>();
|
int a = 1;
|
StringBuilder analysis = new StringBuilder();
|
List<RiskAssessPlanEvaluateLec> lecByIds = lecService.getLecByIds(assessPlanIds);
|
List<RiskAssessPlanEvaluateLs> lsByIds = lsService.getLsByIds(assessPlanIds);
|
List<RiskAssessPlanEvaluateMes> mesByIds = mesService.getMesByIds(assessPlanIds);
|
List<RiskAssessPlanEvaluateRs> rsByIds = rsService.getRsByIds(assessPlanIds);
|
|
if (lecByIds .size() > 0){
|
for (RiskAssessPlanEvaluateLec lecById : lecByIds) {
|
if (lecById.getRiskLevel() > level){
|
riskLevelList.add(lecById.getRiskLevel());
|
level = lecById.getRiskLevel();
|
analysis.append(a +(ObjectUtils.isEmpty(assessPlanMap.get(lecById.getAssessPlanId())) ? "" : assessPlanMap.get(lecById.getAssessPlanId()))+ lecById.getSafeRiskAnalysis() + ";");//todo 安全风险分析
|
a++;
|
}
|
}
|
}
|
if (lsByIds .size() > 0){
|
for (RiskAssessPlanEvaluateLs lsById : lsByIds) {
|
if (lsById.getRiskLevel() > level){
|
riskLevelList.add(lsById.getRiskLevel());
|
level = lsById.getRiskLevel();
|
analysis.append(a +(ObjectUtils.isEmpty(assessPlanMap.get(lsById.getAssessPlanId())) ? "" : assessPlanMap.get(lsById.getAssessPlanId()))+ lsById.getSafeRiskAnalysis() + ";");
|
a++;
|
}
|
}
|
}
|
if (mesByIds .size() > 0){
|
for (RiskAssessPlanEvaluateMes mesById : mesByIds) {
|
if (mesById.getRiskLevel() > level){
|
riskLevelList.add(mesById.getRiskLevel());
|
level = mesById.getRiskLevel();
|
analysis.append(a +(ObjectUtils.isEmpty(assessPlanMap.get(mesById.getAssessPlanId())) ? "" : assessPlanMap.get(mesById.getAssessPlanId()))+ mesById.getSafeRiskAnalysis() + ";");
|
a++;
|
}
|
}
|
}
|
|
if (rsByIds .size() > 0){
|
for (RiskAssessPlanEvaluateRs rsById : rsByIds) {
|
if (rsById.getRiskLevel() > level){
|
riskLevelList.add(rsById.getRiskLevel());
|
level = rsById.getRiskLevel();
|
analysis.append(a +(ObjectUtils.isEmpty(assessPlanMap.get(rsById.getAssessPlanId())) ? "" : assessPlanMap.get(rsById.getAssessPlanId()))+ 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);
|
if (ObjectUtils.isEmpty(riskLevelList)){
|
reportInfo.setAssessLevel(StatusEnum.REPORT_LEVEL_4.getCode().byteValue());
|
}else {
|
byte b = riskLevelList.stream().max(Comparator.comparing(Integer::valueOf)).get();
|
if (b == StatusEnum.REPORT_LEVEL_1.getCode().byteValue()){
|
reportInfo.setAssessLevel(StatusEnum.REPORT_LEVEL_4.getCode().byteValue());
|
}else if (b == StatusEnum.REPORT_LEVEL_2.getCode().byteValue()){
|
reportInfo.setAssessLevel(StatusEnum.REPORT_LEVEL_3.getCode().byteValue());
|
}else if (b == StatusEnum.REPORT_LEVEL_3.getCode().byteValue()){
|
reportInfo.setAssessLevel(StatusEnum.REPORT_LEVEL_2.getCode().byteValue());
|
}else if (b == StatusEnum.REPORT_LEVEL_4.getCode().byteValue()){
|
reportInfo.setAssessLevel(StatusEnum.REPORT_LEVEL_1.getCode().byteValue());
|
}
|
|
}
|
|
//todo 不确定是否需要部门
|
reportInfo.setDepId(null);
|
// reportInfo.setSafeRiskAnalysis(null);
|
|
|
|
//修改实验 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<ReportExperimentSite> reportSiteList = new ArrayList<>();
|
List<ExperimentAndSite> 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<ReportExperimentSite> reportExperimentSites = reportExperimentSiteService.insertAll(reportSiteList);
|
if (reportExperimentSites.size() < reportSiteList.size()){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告实验场所信息时失败,请稍后尝试");
|
}
|
|
//封装风险源类型信息
|
List<ReportExperimentRiskSourceType> riskSourceTypeList = RiskSourceTypeUtils.RiskSourceType(currentUserId, saveResult.getId());
|
|
//封装风
|
List<RiskUnit> riskUnitList = riskUnitService.getRiskUnitByExperimentId(id);
|
List<ReportExperimentRiskSource> 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<ReportExperimentRiskSource> riskSources = reportSourceService.insertAllReportSource(riskSourceList);
|
// if (riskSources.size() < riskSourceList.size()){
|
// throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源信息时失败,请稍后尝试");
|
// }
|
|
//写入风险源类型
|
List<ReportExperimentRiskSourceType> riskSourceTypes = reportSourceTypeService.insertAllReportSource(riskSourceTypeList);
|
if (riskSourceTypes.size() < riskSourceTypeList.size()){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR.getCode() ,"写入报告风险源类型信息时失败,请稍后尝试");
|
}
|
|
return BeanCopyUtils.copyBean(saveResult, ReportInsertDTO.class);
|
|
}
|
|
private void delReportData(Long id,Long userId){
|
ReportRiskAssessInfo byExperimentId = reportRepository.getByExperimentId(id);
|
if (!ObjectUtils.isEmpty(byExperimentId)){
|
reportRepository.delReport(userId, byExperimentId.getId());
|
reportExperimentSiteService.delReportData(byExperimentId.getId());
|
reportSourceTypeService.delReportData(byExperimentId.getId());
|
|
}
|
}
|
|
/**
|
* 风险评估报告 - 填报信息
|
*/
|
@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.setDescription(reportUpdateBO.getDescription());
|
if(!ObjectUtils.isEmpty(reportUpdateBO.getSafeRiskAnalysis())){
|
reportById.setSafeRiskAnalysis(reportUpdateBO.getSafeRiskAnalysis());
|
}
|
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<ReportPersonInsertDTO> 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<ReportPersonInsertDTO> 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
|
@Transactional
|
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<ReportPersonInsertDTO> 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<ReportPersonInsertDTO> 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() ,"实验信息状态修改失败");
|
}
|
|
//添加评估记录 todo
|
ExperimentAssessLog experimentAssessLog = new ExperimentAssessLog();
|
experimentAssessLog.setExperimentCode(experimentInfo.getExperimentCode());
|
experimentAssessLog.setAssessEndTime(date);
|
experimentAssessLog.setAssessUser(user.getRealName());
|
experimentAssessLog.setAssessResult(StatusEnum.APPROVED_PASS.getCode().byteValue());
|
ExperimentAssessLog experimentAssessLogResult = experimentAssessLogService.saveExperimentAssessLog(experimentAssessLog);
|
if (ObjectUtils.isEmpty(experimentAssessLogResult)){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息评估记录写入失败");
|
}
|
}else {
|
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() ,"审核信息保存失败");
|
}
|
}else {
|
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() ,"实验信息状态修改失败");
|
}
|
|
|
//添加评估记录 todo
|
ExperimentAssessLog experimentAssessLog = new ExperimentAssessLog();
|
experimentAssessLog.setExperimentCode(experimentInfo.getExperimentCode());
|
experimentAssessLog.setAssessEndTime(date);
|
experimentAssessLog.setAssessUser(user.getRealName());
|
experimentAssessLog.setAssessResult(StatusEnum.APPROVED_NOT_PASS.getCode().byteValue());
|
ExperimentAssessLog experimentAssessLogResult = experimentAssessLogService.saveExperimentAssessLog(experimentAssessLog);
|
if (ObjectUtils.isEmpty(experimentAssessLogResult)){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_NOT_ALLOWED.getCode() ,"实验信息评估记录写入失败");
|
}
|
}
|
|
return StatusEnum.SUCCESS.getCode();
|
}
|
|
/**
|
* 风险评估报告 - list
|
*/
|
@Override
|
public List<ReportAppQueryDTO> listRiskReport(List<Long> idList) {
|
|
List<ReportRiskAssessInfo> 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);
|
}
|
}
|