package com.gkhy.labRiskManage.domain.experiment.converter; import com.gkhy.labRiskManage.commons.utils.BeanCopyUtils; import com.gkhy.labRiskManage.domain.experiment.entity.*; import com.gkhy.labRiskManage.domain.experiment.model.dto.*; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.List; /** * @email 1603559716@qq.com * @author: zf * @date: 2023/3/21 * @time: 17:05 */ @Service public class ExperimentInfoDomainConverter { public ExperimentInfoDTO getExperimentInfoDTO(ExperimentInfo experimentInfo) { if(experimentInfo == null){ return null; } ExperimentInfoDTO experimentInfoDTO = new ExperimentInfoDTO(); BeanUtils.copyProperties(experimentInfo,experimentInfoDTO); return experimentInfoDTO; } public List getExperimentInfoDTOSimpleList(List experimentInfoByIdList) { List list = new ArrayList<>(); if(!CollectionUtils.isEmpty(experimentInfoByIdList)){ list = BeanCopyUtils.copyBeanList(experimentInfoByIdList,ExperimentInfoDTO.class); } return list; } //返回上一层转换 public List getExperimentInfoDTODetailList(List experimentInfoList){ List list = new ArrayList<>(); if (!CollectionUtils.isEmpty(experimentInfoList)) { for (ExperimentInfo experimentInfo:experimentInfoList){ //实验基础信息 ExperimentInfoDTO experimentInfoDTO = new ExperimentInfoDTO(); BeanUtils.copyProperties(experimentInfo,experimentInfoDTO); //实验场所数据 List sites = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getSites())){ for (ExperimentAndSite experimentAndSite : experimentInfo.getSites()){ ExperimentAndSiteDTO experimentAndSiteDTO = new ExperimentAndSiteDTO(); experimentAndSiteDTO.setSiteId(experimentAndSite.getSiteId()); if(null != experimentAndSite.getSite()){ experimentAndSiteDTO.setSiteName(experimentAndSite.getSite().getSiteName()); experimentAndSiteDTO.setFireFacilities(experimentAndSite.getSite().getFireFacilities()); experimentAndSiteDTO.setPartitionStatus(experimentAndSite.getSite().getPartitionStatus()); experimentAndSiteDTO.setSiteType(experimentAndSite.getSite().getSiteType()); } experimentAndSiteDTO.setRoom(experimentAndSite.getSite().getRoom()); experimentAndSiteDTO.setFloor(experimentAndSite.getSite().getFloor()); sites.add(experimentAndSiteDTO); } } experimentInfoDTO.setSites(sites); //人员信息 List persons = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getPersons())){ for (ExperimentAndPerson person:experimentInfo.getPersons()) { ExperimentAndPersonDTO personDTO = new ExperimentAndPersonDTO(); BeanUtils.copyProperties(person,personDTO); persons.add(personDTO); } } experimentInfoDTO.setPersons(persons); //材料信息 List stuffs = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getStuffs())){ for (ExperimentAndStuff experimentAndStuff:experimentInfo.getStuffs()) { ExperimentAndStuffDTO stuffDTO = new ExperimentAndStuffDTO(); stuffDTO.setStuffCode(experimentAndStuff.getStuff().getStuffCode()); stuffDTO.setStuffName(experimentAndStuff.getStuff().getStuffName()); stuffDTO.setStuffType(experimentAndStuff.getStuff().getStuffType()); stuffDTO.setStuffStorage(experimentAndStuff.getStuff().getStuffStorage()); stuffDTO.setStuffUnit(experimentAndStuff.getStuff().getStuffUnit()); stuffDTO.setStuffUseCount(experimentAndStuff.getStuffUseCount()); stuffDTO.setStuffId(experimentAndStuff.getStuffId()); stuffs.add(stuffDTO); } } experimentInfoDTO.setStuffs(stuffs); //设备信息 List devices = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getDevices())){ for (ExperimentAndDevice experimentAndDevice:experimentInfo.getDevices()) { ExperimentAndDeviceDTO deviceDTO = new ExperimentAndDeviceDTO(); //deviceDTO.setId(experimentAndDevice.getDeviceId()); deviceDTO.setDeviceId(experimentAndDevice.getDeviceId()); deviceDTO.setDeviceCode(experimentAndDevice.getDevice().getDeviceCode()); deviceDTO.setDeviceName(experimentAndDevice.getDevice().getDeviceName()); deviceDTO.setDevicePower(experimentAndDevice.getDevice().getDevicePower()); deviceDTO.setDeviceUnit(experimentAndDevice.getDevice().getDeviceUnit()); deviceDTO.setSpecialDevice(experimentAndDevice.getDevice().getSpecialDevice()); deviceDTO.setDeviceUseCount(experimentAndDevice.getDeviceUseCount()); devices.add(deviceDTO); } } experimentInfoDTO.setDevices(devices); //危废信息 List wastes = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getWastes())){ for (ExperimentHazardousWaste experimentHazardousWaste:experimentInfo.getWastes()) { ExperimentHazardousWasteDTO wasteDTO = new ExperimentHazardousWasteDTO(); BeanUtils.copyProperties(experimentHazardousWaste,wasteDTO); wastes.add(wasteDTO); } } experimentInfoDTO.setWastes(wastes); //应急演练 List emergencies = new ArrayList<>(); if(!ObjectUtils.isEmpty(experimentInfo.getEmergencies())){ for (ExperimentAndEmergency experimentAndEmergency : experimentInfo.getEmergencies()) { ExperimentAndEmergencyDTO emergencyDTO = new ExperimentAndEmergencyDTO(); BeanUtils.copyProperties(experimentAndEmergency,emergencyDTO); emergencies.add(emergencyDTO); } } experimentInfoDTO.setEmergencies(emergencies); list.add(experimentInfoDTO); } } return list; } }