package com.gkhy.labRiskManage.domain.experiment.service.impl;
|
|
import com.gkhy.labRiskManage.application.experiment.dto.bo.ExperimentAndStuffAppInsertBO;
|
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.basic.model.dto.StuffQueryDTO;
|
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentStuffService;
|
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAndStuff;
|
import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentAndStuffRepository;
|
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndStuffService;
|
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;
|
import java.util.stream.Collectors;
|
|
|
/**
|
* 实验与耗材
|
*/
|
@Service
|
public class ExperimentAndStuffServiceImpl implements ExperimentAndStuffService {
|
@Autowired
|
private ExperimentAndStuffRepository repository;
|
@Autowired
|
private BasicExperimentStuffService basicExperimentStuffService;
|
|
@Override
|
public boolean saveBatch(Long currentUserId, List<ExperimentAndStuffAppInsertBO> stuffAppInsertBOList) {
|
Boolean flag = false;
|
if(CollectionUtils.isEmpty(stuffAppInsertBOList)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择试验实验材料!");
|
}
|
//获取材料
|
List<Long> stuffIdList = stuffAppInsertBOList.stream().map(ExperimentAndStuffAppInsertBO::getStuffId).collect(Collectors.toList());
|
List<StuffQueryDTO> basicExperimentStuffByIdList = basicExperimentStuffService.getBasicExperimentStuffByIdList(stuffIdList);
|
for(ExperimentAndStuffAppInsertBO experimentAndStuffAppInsertBO:stuffAppInsertBOList){
|
if(ObjectUtils.isEmpty(experimentAndStuffAppInsertBO.getStuffId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"材料主键不可为空!");
|
}
|
if(ObjectUtils.isEmpty(experimentAndStuffAppInsertBO.getStuffUseCount())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"材料数量不可为空!");
|
}
|
if(ObjectUtils.isEmpty(experimentAndStuffAppInsertBO.getExperimentId())){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!");
|
}
|
List<StuffQueryDTO> selectList = basicExperimentStuffByIdList.stream().filter(item -> item.getId().equals(experimentAndStuffAppInsertBO.getStuffId())).collect(Collectors.toList());
|
if(selectList.size() == 0){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(),"未查询到实验材料!");
|
}
|
}
|
List<ExperimentAndStuff> experimentAndStuffInsertList = new ArrayList<>();
|
for (ExperimentAndStuffAppInsertBO stuffInsertBO:stuffAppInsertBOList){
|
ExperimentAndStuff stuff = new ExperimentAndStuff();
|
BeanUtils.copyProperties(stuffInsertBO,stuff);
|
stuff.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
stuff.setCreateByUserId(currentUserId);
|
stuff.setUpdateByUserId(currentUserId);
|
experimentAndStuffInsertList.add(stuff);
|
}
|
List<ExperimentAndStuff> experimentAndStuffList = repository.saveAll(experimentAndStuffInsertList);
|
if(!CollectionUtils.isEmpty(experimentAndStuffList)){
|
flag = true;
|
}
|
return flag;
|
}
|
|
@Override
|
public void deleteByExperimentId(Long id, Long currentUserId) {
|
if(ObjectUtils.isEmpty(id)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!");
|
}
|
repository.deleteByExperimentId(id);
|
|
}
|
}
|