package com.gkhy.labRiskManage.domain.riskReport.service.impl; import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.RiskAssessPlanEvaluateDeleteReqBO; import com.gkhy.labRiskManage.commons.enums.MethodEnum; import com.gkhy.labRiskManage.commons.enums.ResultCode; import com.gkhy.labRiskManage.commons.enums.StatusEnum; import com.gkhy.labRiskManage.commons.exception.BusinessException; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlanEvaluateLec; import com.gkhy.labRiskManage.domain.riskReport.model.bo.AssessLecInsertBO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.EvaluateInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.EvaluateMethodDeleteDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.LecInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.LecQueryDTO; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanEvaluateLecRepository; import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanEvaluateLecService; import com.gkhy.labRiskManage.domain.riskReport.utils.IdentificationMethodCheck; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; /** * 评价方法LEC */ @Service public class RiskAssessPlanEvaluateLecServiceImpl implements RiskAssessPlanEvaluateLecService { @Autowired private RiskAssessPlanEvaluateLecRepository lecRepository; /** * 评价方法LEC - 评价插入 */ @Override public LecInsertDTO insertLec(Long currentUserId, AssessLecInsertBO lecInsertBO) { EvaluateInsertDTO insertDTO = new EvaluateInsertDTO(); insertDTO.setResult(1); IdentificationMethodCheck methodCheck = new IdentificationMethodCheck(); //校验辨识方法是否存在 int result = methodCheck.identificationMethodCheck(lecInsertBO.getIdentificationId(), lecInsertBO.getIdentificationMethod()); if (result == 0){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识方法不存在"); } if (ObjectUtils.isEmpty(lecInsertBO.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价的计划不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecL())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_L的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecE())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_E的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecC())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_C的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getRiskValue())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getIdentificationId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识方法不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getIdentificationMethod())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识方法类型不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecL())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_L的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecE())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_E的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecC())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_C的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalRiskValue())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有风险数值不能为空"); } RiskAssessPlanEvaluateLec lecByIdentification = lecRepository.getLecByIdentification(lecInsertBO.getIdentificationId(), lecInsertBO.getIdentificationMethod()); if (!ObjectUtils.isEmpty(lecByIdentification)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "该辨识已经被评价,无需重复操作"); } if (ObjectUtils.isEmpty(lecInsertBO.getEvaluateDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价专家意见不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getSafeRiskAnalysis())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "安全风险分析内容不能为空"); } BigDecimal valueL = lecInsertBO.getLecL(); BigDecimal valueE = lecInsertBO.getLecE(); BigDecimal valueC = lecInsertBO.getLecC(); BigDecimal value = valueL.multiply(valueE).multiply(valueC); //BigDecimal类型比较,结果为0是相等 if (value.compareTo(lecInsertBO.getRiskValue()) != 0){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值计算有误,无法保存"); } RiskAssessPlanEvaluateLec lec = new RiskAssessPlanEvaluateLec(); //设置参数 if (value.compareTo(new BigDecimal(10)) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_1.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_1.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_1.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_1.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_2.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_2.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_2.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_3.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_3.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_3.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) > 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_4.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_4.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_4.getCode()); } LocalDateTime date = LocalDateTime.now(); lec.setAssessPlanId(lecInsertBO.getAssessPlanId()); lec.setIdentificationId(lecInsertBO.getIdentificationId()); lec.setIdentificationMethod(lecInsertBO.getIdentificationMethod()); lec.setLecL(lecInsertBO.getLecL()); lec.setLecE(lecInsertBO.getLecE()); lec.setLecC(lecInsertBO.getLecC()); lec.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); lec.setCreateTime(date); lec.setUpdateTime(date); lec.setRiskValue(lecInsertBO.getRiskValue()); lec.setManageLevel(lecInsertBO.getManageLevel()); lec.setStatus((byte) 1); lec.setEvaluateDesc(lecInsertBO.getEvaluateDesc()); lec.setEducationMeasure(lecInsertBO.getEducationMeasure()); lec.setTechnologyMeasure(lecInsertBO.getTechnologyMeasure()); lec.setManageMeasure(lecInsertBO.getManageMeasure()); lec.setPersonalProtectionMeasure(lecInsertBO.getPersonalProtectionMeasure()); lec.setEmergencyMeasure(lecInsertBO.getEmergencyMeasure()); lec.setOriginalLecL(lecInsertBO.getOriginalLecL()); lec.setOriginalLecE(lecInsertBO.getOriginalLecE()); lec.setOriginalLecC(lecInsertBO.getOriginalLecC()); lec.setOriginalRiskValue(lecInsertBO.getOriginalRiskValue()); lec.setOriginalRiskLevelValue(lecInsertBO.getOriginalRiskLevelValue()); lec.setOriginalRiskLevel(lecInsertBO.getOriginalRiskLevel()); lec.setOriginalRiskColor(lecInsertBO.getOriginalRiskColor()); lec.setOriginalManageLevel(lecInsertBO.getOriginalManageLevel()); lec.setAdviseTechnologyMeasure(lecInsertBO.getAdviseTechnologyMeasure()); lec.setAdviseManageMeasure(lecInsertBO.getAdviseManageMeasure()); lec.setAdviseEmergencyMeasure(lecInsertBO.getAdviseEmergencyMeasure()); lec.setAdviseEducationMeasure(lecInsertBO.getAdviseEducationMeasure()); lec.setAdvisePersonalProtectionMeasure(lecInsertBO.getAdvisePersonalProtectionMeasure()); lec.setSafeRiskAnalysis(lecInsertBO.getSafeRiskAnalysis()); RiskAssessPlanEvaluateLec insertResult = lecRepository.save(lec); return BeanCopyUtils.copyBean(insertResult, LecInsertDTO.class); } /** * 评价方法LEC - 修改 */ @Override public LecInsertDTO updateLec(Long currentUserId, AssessLecInsertBO lecInsertBO) { EvaluateInsertDTO insertDTO = new EvaluateInsertDTO(); insertDTO.setResult(1); if (ObjectUtils.isEmpty(lecInsertBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的评价内容不能为空"); } RiskAssessPlanEvaluateLec lecById = lecRepository.getLecById(lecInsertBO.getId()); if (ObjectUtils.isEmpty(lecById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的评价不存在"); } if (ObjectUtils.isEmpty(lecInsertBO.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价的计划不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecL())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_L的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecE())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_E的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getLecC())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LEC_C的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getRiskValue())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecL())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_L的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecE())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_E的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalLecC())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LEC_C的数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getOriginalRiskValue())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有风险数值不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getEvaluateDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价专家意见不能为空"); } if (ObjectUtils.isEmpty(lecInsertBO.getSafeRiskAnalysis())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "安全风险分析内容不能为空"); } BigDecimal valueL = lecInsertBO.getLecL(); BigDecimal valueE = lecInsertBO.getLecE(); BigDecimal valueC = lecInsertBO.getLecC(); BigDecimal value = valueL.multiply(valueE).multiply(valueC); //BigDecimal类型比较,结果为0是相等 if (value.compareTo(lecInsertBO.getRiskValue()) != 0){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值计算有误,无法保存"); } //设置参数 RiskAssessPlanEvaluateLec lec = BeanCopyUtils.copyBean(lecById, RiskAssessPlanEvaluateLec.class); LocalDateTime date = LocalDateTime.now(); if (value.compareTo(new BigDecimal(10)) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_1.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_1.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_1.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_1.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_2.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_2.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_2.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) < 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_3.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_3.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_3.getCode()); }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) > 0){ lec.setRiskLevel(MethodEnum.RISK_LEVEL_4.getCode()); lec.setRiskLevelValue(MethodEnum.RISK_LEVEL_4.getCode()); lec.setRiskColor(MethodEnum.RISK_LEVEL_4.getCode()); } lec.setLecL(lecInsertBO.getLecL()); lec.setLecE(lecInsertBO.getLecE()); lec.setLecC(lecInsertBO.getLecC()); lec.setUpdateTime(date); lec.setRiskValue(lecInsertBO.getRiskValue()); lec.setManageLevel(lecInsertBO.getManageLevel()); lec.setEvaluateDesc(lecInsertBO.getEvaluateDesc()); lec.setEducationMeasure(lecInsertBO.getEducationMeasure()); lec.setTechnologyMeasure(lecInsertBO.getTechnologyMeasure()); lec.setManageMeasure(lecInsertBO.getManageMeasure()); lec.setPersonalProtectionMeasure(lecInsertBO.getPersonalProtectionMeasure()); lec.setEmergencyMeasure(lecInsertBO.getEmergencyMeasure()); lec.setOriginalLecL(lecInsertBO.getOriginalLecL()); lec.setOriginalLecE(lecInsertBO.getOriginalLecE()); lec.setOriginalLecC(lecInsertBO.getOriginalLecC()); lec.setOriginalRiskValue(lecInsertBO.getOriginalRiskValue()); lec.setOriginalRiskLevelValue(lecInsertBO.getOriginalRiskLevelValue()); lec.setOriginalRiskLevel(lecInsertBO.getOriginalRiskLevel()); lec.setOriginalRiskColor(lecInsertBO.getOriginalRiskColor()); lec.setOriginalManageLevel(lecInsertBO.getOriginalManageLevel()); lec.setAdviseTechnologyMeasure(lecInsertBO.getAdviseTechnologyMeasure()); lec.setAdviseManageMeasure(lecInsertBO.getAdviseManageMeasure()); lec.setAdviseEmergencyMeasure(lecInsertBO.getAdviseEmergencyMeasure()); lec.setAdviseEducationMeasure(lecInsertBO.getAdviseEducationMeasure()); lec.setAdvisePersonalProtectionMeasure(lecInsertBO.getAdvisePersonalProtectionMeasure()); lec.setSafeRiskAnalysis(lecInsertBO.getSafeRiskAnalysis()); RiskAssessPlanEvaluateLec insertResult = lecRepository.save(lec); return BeanCopyUtils.copyBean(insertResult, LecInsertDTO.class); } /** * 评价方法LEC - 查询 */ @Override public LecQueryDTO getLecByPlanId(Long id) { RiskAssessPlanEvaluateLec lecById = lecRepository.getLecById(id); if (ObjectUtils.isEmpty(lecById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "lec评价方法不存在或已被删除"); } return BeanCopyUtils.copyBean(lecById, LecQueryDTO.class); } /** * 评价方法LEC - 删除 */ @Override public EvaluateMethodDeleteDTO deleteLecByPlanId(Long currentUserId, RiskAssessPlanEvaluateDeleteReqBO deleteReqBO) { if (ObjectUtils.isEmpty(deleteReqBO.getLecId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要删除的评价项目不能为空"); } RiskAssessPlanEvaluateLec lecById = lecRepository.getLecById(deleteReqBO.getLecId()); if (ObjectUtils.isEmpty(lecById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要删除的评价项目为空,或已被删除"); } if (!lecById.getAssessPlanId().equals(deleteReqBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评估计划与评价项不匹配,无法删除"); } EvaluateMethodDeleteDTO deleteDTO = new EvaluateMethodDeleteDTO(); LocalDateTime date = LocalDateTime.now(); lecById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue()); lecById.setUpdateTime(date); RiskAssessPlanEvaluateLec deleteResult = lecRepository.save(lecById); if (ObjectUtils.isEmpty(deleteResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价方法不存在或已被删除"); } deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue()); return deleteDTO; } /** * 评价方法LEC - list */ @Override public List listLecByPlanId(Long id) { List lecList = lecRepository.listLecByPlanId(id); return BeanCopyUtils.copyBeanList(lecList, LecQueryDTO.class); } @Override public List getLecByIds(List assessPlanIds) { List lecByIds = lecRepository.getLecByIds(assessPlanIds); return lecByIds; } @Override public int deleteLecByAssessPlanId(Long assessPlanId) { List lecList = lecRepository.getbyByAssessPlanId(assessPlanId); if (lecList.size() < 1){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价方法不存在或已被删除"); } int i = 0; for (RiskAssessPlanEvaluateLec lec : lecList) { lec.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue()); RiskAssessPlanEvaluateLec save = lecRepository.save(lec); if (ObjectUtils.isEmpty(save)){ i = 1; } } return i; } @Override public int deleteLecByPlan(Long id) { List lecListByPlanId = lecRepository.getLecByPlanId(id); if (ObjectUtils.isEmpty(lecListByPlanId)){ return StatusEnum.SUCCESS.getCode(); } for (RiskAssessPlanEvaluateLec riskAssessPlanEvaluateLec : lecListByPlanId) { riskAssessPlanEvaluateLec.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue()); } List result = lecRepository.saveAll(lecListByPlanId); if (result.size() != lecListByPlanId.size()){ return StatusEnum.FAIL.getCode(); } return StatusEnum.SUCCESS.getCode(); } @Override public RiskAssessPlanEvaluateLec getLecByIdentificationId(Long identificationId, Byte identificationMethod) { return lecRepository.getLecByIdentification(identificationId, identificationMethod); } }