package com.gkhy.labRiskManage.domain.experiment.service.impl; import com.gkhy.labRiskManage.application.experiment.dto.bo.ExperimentHazardousWasteAppInsertBO; 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.domain.experiment.entity.ExperimentHazardousWaste; import com.gkhy.labRiskManage.domain.experiment.enums.HazardousWasteStorageEnum; import com.gkhy.labRiskManage.domain.experiment.enums.HazardousWasteTypeEnum; import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentHazardousWasteRepository; import com.gkhy.labRiskManage.domain.experiment.service.ExperimentHazardousWasteService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import java.util.ArrayList; import java.util.List; /** * 实验危废物 */ @Service public class ExperimentHazardousWasteServiceImpl implements ExperimentHazardousWasteService { @Autowired private ExperimentHazardousWasteRepository repository; @Override public boolean saveBatch(Long currentUserId, List hazardousWasteAppInsertBOList) { Boolean flag = false; if(!CollectionUtils.isEmpty(hazardousWasteAppInsertBOList)){ for(ExperimentHazardousWasteAppInsertBO experimentHazardousWasteInsertBO:hazardousWasteAppInsertBOList){ if(ObjectUtils.isEmpty(HazardousWasteTypeEnum.prase(experimentHazardousWasteInsertBO.getClassify()))){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"危废类型校验非法!"); } if(ObjectUtils.isEmpty(HazardousWasteStorageEnum.prase(experimentHazardousWasteInsertBO.getWasteStorage()))){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"危废存储方式校验非法!"); } if(ObjectUtils.isEmpty(experimentHazardousWasteInsertBO.getHandAmount())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写危废存预估处理数量!"); } if(ObjectUtils.isEmpty(experimentHazardousWasteInsertBO.getExperimentId())){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!"); } } List experimentHazardousWasteInsertList = new ArrayList<>(); for (ExperimentHazardousWasteAppInsertBO wasteInsertBO:hazardousWasteAppInsertBOList){ ExperimentHazardousWaste waste = new ExperimentHazardousWaste(); BeanUtils.copyProperties(wasteInsertBO,waste); waste.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); waste.setCreateByUserId(currentUserId); waste.setUpdateByUserId(currentUserId); experimentHazardousWasteInsertList.add(waste); } List experimentHazardousWasteList = repository.saveAll(experimentHazardousWasteInsertList); if(!CollectionUtils.isEmpty(experimentHazardousWasteList)){ flag = true; } } return flag; } @Override public void deleteByExperimentId(Long experimentId, Long currentUserId) { if(ObjectUtils.isEmpty(experimentId)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!"); } repository.deleteByExperimentId(experimentId); } }