package com.gkhy.labRiskManage.domain.experiment.service.impl; import com.gkhy.labRiskManage.application.experiment.dto.bo.ExperimentAndEmergencyAppInsertBO; 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.ExperimentAndEmergency; import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentAndEmergencyRepository; import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndEmergencyService; 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; /** * @email 1603559716@qq.com * @author: zf * @date: 2023/4/24 * @time: 13:56 */ @Service public class ExperimentAndEmergencyServiceImpl implements ExperimentAndEmergencyService { @Autowired private ExperimentAndEmergencyRepository repository; @Override public boolean saveBatch(Long currentUserId, List experimentAndEmergencyAppInsertBOList) { Boolean flag = false; if(!CollectionUtils.isEmpty(experimentAndEmergencyAppInsertBOList)){ List experimentAndEmergencyList = new ArrayList<>(); for (ExperimentAndEmergencyAppInsertBO emergencyAppInsertBO : experimentAndEmergencyAppInsertBOList){ ExperimentAndEmergency experimentAndEmergency = new ExperimentAndEmergency(); BeanUtils.copyProperties(emergencyAppInsertBO,experimentAndEmergency); experimentAndEmergency.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue()); experimentAndEmergency.setCreateByUserId(currentUserId); experimentAndEmergency.setUpdateByUserId(currentUserId); experimentAndEmergencyList.add(experimentAndEmergency); } List emergencies = repository.saveAll(experimentAndEmergencyList); if(!CollectionUtils.isEmpty(emergencies)){ flag = true; } } return flag; } @Override public void deleteByExperimentId(Long experimentId) { if(ObjectUtils.isEmpty(experimentId)){ throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!"); } repository.deleteByExperimentId(experimentId); } }