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.RiskAssessPlanIdentificationPha;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.IdentificationMethodDeleteDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.PhaInsertDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.model.dto.PhaQueryDTO;
|
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanIdentificationPhaRepository;
|
import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanIdentificationPhaService;
|
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;
|
|
/**
|
* 辨识方法-Pha
|
*/
|
@Service
|
public class RiskAssessPlanIdentificationPhaServiceImpl implements RiskAssessPlanIdentificationPhaService {
|
|
@Autowired
|
private RiskAssessPlanIdentificationPhaRepository phaRepository;
|
|
/**
|
* 辨识方法-Pha - 插入
|
*/
|
@Override
|
public PhaInsertDTO insertPha(Long currentUserId, RiskAssessPlanIdentificationPha pha) {
|
|
if (ObjectUtils.isEmpty(pha.getAssessPlanId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaCheckItem())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_检查项目不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaRiskFactor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_存在风险因素不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_可能产生的后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空");
|
}
|
if (pha.getResult() == 1){
|
if (ObjectUtils.isEmpty(pha.getIdentificationDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空");
|
}
|
}
|
LocalDateTime data = LocalDateTime.now();
|
pha.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
pha.setCreateTime(data);
|
pha.setUpdateTime(data);
|
pha.setId(null); //参数拷贝多了,重设id为空
|
|
RiskAssessPlanIdentificationPha insertResult = phaRepository.save(pha);
|
return BeanCopyUtils.copyBean(insertResult, PhaInsertDTO.class);
|
}
|
|
/**
|
* 辨识方法-Pha - 修改
|
*/
|
@Override
|
public PhaInsertDTO updatePha(Long currentUserId, RiskAssessPlanIdentificationPha pha) {
|
|
if (ObjectUtils.isEmpty(pha.getId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
RiskAssessPlanIdentificationPha phaById = phaRepository.getPhaById(pha.getId());
|
|
if (ObjectUtils.isEmpty(phaById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的辨识项不存在");
|
}
|
if (ObjectUtils.isEmpty(pha.getAssessPlanId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识的计划不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaCheckItem())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_检查项目不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaRiskFactor())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_存在风险因素不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getPhaResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "PHA_可能产生的后果不能为空");
|
}
|
if (ObjectUtils.isEmpty(pha.getResult())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识结果不能为空");
|
}
|
if (pha.getResult() == 1){
|
if (ObjectUtils.isEmpty(pha.getIdentificationDesc())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识专家意见不能为空");
|
}
|
}
|
LocalDateTime data = LocalDateTime.now();
|
phaById.setUpdateTime(data);
|
phaById.setPhaResult(pha.getPhaResult());
|
phaById.setPhaRiskFactor(pha.getPhaRiskFactor());
|
phaById.setPhaCheckItem(pha.getPhaCheckItem());
|
phaById.setFileData(pha.getFileData());
|
// phaById.setEducationMeasure(pha.getEducationMeasure());
|
// phaById.setManageMeasure(pha.getManageMeasure());
|
// phaById.setEmergencyMeasure(pha.getEmergencyMeasure());
|
// phaById.setTechnologyMeasure(pha.getTechnologyMeasure());
|
// phaById.setPersonalProtectionMeasure(pha.getPersonalProtectionMeasure());
|
phaById.setResult(pha.getResult());
|
phaById.setIdentificationDesc(pha.getIdentificationDesc());
|
|
RiskAssessPlanIdentificationPha updateResult = phaRepository.save(phaById);
|
|
return BeanCopyUtils.copyBean(updateResult, PhaInsertDTO.class);
|
}
|
|
/**
|
* 辨识方法-Pha - 查询
|
*/
|
@Override
|
public PhaQueryDTO getPhaByPlanId(Long id) {
|
RiskAssessPlanIdentificationPha phaById = phaRepository.getPhaById(id);
|
if (ObjectUtils.isEmpty(phaById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "pha辨识方法不存在或已被删除");
|
}
|
return BeanCopyUtils.copyBean(phaById, PhaQueryDTO.class);
|
}
|
|
/**
|
* 辨识方法-Pha - 删除
|
*/
|
@Override
|
public IdentificationMethodDeleteDTO deletePhaByPlanId(Long currentUserId, Long id) {
|
|
RiskAssessPlanIdentificationPha phaById = phaRepository.getPhaById(id);
|
if (ObjectUtils.isEmpty(phaById)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "pha辨识方法不存在或已被删除");
|
}
|
IdentificationMethodDeleteDTO deleteDTO = new IdentificationMethodDeleteDTO();
|
LocalDateTime data = LocalDateTime.now();
|
|
// RiskAssessPlanIdentificationPha deleteResult = phaRepository.deletePhaByPlanId(id, data);
|
|
phaById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
|
phaById.setUpdateTime(data);
|
|
RiskAssessPlanIdentificationPha deleteResult = phaRepository.save(phaById);
|
|
if (ObjectUtils.isEmpty(deleteResult)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "pha辨识方法不存在或已被删除");
|
}
|
deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue());
|
|
return deleteDTO;
|
}
|
|
/**
|
* 辨识方法-Pha - 查询 - 不校验结果
|
*/
|
@Override
|
public RiskAssessPlanIdentificationPha checkPhaByPlanId(Long identificationId) {
|
RiskAssessPlanIdentificationPha phaById = phaRepository.getPhaById(identificationId);
|
return phaById;
|
}
|
|
/**
|
* 辨识方法-Pha - list
|
*/
|
@Override
|
public List<PhaQueryDTO> listPhaByPlanId(Long id) {
|
List<RiskAssessPlanIdentificationPha> phaList = phaRepository.listPhaByPlanId(id);
|
return BeanCopyUtils.copyBeanList(phaList, PhaQueryDTO.class);
|
}
|
}
|