package com.gkhy.labRiskManage.domain.riskReport.service.impl; import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportRiskSourceQueryRespDTO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportSourceAppInsertBO; import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportSourceAppUpdateBO; 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.account.service.UserDomainService; import com.gkhy.labRiskManage.domain.riskReport.entity.ReportExperimentRiskSource; import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportSourceInsertBO; import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportSourceUpdateBO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportPersonInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportRiskSourceDTO; import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportSourceTypeInsertDTO; import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportExperimentRiskSourceRepository; import com.gkhy.labRiskManage.domain.riskReport.service.ReportExperimentRiskSourceService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.ObjectUtils; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.List; /** * */ @Service public class ReportExperimentRiskSourceServiceImpl implements ReportExperimentRiskSourceService { @Autowired private ReportExperimentRiskSourceRepository riskSourceRepository; @Autowired private UserDomainService userDomainService; /** * 风险评估报告-危险因素 - 插入 */ @Override public List insertReportSource(Long currentUserId, List riskSourceInsertBO) { if (riskSourceInsertBO.size() < 1){ List list= new ArrayList<>(); return list; } List reportSourceInsertBO = BeanCopyUtils.copyBeanList(riskSourceInsertBO, ReportSourceInsertBO.class); List riskSourceLists = new ArrayList<>(); for (ReportSourceInsertBO sourceInsertBO : reportSourceInsertBO) { if (ObjectUtils.isEmpty(sourceInsertBO.getReportId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "报告id不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSource())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险源不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskCharacteristic())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险特性不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getNumber())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "数量不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSourceIndex())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "排序不能为空"); } ReportExperimentRiskSource riskSource = BeanCopyUtils.copyBean(sourceInsertBO, ReportExperimentRiskSource.class); //补全数据 LocalDateTime date = LocalDateTime.now(); riskSource.setCreateTime(date); riskSource.setUpdateTime(date); riskSource.setCreateByUserId(currentUserId); riskSource.setUpdateByUserId(currentUserId); riskSource.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); riskSourceLists.add(riskSource); } List insertResult = riskSourceRepository.saveAll(riskSourceLists); if (insertResult.size() != reportSourceInsertBO.size()){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险源写入失败"); } return BeanCopyUtils.copyBeanList(insertResult, ReportRiskSourceDTO.class); } /** * 风险评估报告-危险因素 - 修改 */ @Override public List updateReportSource(Long currentUserId, List riskSourceUpdateBO) { if (riskSourceUpdateBO.size() < 1){ List list= new ArrayList<>(); return list; } List reportSourceUpdateBO = BeanCopyUtils.copyBeanList(riskSourceUpdateBO, ReportSourceUpdateBO.class); List riskSourceLists = new ArrayList<>(); for (ReportSourceUpdateBO sourceInsertBO : reportSourceUpdateBO) { if (ObjectUtils.isEmpty(sourceInsertBO.getId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险因素id不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getReportId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "报告id不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSource())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险源不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskCharacteristic())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险特性不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getNumber())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "数量不能为空"); } if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSourceIndex())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "排序不能为空"); } ReportExperimentRiskSource riskSource = riskSourceRepository.getRiskSourceById(sourceInsertBO.getId()); //补全数据 LocalDateTime date = LocalDateTime.now(); riskSource.setUpdateTime(date); riskSource.setUpdateByUserId(currentUserId); riskSource.setRiskSourceIndex(sourceInsertBO.getRiskSourceIndex()); riskSource.setRiskSource(sourceInsertBO.getRiskSource()); riskSource.setRiskCharacteristic(sourceInsertBO.getRiskCharacteristic()); riskSource.setNumber(sourceInsertBO.getNumber()); riskSource.setDescription(sourceInsertBO.getDesc()); riskSourceLists.add(riskSource); } List insertResult = riskSourceRepository.saveAll(riskSourceLists); if (insertResult.size() != riskSourceUpdateBO.size()){ throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险源写入失败"); } return BeanCopyUtils.copyBeanList(insertResult, ReportRiskSourceDTO.class); } /** * 风险评估报告-危险因素 - 查询by 报告id */ @Override public List getRiskSourceByReportId(Long id) { List riskSourceByReportId = riskSourceRepository.getRiskSourceByReportId(id); if (ObjectUtils.isEmpty(riskSourceByReportId)){ return null; } List reportRiskSourceDTOS = BeanCopyUtils.copyBeanList(riskSourceByReportId, ReportRiskSourceQueryRespDTO.class); return reportRiskSourceDTOS; } @Override public List insertAllReportSource(List riskSourceList) { List riskSources = riskSourceRepository.saveAll(riskSourceList); return riskSources; } }