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.RiskAssessPlanIdentificationHazop;
|
import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlanIdentificationScl;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.HazopInsertDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.HazopQueryDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.IdentificationMethodDeleteDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanIdentificationHazopRepository;
|
import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanIdentificationHazopService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.context.annotation.Bean;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.ObjectUtils;
|
|
import java.time.LocalDateTime;
|
import java.util.List;
|
|
/**
|
* 辨识方法-Hazop
|
*/
|
@Service
|
public class RiskAssessPlanIdentificationHazopServiceImpl implements RiskAssessPlanIdentificationHazopService {
|
|
@Autowired
|
private RiskAssessPlanIdentificationHazopRepository hazopRepository;
|
|
/**
|
* 辨识方法-Hazop - 插入
|
*/
|
@Override
|
public HazopInsertDTO insertHazop(Long currentUserId, RiskAssessPlanIdentificationHazop hazop) {
|
|
if (ObjectUtils.isEmpty(hazop.getAssessPlanId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopNode())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_节点不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopParam())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_参数不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopParamDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_参数描述不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopGuide())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_引导词不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopDeviation())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_偏差不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopPossibleCauses())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_可能原因不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_主要后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空");
|
}
|
if (hazop.getResult() == 1){
|
if (ObjectUtils.isEmpty(hazop.getIdentificationDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空");
|
}
|
}
|
hazop.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
LocalDateTime data = LocalDateTime.now();
|
hazop.setCreateTime(data);
|
hazop.setUpdateTime(data);
|
hazop.setId(null); //参数拷贝多了,重设id为空
|
|
RiskAssessPlanIdentificationHazop insertResult = hazopRepository.save(hazop);
|
return BeanCopyUtils.copyBean(insertResult, HazopInsertDTO.class);
|
}
|
|
/**
|
* 辨识方法-Hazop - 修改
|
*/
|
@Override
|
public HazopInsertDTO updateHazop(Long currentUserId, RiskAssessPlanIdentificationHazop hazop) {
|
|
if (ObjectUtils.isEmpty(hazop.getId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
RiskAssessPlanIdentificationHazop hazopById = hazopRepository.getHazopById(hazop.getId());
|
if (ObjectUtils.isEmpty(hazopById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的辨识项不存在");
|
}
|
if (ObjectUtils.isEmpty(hazop.getAssessPlanId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopNode())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_节点不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopParam())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_参数不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopParamDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_参数描述不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopGuide())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_引导词不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopDeviation())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_偏差不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopPossibleCauses())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_可能原因不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getHazopResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "HAZOP_主要后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(hazop.getResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空");
|
}
|
if (hazop.getResult() == 1){
|
if (ObjectUtils.isEmpty(hazop.getIdentificationDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空");
|
}
|
}
|
LocalDateTime data = LocalDateTime.now();
|
hazopById.setUpdateTime(data);
|
hazopById.setHazopDeviation(hazop.getHazopDeviation());
|
hazopById.setHazopGuide(hazop.getHazopGuide());
|
hazopById.setHazopNode(hazop.getHazopNode());
|
hazopById.setHazopParam(hazop.getHazopParam());
|
hazopById.setHazopResult(hazop.getHazopResult());
|
hazopById.setHazopPossibleCauses(hazop.getHazopPossibleCauses());
|
hazopById.setHazopParamDesc(hazop.getHazopParamDesc());
|
hazopById.setFileData(hazop.getFileData());
|
// hazopById.setEducationMeasure(hazop.getEducationMeasure());
|
// hazopById.setManageMeasure(hazop.getManageMeasure());
|
// hazopById.setEmergencyMeasure(hazop.getEmergencyMeasure());
|
// hazopById.setTechnologyMeasure(hazop.getTechnologyMeasure());
|
// hazopById.setPersonalProtectionMeasure(hazop.getPersonalProtectionMeasure());
|
hazopById.setResult(hazop.getResult());
|
hazopById.setIdentificationDesc(hazop.getIdentificationDesc());
|
|
RiskAssessPlanIdentificationHazop updateResult = hazopRepository.save(hazopById);
|
|
return BeanCopyUtils.copyBean(updateResult, HazopInsertDTO.class);
|
}
|
|
/**
|
* 辨识方法-Hazop - 查询
|
*/
|
@Override
|
public HazopQueryDTO getHazopByPlanId(Long id) {
|
|
RiskAssessPlanIdentificationHazop hazopById = hazopRepository.getHazopById(id);
|
if (ObjectUtils.isEmpty(hazopById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "hazop辨识方法不存在或已被删除");
|
}
|
return BeanCopyUtils.copyBean(hazopById, HazopQueryDTO.class);
|
}
|
|
/**
|
* 辨识方法-Hazop - 删除
|
*/
|
@Override
|
public IdentificationMethodDeleteDTO deleteHazopByPlanId(Long currentUserId, Long id) {
|
|
RiskAssessPlanIdentificationHazop hazopById = hazopRepository.getHazopById(id);
|
if (ObjectUtils.isEmpty(hazopById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "Hazop辨识方法不存在或已被删除");
|
}
|
IdentificationMethodDeleteDTO deleteDTO = new IdentificationMethodDeleteDTO();
|
|
hazopById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
|
LocalDateTime data = LocalDateTime.now();
|
hazopById.setUpdateTime(data);
|
RiskAssessPlanIdentificationHazop deleteResult = hazopRepository.save(hazopById);
|
|
if (ObjectUtils.isEmpty(deleteResult)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "Hazop辨识方法不存在或已被删除");
|
}
|
deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue());
|
|
return deleteDTO;
|
}
|
|
/**
|
* 辨识方法-Hazop - 查询 -- 不校验结果
|
*/
|
@Override
|
public RiskAssessPlanIdentificationHazop checkHazopByPlanId(Long identificationId) {
|
return hazopRepository.getHazopById(identificationId);
|
}
|
|
/**
|
* 辨识方法-Hazop - list
|
*/
|
@Override
|
public List<HazopQueryDTO> listHazopByPlanId(Long id) {
|
List<RiskAssessPlanIdentificationHazop> hazopList = hazopRepository.listHazopByPlanId(id);
|
return BeanCopyUtils.copyBeanList(hazopList, HazopQueryDTO.class);
|
}
|
}
|