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.RiskAssessPlanIdentificationJha; import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlanIdentificationPha; import com.gkhy.labRiskManage.domain.riskReport.model.dto.IdentificationMethodDeleteDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.JhaInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.JhaQueryDTO; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanIdentificationJhaRepository; import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanIdentificationJhaService; 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; /** * 辨识方法-Jha */ @Service public class RiskAssessPlanIdentificationJhaServiceImpl implements RiskAssessPlanIdentificationJhaService { @Autowired private RiskAssessPlanIdentificationJhaRepository jhaRepository; /** * 辨识方法-Jha -- 插入 */ @Override public JhaInsertDTO insertJha(Long currentUserId, RiskAssessPlanIdentificationJha jha) { if (ObjectUtils.isEmpty(jha.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaCheckItem())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_作业步骤不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaRiskFactor())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_危险源或潜在事件不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_可能发生的事故类型及后果不能为空"); } if (ObjectUtils.isEmpty(jha.getResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空"); } if (jha.getResult() == 1){ if (ObjectUtils.isEmpty(jha.getIdentificationDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空"); } } jha.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); LocalDateTime data = LocalDateTime.now(); jha.setCreateTime(data); jha.setUpdateTime(data); jha.setId(null); //参数拷贝多了,重设id为空 RiskAssessPlanIdentificationJha insertResult = jhaRepository.save(jha); return BeanCopyUtils.copyBean(insertResult, JhaInsertDTO.class); } /** * 辨识方法-Jha -- 修改 */ @Override public JhaInsertDTO updateJha(Long currentUserId, RiskAssessPlanIdentificationJha jha) { if (ObjectUtils.isEmpty(jha.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } RiskAssessPlanIdentificationJha jhaById = jhaRepository.getJhaById(jha.getId()); if (ObjectUtils.isEmpty(jhaById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的辨识项不存在"); } if (ObjectUtils.isEmpty(jha.getAssessPlanId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaCheckItem())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_作业步骤不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaRiskFactor())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_危险源或潜在事件不能为空"); } if (ObjectUtils.isEmpty(jha.getJhaResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "JHA_可能发生的事故类型及后果不能为空"); } if (ObjectUtils.isEmpty(jha.getResult())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空"); } if (jha.getResult() == 1){ if (ObjectUtils.isEmpty(jha.getIdentificationDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空"); } } LocalDateTime data = LocalDateTime.now(); jhaById.setUpdateTime(data); jhaById.setJhaResult(jha.getJhaResult()); jhaById.setJhaRiskFactor(jha.getJhaRiskFactor()); jhaById.setJhaCheckItem(jha.getJhaCheckItem()); // jhaById.setEducationMeasure(jha.getEducationMeasure()); // jhaById.setManageMeasure(jha.getManageMeasure()); // jhaById.setEmergencyMeasure(jha.getEmergencyMeasure()); // jhaById.setTechnologyMeasure(jha.getTechnologyMeasure()); // jhaById.setPersonalProtectionMeasure(jha.getPersonalProtectionMeasure()); jhaById.setResult(jha.getResult()); jhaById.setIdentificationDesc(jha.getIdentificationDesc()); RiskAssessPlanIdentificationJha updateResult = jhaRepository.save(jhaById); return BeanCopyUtils.copyBean(updateResult, JhaInsertDTO.class); } /** * 辨识方法-Jha -- 查询 */ @Override public JhaQueryDTO getJhaByPlanId(Long id) { RiskAssessPlanIdentificationJha jhaById = jhaRepository.getJhaById(id); if (ObjectUtils.isEmpty(jhaById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "jha辨识方法不存在或已被删除"); } return BeanCopyUtils.copyBean(jhaById, JhaQueryDTO.class); } /** * 辨识方法-Jha -- 删除 */ @Override public IdentificationMethodDeleteDTO deleteJhaByPlanId(Long currentUserId, Long id) { RiskAssessPlanIdentificationJha jhaById = jhaRepository.getJhaById(id); if (ObjectUtils.isEmpty(jhaById)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "jha辨识方法不存在或已被删除"); } IdentificationMethodDeleteDTO deleteDTO = new IdentificationMethodDeleteDTO(); LocalDateTime data = LocalDateTime.now(); jhaById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue()); jhaById.setUpdateTime(data); RiskAssessPlanIdentificationJha deleteResult = jhaRepository.save(jhaById); if (ObjectUtils.isEmpty(deleteResult)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "jha辨识方法不存在或已被删除"); } deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue()); jhaRepository.getJhaById(id); return deleteDTO; } /** * 辨识方法-Jha -- 查询 --不校验结果 */ @Override public RiskAssessPlanIdentificationJha checkJhaByPlanId(Long identificationId) { return jhaRepository.getJhaById(identificationId); } /** * 辨识方法-Jha -- list */ @Override public List listJhaByPlanId(Long id) { List jhaList = jhaRepository.listJhaByPlanId(id); return BeanCopyUtils.copyBeanList(jhaList, JhaQueryDTO.class); } }