heheng
2024-11-07 37b0d2560607d1e0bfd5247a59a154704cac60f8
src/main/java/com/gkhy/labRiskManage/application/experiment/service/impl/ExperimentAppServiceImpl.java
@@ -13,13 +13,12 @@
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.ExperimentAndType;
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAssessLog;
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.enums.*;
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.ExperimentAndTypeDTO;
import com.gkhy.labRiskManage.domain.experiment.model.dto.ExperimentInfoDTO;
import com.gkhy.labRiskManage.domain.experiment.service.*;
import com.gkhy.labRiskManage.domain.riskReport.entity.ReportRiskAssessInfo;
@@ -57,6 +56,8 @@
    private ExperimentAppConverter experimentAppConverter;
    @Autowired
    private ExperimentAssessLogService experimentAssessLogService;
    @Autowired
    private ExperimentAndTypeService experimentAndTypeService;
    @Transactional
    @Override
    public int save(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) {
@@ -80,9 +81,14 @@
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getSiteList())){
            siteIds = experimentInsertReqBO.getSiteList().stream().map(ExperimentAndSiteInsertReqBO::getSiteId).collect(Collectors.toList());
        }
        //实验类型中间表
        List<Long> typeIds = new ArrayList<>();
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getTypeList())){
            typeIds = experimentInsertReqBO.getTypeList().stream().map(ExperimentAndTypeInsertReqBO::getTypeId).collect(Collectors.toList());
        }
        //危废中间表
        List<ExperimentHazardousWasteAppInsertBO> hazardousWasteInsertBOList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(experimentAppInsertBO.getHazardousWasteList())){
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getHazardousWasteList())){
            hazardousWasteInsertBOList = experimentAppConverter.getHazardousWasteInsertBOList(experimentInsertReqBO.getHazardousWasteList(),experimentInfoDTO.getId());
        }
        //应急演练
@@ -90,10 +96,14 @@
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getEmergencyList())){
            experimentAndEmergencyAppInsertBOList = experimentAppConverter.getExperimentAndEmergencyAppInsertBOList(experimentInsertReqBO.getEmergencyList(), experimentInfoDTO.getId());
        }
        // 暂存清空了之前绑定数据
        dealDelete(experimentInfoDTO.getId(),currentUserId);
        experimentAndDeviceService.saveBatch(currentUserId,deviceAppInsertBOList);
        experimentAndStuffService.saveBatch(currentUserId,stuffInsertBOList);
        experimentAndPersonService.saveBatch(currentUserId,personIds,experimentInfoDTO.getId());
        experimentAndSiteService.saveBatch(currentUserId, siteIds, experimentInfoDTO.getId());
        experimentAndTypeService.saveBatch(currentUserId, typeIds, experimentInfoDTO.getId());
        experimentHazardousWasteService.saveBatch(currentUserId,hazardousWasteInsertBOList);
        experimentAndEmergencyService.saveBatch(currentUserId,experimentAndEmergencyAppInsertBOList);
        Integer code = StatusEnum.SUCCESS.getCode();
@@ -102,6 +112,31 @@
        }
        return code;
    }
    @Override
    @Transactional
    public int temporary(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) {
//        if(ExperimentStagingEnum.SAVE.getValue().equals(experimentInsertReqBO.getStagingTag())){
//            throw new BusinessException(this.getClass(),ResultCode.PARAM_ERROR_NULL.getCode(),"已保存数据不可操作暂存!");
//        }
        //实验基础信息
        ExperimentAppInsertBO experimentAppInsertBO = new ExperimentAppInsertBO();
        BeanUtils.copyProperties(experimentInsertReqBO,experimentAppInsertBO);
        ExperimentInfoDTO experimentInfoDTO = experimentInfoService.temporary(currentUserId,experimentAppInsertBO);
        //删除业务数据
        dealDelete(experimentInfoDTO.getId(),currentUserId);
        temporary(currentUserId,experimentInsertReqBO,experimentInfoDTO.getId(),experimentAppInsertBO);
        Integer code = StatusEnum.SUCCESS.getCode();
        if(ObjectUtils.isEmpty(experimentInfoDTO)){
            code = StatusEnum.FAIL.getCode();
        }
        return code;
    }
    @Transactional
    @Override
    public int developSave(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) {
@@ -126,7 +161,7 @@
        }
        //危废中间表
        List<ExperimentHazardousWasteAppInsertBO> hazardousWasteInsertBOList = new ArrayList<>();
        if(!CollectionUtils.isEmpty(experimentAppInsertBO.getHazardousWasteList())){
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getHazardousWasteList())){
            hazardousWasteInsertBOList = experimentAppConverter.getHazardousWasteInsertBOList(experimentInsertReqBO.getHazardousWasteList(),experimentInfoDTO.getId());
        }
        //应急演练
@@ -134,11 +169,20 @@
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getEmergencyList())){
            experimentAndEmergencyAppInsertBOList = experimentAppConverter.getExperimentAndEmergencyAppInsertBOList(experimentInsertReqBO.getEmergencyList(), experimentInfoDTO.getId());
        }
        //实验类型中间表
        List<Long> typeIds = new ArrayList<>();
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getTypeList())){
            typeIds = experimentInsertReqBO.getTypeList().stream().map(ExperimentAndTypeInsertReqBO::getTypeId).collect(Collectors.toList());
        }
        // 暂存清空了之前绑定数据
        dealDelete(experimentInfoDTO.getId(),currentUserId);
        experimentAndDeviceService.saveBatch(currentUserId,deviceAppInsertBOList);
        experimentAndStuffService.saveBatch(currentUserId,stuffInsertBOList);
        experimentAndPersonService.saveBatch(currentUserId,personIds,experimentInfoDTO.getId());
        experimentAndSiteService.saveBatch(currentUserId, siteIds, experimentInfoDTO.getId());
        experimentAndTypeService.saveBatch(currentUserId, typeIds, experimentInfoDTO.getId());
        experimentHazardousWasteService.saveBatch(currentUserId,hazardousWasteInsertBOList);
        experimentAndEmergencyService.saveBatch(currentUserId,experimentAndEmergencyAppInsertBOList);
        Integer code = StatusEnum.SUCCESS.getCode();
@@ -146,6 +190,88 @@
            code = StatusEnum.FAIL.getCode();
        }
        return code;
    }
    @Override
    @Transactional
    public int developTemporary(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO) {
        //实验基础信息
        ExperimentAppInsertBO experimentAppInsertBO = new ExperimentAppInsertBO();
        BeanUtils.copyProperties(experimentInsertReqBO,experimentAppInsertBO);
        ExperimentInfoDTO experimentInfoDTO = experimentInfoService.developTemporary(currentUserId,experimentAppInsertBO);
        //处理中间表数据
        dealDelete(experimentInfoDTO.getId(),currentUserId);
        temporary(currentUserId,experimentInsertReqBO,experimentInfoDTO.getId(),experimentAppInsertBO);
        Integer code = StatusEnum.SUCCESS.getCode();
        if(ObjectUtils.isEmpty(experimentInfoDTO)){
            code = StatusEnum.FAIL.getCode();
        }
        return code;
    }
    /**
     * 处理删除
     * @param id
     * @param currentUserId
     */
    private void dealDelete(Long id ,Long currentUserId){
        experimentAndTypeService.deleteByExperimentId(id);
        experimentAndDeviceService.deleteByExperimentId(id,currentUserId);
        experimentHazardousWasteService.deleteByExperimentId(id,currentUserId);
        experimentAndPersonService.deleteByExperimentId(id,currentUserId);
        experimentAndStuffService.deleteByExperimentId(id,currentUserId);
        experimentAndSiteService.deleteByExperimentId(id);
        experimentAndEmergencyService.deleteByExperimentId(id);
    }
    /**
     * 处理中间表数据
     * @param currentUserId
     * @param experimentInsertReqBO
     * @param experimentAppInsertBO
     */
    private void temporary(Long currentUserId, ExperimentInsertReqBO experimentInsertReqBO,Long id ,ExperimentAppInsertBO experimentAppInsertBO) {
        if (!CollectionUtils.isEmpty(experimentInsertReqBO.getDeviceList())){
            //设备中间表
            List<ExperimentAndDeviceAppInsertBO> deviceAppInsertBOList = experimentAppConverter.getDeviceInsertBOList(experimentInsertReqBO.getDeviceList(),id);
            experimentAndDeviceService.saveBatch(currentUserId,deviceAppInsertBOList);
        }
        if (!CollectionUtils.isEmpty(experimentInsertReqBO.getStuffList())) {
            //材料中间表
            List<ExperimentAndStuffAppInsertBO> stuffInsertBOList = experimentAppConverter.getStuffInsertBOList(experimentInsertReqBO.getStuffList(), id);
            experimentAndStuffService.saveBatch(currentUserId,stuffInsertBOList);
        }
        //实验人员
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getPersons())){
            List<Long> personIds =  experimentInsertReqBO.getPersons().stream().map(ExperimentAndPersonInsertReqBO::getPersonId).collect(Collectors.toList());
            experimentAndPersonService.saveBatch(currentUserId,personIds,id);
        }
        //实验地点中间表
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getSiteList())){
            List<Long> siteIds = experimentInsertReqBO.getSiteList().stream().map(ExperimentAndSiteInsertReqBO::getSiteId).collect(Collectors.toList());
            experimentAndSiteService.saveBatch(currentUserId, siteIds, id);
        }
        //实验类型中间表
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getTypeList())){
            List<Long> typeIds = experimentInsertReqBO.getTypeList().stream().map(ExperimentAndTypeInsertReqBO::getTypeId).collect(Collectors.toList());
            experimentAndTypeService.saveBatch(currentUserId, typeIds, id);
        }
        //危废中间表
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getHazardousWasteList())){
            List<ExperimentHazardousWasteAppInsertBO> hazardousWasteInsertBOList = experimentAppConverter.getHazardousWasteInsertBOList(experimentInsertReqBO.getHazardousWasteList(),id);
            experimentHazardousWasteService.saveBatch(currentUserId,hazardousWasteInsertBOList);
        }
        //应急演练
        if(!CollectionUtils.isEmpty(experimentInsertReqBO.getEmergencyList())){
            List<ExperimentAndEmergencyAppInsertBO> experimentAndEmergencyAppInsertBOList = experimentAppConverter.getExperimentAndEmergencyAppInsertBOList(experimentInsertReqBO.getEmergencyList(), id);
            experimentAndEmergencyService.saveBatch(currentUserId,experimentAndEmergencyAppInsertBOList);
        }
    }
    @Transactional
    @Override
@@ -189,6 +315,11 @@
                experimentInfo.setAssessLevel(byExperimentId.getAssessLevel());
                experimentInfo.setAssessTime(byExperimentId.getAssessTime());
            }
            List<ExperimentAndTypeDTO> types = experimentInfo.getTypes();
            if (!CollectionUtils.isEmpty(types)){
                String collect = types.stream().map(type -> type.getTypeName()).collect(Collectors.joining(","));
                experimentInfo.setExperimentTypeName(collect);
            }
        }
        result.setData(experimentInfoAppQueryDTOS);
@@ -206,6 +337,7 @@
    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteById(Long id, Long currentUserId) {
        experimentInfoService.deleteById(id,currentUserId);
        experimentAndDeviceService.deleteByExperimentId(id,currentUserId);
        experimentHazardousWasteService.deleteByExperimentId(id,currentUserId);
@@ -213,6 +345,7 @@
        experimentAndStuffService.deleteByExperimentId(id,currentUserId);
        experimentAndSiteService.deleteByExperimentId(id);
        experimentAndEmergencyService.deleteByExperimentId(id);
        experimentAndTypeService.deleteByExperimentId(id);
        return StatusEnum.SUCCESS.getCode();
    }
@@ -275,7 +408,8 @@
            BeanUtils.copyProperties(searchResult,result);
        }
        List<ExperimentInfoDTO> experimentInfoDTOS = (List<ExperimentInfoDTO>)searchResult.getData();
        List<ExperimentInfoAppQueryDTO> experimentInfoAppQueryDTOS = BeanCopyUtils.copyBeanList(experimentInfoDTOS, ExperimentInfoAppQueryDTO.class);
        List<ExperimentInfoAppQueryDTO> experimentInfoAppQueryDTOS = BeanCopyUtils.list2OtherList(experimentInfoDTOS, ExperimentInfoAppQueryDTO.class);
        for (ExperimentInfoAppQueryDTO experimentInfo : experimentInfoAppQueryDTOS) {
            List<ExperimentAssessLog> assessLogs = experimentAssessLogService.getAssessLogs(experimentInfo.getExperimentCode());
@@ -287,6 +421,12 @@
                experimentInfo.setAssessLevel(byExperimentId.getAssessLevel());
                experimentInfo.setAssessTime(byExperimentId.getAssessTime());
            }
            List<ExperimentAndTypeDTO> types = experimentInfo.getTypes();
            if (!CollectionUtils.isEmpty(types)){
                String collect = types.stream().map(type -> type.getTypeName()).collect(Collectors.joining(","));
                experimentInfo.setExperimentTypeName(collect);
            }
        }
        result.setData(experimentInfoAppQueryDTOS);
@@ -311,7 +451,7 @@
            BeanUtils.copyProperties(searchResult,result);
        }
        List<ExperimentInfoDTO> experimentInfoDTOS = (List<ExperimentInfoDTO>)searchResult.getData();
        List<ExperimentInfoAppQueryDTO> experimentInfoAppQueryDTOS = BeanCopyUtils.copyBeanList(experimentInfoDTOS, ExperimentInfoAppQueryDTO.class);
        List<ExperimentInfoAppQueryDTO> experimentInfoAppQueryDTOS = BeanCopyUtils.list2OtherList(experimentInfoDTOS, ExperimentInfoAppQueryDTO.class);
        for (ExperimentInfoAppQueryDTO experimentInfo : experimentInfoAppQueryDTOS) {
            List<ExperimentAssessLog> assessLogs = experimentAssessLogService.getAssessLogs(experimentInfo.getExperimentCode());
@@ -323,6 +463,11 @@
                experimentInfo.setAssessLevel(byExperimentId.getAssessLevel());
                experimentInfo.setAssessTime(byExperimentId.getAssessTime());
            }
            List<ExperimentAndTypeDTO> types = experimentInfo.getTypes();
            if (!CollectionUtils.isEmpty(types)){
                String collect = types.stream().map(type -> type.getTypeName()).collect(Collectors.joining(","));
                experimentInfo.setExperimentTypeName(collect);
            }
        }
        result.setData(experimentInfoAppQueryDTOS);