package com.gkhy.labRiskManage.application.experiment.service.impl; import com.gkhy.labRiskManage.api.controller.experiment.dto.req.*; import com.gkhy.labRiskManage.api.controller.experiment.dto.resp.ExperimentAndEmergencyRespDTO; import com.gkhy.labRiskManage.application.experiment.converter.ExperimentAppConverter; import com.gkhy.labRiskManage.application.experiment.dto.bo.*; import com.gkhy.labRiskManage.application.experiment.dto.dto.*; import com.gkhy.labRiskManage.application.experiment.service.ExperimentAppService; import com.gkhy.labRiskManage.application.riskReport.dto.dto.ReportAppQueryDTO; import com.gkhy.labRiskManage.commons.domain.SearchResult; 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.model.PageQuery; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentInfo; import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentStatusEnum; import com.gkhy.labRiskManage.domain.experiment.enums.ExperimentTagEnum; import com.gkhy.labRiskManage.domain.experiment.model.bo.*; import com.gkhy.labRiskManage.domain.experiment.enums.HazardousWasteEnum; import com.gkhy.labRiskManage.domain.experiment.enums.TimeoutEnum; import com.gkhy.labRiskManage.domain.experiment.model.dto.ExperimentInfoDTO; import com.gkhy.labRiskManage.domain.experiment.service.*; import com.gkhy.labRiskManage.domain.riskReport.service.ReportRiskAssessInfoService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @Service public class ExperimentAppServiceImpl implements ExperimentAppService { @Autowired private ExperimentInfoService experimentInfoService; @Autowired private ExperimentHazardousWasteService experimentHazardousWasteService; @Autowired private ExperimentAndStuffService experimentAndStuffService; @Autowired private ExperimentAndDeviceService experimentAndDeviceService; @Autowired private ExperimentAndPersonService experimentAndPersonService; @Autowired private ReportRiskAssessInfoService reportRiskAssessInfoService; @Autowired private ExperimentAndSiteService experimentAndSiteService; @Autowired private ExperimentAndEmergencyService experimentAndEmergencyService; @Autowired private ExperimentAppConverter experimentAppConverter; @Transactional @Override public int save(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) { //实验基础信息 ExperimentAppInsertBO experimentAppInsertBO = new ExperimentAppInsertBO(); BeanUtils.copyProperties(experimentInsertReqBO,experimentAppInsertBO); ExperimentInfoDTO experimentInfoDTO = experimentInfoService.save(currentUserId,experimentAppInsertBO); //设备中间表 List deviceAppInsertBOList = experimentAppConverter.getDeviceInsertBOList(experimentInsertReqBO.getDeviceList(),experimentInfoDTO.getId()); //材料中间表 List stuffInsertBOList = experimentAppConverter.getStuffInsertBOList(experimentInsertReqBO.getStuffList(),experimentInfoDTO.getId()); //实验人员 List personIds = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getPersons())){ personIds = experimentInsertReqBO.getPersons().stream().map(ExperimentAndPersonInsertReqBO::getPersonId).collect(Collectors.toList()); } //实验地点中间表 List siteIds = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getSiteList())){ siteIds = experimentInsertReqBO.getSiteList().stream().map(ExperimentAndSiteInsertReqBO::getSiteId).collect(Collectors.toList()); } //危废中间表 List hazardousWasteInsertBOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentAppInsertBO.getHazardousWasteList())){ hazardousWasteInsertBOList = experimentAppConverter.getHazardousWasteInsertBOList(experimentInsertReqBO.getHazardousWasteList(),experimentInfoDTO.getId()); } //应急演练 List experimentAndEmergencyAppInsertBOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getEmergencyList())){ experimentAndEmergencyAppInsertBOList = experimentAppConverter.getExperimentAndEmergencyAppInsertBOList(experimentInsertReqBO.getEmergencyList(), experimentInfoDTO.getId()); } experimentAndDeviceService.saveBatch(currentUserId,deviceAppInsertBOList); experimentAndStuffService.saveBatch(currentUserId,stuffInsertBOList); experimentAndPersonService.saveBatch(currentUserId,personIds,experimentInfoDTO.getId()); experimentAndSiteService.saveBatch(currentUserId, siteIds, experimentInfoDTO.getId()); experimentHazardousWasteService.saveBatch(currentUserId,hazardousWasteInsertBOList); experimentAndEmergencyService.saveBatch(currentUserId,experimentAndEmergencyAppInsertBOList); Integer code = StatusEnum.SUCCESS.getCode(); if(ObjectUtils.isEmpty(experimentInfoDTO)){ code = StatusEnum.FAIL.getCode(); } return code; } @Transactional @Override public int developSave(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) { //实验基础信息 ExperimentAppInsertBO experimentAppInsertBO = new ExperimentAppInsertBO(); BeanUtils.copyProperties(experimentInsertReqBO,experimentAppInsertBO); ExperimentInfoDTO experimentInfoDTO = experimentInfoService.developSave(currentUserId,experimentAppInsertBO); //设备中间表 List deviceAppInsertBOList = experimentAppConverter.getDeviceInsertBOList(experimentInsertReqBO.getDeviceList(),experimentInfoDTO.getId()); //材料中间表 List stuffInsertBOList = experimentAppConverter.getStuffInsertBOList(experimentInsertReqBO.getStuffList(),experimentInfoDTO.getId()); //实验人员 List personIds = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getPersons())){ personIds = experimentInsertReqBO.getPersons().stream().map(ExperimentAndPersonInsertReqBO::getPersonId).collect(Collectors.toList()); } //实验地点中间表 List siteIds = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getSiteList())){ siteIds = experimentInsertReqBO.getSiteList().stream().map(ExperimentAndSiteInsertReqBO::getSiteId).collect(Collectors.toList()); } //危废中间表 List hazardousWasteInsertBOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentAppInsertBO.getHazardousWasteList())){ hazardousWasteInsertBOList = experimentAppConverter.getHazardousWasteInsertBOList(experimentInsertReqBO.getHazardousWasteList(),experimentInfoDTO.getId()); } //应急演练 List experimentAndEmergencyAppInsertBOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInsertReqBO.getEmergencyList())){ experimentAndEmergencyAppInsertBOList = experimentAppConverter.getExperimentAndEmergencyAppInsertBOList(experimentInsertReqBO.getEmergencyList(), experimentInfoDTO.getId()); } experimentAndDeviceService.saveBatch(currentUserId,deviceAppInsertBOList); experimentAndStuffService.saveBatch(currentUserId,stuffInsertBOList); experimentAndPersonService.saveBatch(currentUserId,personIds,experimentInfoDTO.getId()); experimentAndSiteService.saveBatch(currentUserId, siteIds, experimentInfoDTO.getId()); experimentHazardousWasteService.saveBatch(currentUserId,hazardousWasteInsertBOList); experimentAndEmergencyService.saveBatch(currentUserId,experimentAndEmergencyAppInsertBOList); Integer code = StatusEnum.SUCCESS.getCode(); if(ObjectUtils.isEmpty(experimentInfoDTO)){ code = StatusEnum.FAIL.getCode(); } return code; } @Transactional @Override public int rectifySave(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) { //修该原有实验已整改 boolean flag = experimentInfoService.updateRectify(experimentInsertReqBO.getId()); //新建 int save = this.save(currentUserId, experimentInsertReqBO); if(flag && save == StatusEnum.SUCCESS.getCode()){ return StatusEnum.SUCCESS.getCode(); } return StatusEnum.FAIL.getCode(); } @Override public SearchResult> applyEvaluationListByPage(PageQuery appPageQuery,Long currentUserId) { PageQuery pageQuery = new PageQuery<>(); pageQuery.setPageSize(appPageQuery.getPageSize()); pageQuery.setPageIndex(appPageQuery.getPageIndex()); ExperimentInfoQueryBO queryBO = new ExperimentInfoQueryBO(); if(!ObjectUtils.isEmpty(appPageQuery.getSearchParams())){ BeanUtils.copyProperties(appPageQuery.getSearchParams(),queryBO); } queryBO.setStatus(ExperimentStatusEnum.YES_APPLY.getValue()); pageQuery.setSearchParams(queryBO); SearchResult> searchResult = experimentInfoService.listByPage(pageQuery,currentUserId); SearchResult> result = new SearchResult<>(); if(!ObjectUtils.isEmpty(searchResult)){ BeanUtils.copyProperties(searchResult,result); } List experimentInfoDTOS = (List)searchResult.getData(); result.setData(getExperimentInfoAppQueryDTO(experimentInfoDTOS)); //获取分页数据 return result; } /** * 删除 * * @param id * @param currentUserId * @return */ @Transactional(rollbackFor = Exception.class) @Override public int deleteById(Long id, Long currentUserId) { experimentInfoService.deleteById(id,currentUserId); experimentAndDeviceService.deleteByExperimentId(id,currentUserId); experimentHazardousWasteService.deleteByExperimentId(id,currentUserId); experimentAndPersonService.deleteByExperimentId(id,currentUserId); experimentAndStuffService.deleteByExperimentId(id,currentUserId); experimentAndSiteService.deleteByExperimentId(id); experimentAndEmergencyService.deleteByExperimentId(id); return StatusEnum.SUCCESS.getCode(); } @Override public int updateDevelop(Long currentUserId, List appDevelopUpdateBOList) { int code = StatusEnum.SUCCESS.getCode(); List developUpdateBOList = new ArrayList<>(); if(!CollectionUtils.isEmpty(appDevelopUpdateBOList)){ developUpdateBOList = BeanCopyUtils.copyBeanList(appDevelopUpdateBOList,ExperimentDevelopUpdateBO.class); } boolean flag = experimentInfoService.updateDevelop(currentUserId,developUpdateBOList); if(!flag){ code = StatusEnum.FAIL.getCode(); } return code; } @Override public int applyEvaluation(Long currentUserId, List ids) { int code = StatusEnum.SUCCESS.getCode(); boolean flag = experimentInfoService.applyEvaluation(currentUserId,ids); if(!flag){ code = StatusEnum.FAIL.getCode(); } return code; } @Override public int revokeApplyEvaluation(Long currentUserId, List ids) { int code = StatusEnum.SUCCESS.getCode(); boolean flag = experimentInfoService.revokeApplyEvaluation(currentUserId,ids); if(!flag){ code = StatusEnum.FAIL.getCode(); } return code; } @Override public List getExperimentInfoList(Long currentUserId) { List experimentInfoList = experimentInfoService.getExperimentInfoList(currentUserId); return experimentAppConverter.getExperimentInfoAppVoList(experimentInfoList); } @Override public SearchResult> projectListByPage(PageQuery appPageQuery,Long currentUserId) { PageQuery pageQuery = new PageQuery<>(); pageQuery.setPageSize(appPageQuery.getPageSize()); pageQuery.setPageIndex(appPageQuery.getPageIndex()); ExperimentInfoQueryBO queryBO = new ExperimentInfoQueryBO(); if(!ObjectUtils.isEmpty(appPageQuery.getSearchParams())){ BeanUtils.copyProperties(appPageQuery.getSearchParams(),queryBO); } queryBO.setExperimentTag(ExperimentTagEnum.NEW_CREATE.getValue()); pageQuery.setSearchParams(queryBO); SearchResult> searchResult = experimentInfoService.listByPage(pageQuery,currentUserId); SearchResult> result = new SearchResult<>(); if(!ObjectUtils.isEmpty(searchResult)){ BeanUtils.copyProperties(searchResult,result); } List experimentInfoDTOS = (List)searchResult.getData(); result.setData(getExperimentInfoAppQueryDTO(experimentInfoDTOS)); //获取分页数据 return result; } @Override public SearchResult> developListByPage(PageQuery appPageQuery,Long currentUserId) { PageQuery pageQuery = new PageQuery<>(); pageQuery.setPageSize(appPageQuery.getPageSize()); pageQuery.setPageIndex(appPageQuery.getPageIndex()); ExperimentInfoQueryBO queryBO = new ExperimentInfoQueryBO(); if(!ObjectUtils.isEmpty(appPageQuery.getSearchParams())){ BeanUtils.copyProperties(appPageQuery.getSearchParams(),queryBO); } queryBO.setExperimentTag(ExperimentTagEnum.AREADLY_DEVELOP.getValue()); pageQuery.setSearchParams(queryBO); SearchResult> searchResult = experimentInfoService.listByPage(pageQuery,currentUserId); SearchResult> result = new SearchResult<>(); if(!ObjectUtils.isEmpty(searchResult)){ BeanUtils.copyProperties(searchResult,result); } List experimentInfoDTOS = (List)searchResult.getData(); result.setData(getExperimentInfoAppQueryDTO(experimentInfoDTOS)); //获取分页数据 return result; } private List getExperimentInfoAppQueryDTO(List experimentInfoDTOS){ List experimentInfoAppQueryDTOS = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTOS)){ List expermentIds = experimentInfoDTOS.stream().map(ExperimentInfoDTO::getId).collect(Collectors.toList()); //获取关联的评估数据 List reportAppQueryDTOS = reportRiskAssessInfoService.listRiskReport(expermentIds); //遍历实验 for (ExperimentInfoDTO experimentInfoDTO:experimentInfoDTOS){ ExperimentInfoAppQueryDTO experimentInfoAppQueryDTO = new ExperimentInfoAppQueryDTO(); BeanUtils.copyProperties(experimentInfoDTO,experimentInfoAppQueryDTO); //实验场所 List siteAppQueryDTOs = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getSites())){ siteAppQueryDTOs = BeanCopyUtils.copyBeanList(experimentInfoDTO.getSites(),ExperimentAndSiteAppQueryDTO.class); } experimentInfoAppQueryDTO.setSites(siteAppQueryDTOs); //人员 List personAppQueryDTOList = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getPersons())){ personAppQueryDTOList = BeanCopyUtils.copyBeanList(experimentInfoDTO.getPersons(),ExperimentAndPersonAppQueryDTO.class); } experimentInfoAppQueryDTO.setPersons(personAppQueryDTOList); //设备 List deviceAppQueryDTOList = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getDevices())){ deviceAppQueryDTOList = BeanCopyUtils.copyBeanList(experimentInfoDTO.getDevices(),ExperimentAndDeviceAppQueryDTO.class); } experimentInfoAppQueryDTO.setDevices(deviceAppQueryDTOList); //材料 List stuffAppQueryDTOList = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getStuffs())){ stuffAppQueryDTOList = BeanCopyUtils.copyBeanList(experimentInfoDTO.getStuffs(),ExperimentAndStuffAppQueryDTO.class); } experimentInfoAppQueryDTO.setStuffs(stuffAppQueryDTOList); //危废 List wasteAppQueryDTOList = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getWastes())){ wasteAppQueryDTOList = BeanCopyUtils.copyBeanList(experimentInfoDTO.getWastes(),ExperimentHazardousWasteAppQueryDTO.class); } experimentInfoAppQueryDTO.setWastes(wasteAppQueryDTOList); //应急演练 List emergencies = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfoDTO.getEmergencies())){ emergencies = BeanCopyUtils.copyBeanList(experimentInfoDTO.getEmergencies(),ExperimentAndEmergencyRespDTO.class); } experimentInfoAppQueryDTO.setEmergencies(emergencies); //风险评估 if(!ObjectUtils.isEmpty(reportAppQueryDTOS)){ List selectList = reportAppQueryDTOS.stream().filter(item -> item.getExperimentId().equals(experimentInfoDTO.getId())).collect(Collectors.toList()); if(selectList.size()>0){ experimentInfoAppQueryDTO.setAssessLevel(selectList.get(0).getAssessLevel()); experimentInfoAppQueryDTO.setAssessTime(selectList.get(0).getAssessTime()); } }else { experimentInfoAppQueryDTO.setAssessLevel((byte)0); } experimentInfoAppQueryDTOS.add(experimentInfoAppQueryDTO); } } return experimentInfoAppQueryDTOS; } }