package com.gkhy.labRiskManage.domain.riskReport.service.impl; 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.RiskAssessPlanIdentificationAnalogy; import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlanIdentificationHazop; import com.gkhy.labRiskManage.domain.riskReport.model.dto.AnalogyInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.AnalogyQueryDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.IdentificationMethodDeleteDTO; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanIdentificationAnalogyRepository; import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanIdentificationAnalogyService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.time.LocalDateTime; import java.util.List; /** * 辨识方法-类比法(Analogy) */ @Service public class RiskAssessPlanIdentificationAnalogyServiceImpl implements RiskAssessPlanIdentificationAnalogyService { @Autowired private RiskAssessPlanIdentificationAnalogyRepository analogyRepository; /** * 辨识方法-类比法(Analogy) - 插入 */ @Override public AnalogyInsertDTO insertAnalogy(Long currentUserId, RiskAssessPlanIdentificationAnalogy analogy) { if (ObjectUtils.isEmpty(analogy.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyCheckItem())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_检查项目不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyRiskFactor())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_存在风险因素不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_可能产生的后果不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyReference())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_类比参照不能为空"); } if (ObjectUtils.isEmpty(analogy.getResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空"); } if (analogy.getResult() == 1){ if (ObjectUtils.isEmpty(analogy.getIdentificationDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空"); } } analogy.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); LocalDateTime data = LocalDateTime.now(); analogy.setCreateTime(data); analogy.setUpdateTime(data); analogy.setId(null); //参数拷贝多了,重设id为空 RiskAssessPlanIdentificationAnalogy insertResult = analogyRepository.save(analogy); return BeanCopyUtils.copyBean(insertResult, AnalogyInsertDTO.class); } /** * 辨识方法-类比法(Analogy) - 修改 */ @Override public AnalogyInsertDTO updateAnalogy(Long currentUserId, RiskAssessPlanIdentificationAnalogy analogy) { if (ObjectUtils.isEmpty(analogy.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } RiskAssessPlanIdentificationAnalogy analogyById = analogyRepository.getAnalogyById(analogy.getId()); if (ObjectUtils.isEmpty(analogyById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的辨识项不存在"); } if (ObjectUtils.isEmpty(analogy.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyCheckItem())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_检查项目不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyRiskFactor())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_存在风险因素不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_可能产生的后果不能为空"); } if (ObjectUtils.isEmpty(analogy.getAnalogyReference())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法_类比参照不能为空"); } if (ObjectUtils.isEmpty(analogy.getResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空"); } if (analogy.getResult() == 1){ if (ObjectUtils.isEmpty(analogy.getIdentificationDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空"); } } LocalDateTime data = LocalDateTime.now(); analogyById.setUpdateTime(data); analogyById.setAnalogyReference(analogy.getAnalogyReference()); analogyById.setAnalogyCheckItem(analogy.getAnalogyCheckItem()); analogyById.setAnalogyResult(analogy.getAnalogyResult()); analogyById.setAnalogyRiskFactor(analogy.getAnalogyRiskFactor()); // analogyById.setEducationMeasure(analogy.getEducationMeasure()); // analogyById.setManageMeasure(analogy.getManageMeasure()); // analogyById.setEmergencyMeasure(analogy.getEmergencyMeasure()); // analogyById.setTechnologyMeasure(analogy.getTechnologyMeasure()); // analogyById.setPersonalProtectionMeasure(analogy.getPersonalProtectionMeasure()); analogyById.setResult(analogy.getResult()); analogyById.setIdentificationDesc(analogy.getIdentificationDesc()); RiskAssessPlanIdentificationAnalogy insertResult = analogyRepository.save(analogyById); return BeanCopyUtils.copyBean(insertResult, AnalogyInsertDTO.class); } /** * 辨识方法-类比法(Analogy) - 查询 */ @Override public AnalogyQueryDTO getAnalogyByPlanId(Long id) { RiskAssessPlanIdentificationAnalogy analogyById = analogyRepository.getAnalogyById(id); if (ObjectUtils.isEmpty(analogyById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "类比法(Analogy)辨识方法不存在或已被删除"); } return BeanCopyUtils.copyBean(analogyById, AnalogyQueryDTO.class); } /** * 辨识方法-类比法(Analogy) - 删除 */ @Override public IdentificationMethodDeleteDTO deleteAnalogyByPlanId(Long currentUserId, Long id) { RiskAssessPlanIdentificationAnalogy analogyById = analogyRepository.getAnalogyById(id); if (ObjectUtils.isEmpty(analogyById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "Hazop辨识方法不存在或已被删除"); } IdentificationMethodDeleteDTO deleteDTO = new IdentificationMethodDeleteDTO(); analogyById.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); LocalDateTime data = LocalDateTime.now(); analogyById.setUpdateTime(data); RiskAssessPlanIdentificationAnalogy deleteResult = analogyRepository.save(analogyById); if (ObjectUtils.isEmpty(deleteResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "Hazop辨识方法不存在或已被删除"); } deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue()); return deleteDTO; } /** * 辨识方法-类比法(Analogy) - 查询 -- 不校验结果 */ @Override public RiskAssessPlanIdentificationAnalogy checkAnalogyByPlanId(Long identificationId) { return analogyRepository.getAnalogyById(identificationId); } /** * 辨识方法-类比法(Analogy) - list */ @Override public List listAnalogyByPlanId(Long id) { List analogyList = analogyRepository.listAnalogyByPlanId(id); return BeanCopyUtils.copyBeanList(analogyList, AnalogyQueryDTO.class); } }