package com.gkhy.labRiskManage.domain.riskReport.service.impl; import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.ReportReqBO; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportPersonQueryRespDTO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportPersonAppInsertBO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportPersonAppUpdateBO; 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.basic.model.dto.PersonQueryDTO; import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService; import com.gkhy.labRiskManage.domain.riskReport.entity.ReportRiskAssessPerson; import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportPersonInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportRiskAssessPersonRepository; import com.gkhy.labRiskManage.domain.riskReport.service.ReportRiskAssessPersonService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; /** * 风险评估报告-评估专家 */ @Service public class ReportRiskAssessPersonServiceImpl implements ReportRiskAssessPersonService { @Autowired private ReportRiskAssessPersonRepository personRepository; @Autowired private BasicExperimentPersonService basicPersonService; /** * 风险评估报告-评估专家 - 插入 */ @Override public List insertReportPerson(Long currentUserId, List personInsertBO) { if (personInsertBO.size() < 1){ List list= new ArrayList<>(); return list; } List reportPeopleList = BeanCopyUtils.copyBeanList(personInsertBO, ReportRiskAssessPerson.class); List personList = new ArrayList<>(); for (ReportRiskAssessPerson reportPerson : reportPeopleList) { if (ObjectUtils.isEmpty(reportPerson.getReportId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "用户信息不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveStage())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段名称不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveIndex())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段排序不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批意见说明不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApprovePersonId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人不能为空"); } PersonQueryDTO personById = basicPersonService.getBasicExperimentPersonById(reportPerson.getApprovePersonId()); if (ObjectUtils.isEmpty(personById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "审批人不能为空"); } //补全数据 LocalDateTime date = LocalDateTime.now(); reportPerson.setApprovePerson(personById.getPersonName()); reportPerson.setCreateTime(date); reportPerson.setUpdateTime(date); reportPerson.setCreateByUserId(currentUserId); reportPerson.setUpdateByUserId(currentUserId); reportPerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); reportPerson.setApproveStatus(StatusEnum.EXPERIMENT_STATUS_NOT_START.getCode().byteValue()); personList.add(reportPerson); } List insertResult = personRepository.saveAll(personList); if (insertResult.size() != personInsertBO.size()){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人写入失败"); } return BeanCopyUtils.copyBeanList(insertResult, ReportPersonInsertDTO.class); } /** * 风险评估报告-评估专家 - 修改 */ @Override public List updateReportPerson(Long currentUserId, List personUpdateBO) { if (personUpdateBO.size() < 1){ List list= new ArrayList<>(); return list; } List reportPeopleList = BeanCopyUtils.copyBeanList(personUpdateBO, ReportRiskAssessPerson.class); List personList = new ArrayList<>(); for (ReportRiskAssessPerson reportPerson : reportPeopleList) { if (ObjectUtils.isEmpty(reportPerson.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审核人id不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getReportId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "用户信息不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveStage())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段名称不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveIndex())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批阶段排序不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApproveDesc())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批意见说明不能为空"); } if (ObjectUtils.isEmpty(reportPerson.getApprovePersonId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人不能为空"); } if (reportPerson.getApproveStatus() == StatusEnum.REPORT_APPROVED.getCode().byteValue()){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "审批人已经提交审核结果,无法修改信息"); } PersonQueryDTO personById = basicPersonService.getBasicExperimentPersonById(reportPerson.getApprovePersonId()); if (ObjectUtils.isEmpty(personById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(), "审批人不能为空"); } ReportRiskAssessPerson person = personRepository.getPersonById(reportPerson.getId()); //补全数据 LocalDateTime date = LocalDateTime.now(); person.setApprovePerson(personById.getPersonName()); person.setUpdateTime(date); person.setUpdateByUserId(currentUserId); person.setApproveIndex(reportPerson.getApproveIndex()); person.setApproveStage(reportPerson.getApproveStage()); person.setApproveDesc(reportPerson.getApproveDesc()); person.setApprovePersonId(reportPerson.getApprovePersonId()); personList.add(person); } List updateResult = personRepository.saveAll(personList); if (updateResult.size() != personUpdateBO.size()){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人写入失败"); } return BeanCopyUtils.copyBeanList(updateResult, ReportPersonInsertDTO.class); } /** * 风险评估报告-评估专家 - 查询 */ @Override public ReportPersonInsertDTO getPersonById(Long id) { if (ObjectUtils.isEmpty(id)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告审核人不能为空"); } ReportRiskAssessPerson personById = personRepository.getPersonById(id); if (ObjectUtils.isEmpty(personById)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审批人不存在或已被删除"); } return BeanCopyUtils.copyBean(personById, ReportPersonInsertDTO.class); } /** * 风险评估报告-评估专家 - list */ @Override public List getPersonByReportId(Long reportId) { if (ObjectUtils.isEmpty(reportId)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空"); } List personList = personRepository.getPersonByReportId(reportId); if (ObjectUtils.isEmpty(personList)){ return null; } return BeanCopyUtils.copyBeanList(personList, ReportPersonInsertDTO.class); } /** * 风险评估报告-评估专家 */ @Override public List listPersonByReportId(Long id) { if (ObjectUtils.isEmpty(id)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空"); } List personList = personRepository.getPersonByReportId(id); if (ObjectUtils.isEmpty(personList)){ return null; } return BeanCopyUtils.copyBeanList(personList, ReportPersonQueryRespDTO.class); } /** * 风险评估报告-评估专家 - 审核 */ @Transactional @Override public ReportPersonInsertDTO report(Long currentUserId, ReportReqBO reportReqBO) { if (ObjectUtils.isEmpty(reportReqBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"报告id不能为空"); } if (ObjectUtils.isEmpty(reportReqBO.getApproveStatus())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode() ,"审批状态不能为空"); } //获取审核人信息 ReportRiskAssessPerson personById = personRepository.getPersonById(reportReqBO.getId()); LocalDateTime date = LocalDateTime.now(); personById.setApproveDesc(reportReqBO.getApproveDesc()); personById.setApproveTime(date); personById.setApproveStatus(reportReqBO.getApproveStatus()); ReportRiskAssessPerson save = personRepository.save(personById); if (ObjectUtils.isEmpty(save)){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "审核失败"); } return BeanCopyUtils.copyBean(save, ReportPersonInsertDTO.class); } @Override public ReportRiskAssessPerson insertOneReportPerson(ReportRiskAssessPerson approvePerson) { return personRepository.save(approvePerson); } }