package com.gkhy.labRiskManage.domain.experiment.service.impl;
|
|
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.PersonQueryDTO;
|
import com.gkhy.labRiskManage.domain.basic.service.BasicExperimentPersonService;
|
import com.gkhy.labRiskManage.domain.experiment.entity.ExperimentAndPerson;
|
import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentAndPersonRepository;
|
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentAndPersonService;
|
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 ExperimentAndPersonServiceImpl implements ExperimentAndPersonService {
|
@Autowired
|
private ExperimentAndPersonRepository repository;
|
@Autowired
|
private BasicExperimentPersonService basicExperimentPersonService;
|
|
@Override
|
public boolean saveBatch(Long currentUserId, List<Long> personIds, Long experimentId) {
|
boolean flag = false;
|
if(CollectionUtils.isEmpty(personIds)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请选择试验人员!");
|
}
|
if(ObjectUtils.isEmpty(experimentId)){
|
throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验信息主键不可为空!");
|
}
|
List<PersonQueryDTO> basicExperimentPersonList = basicExperimentPersonService.getBasicExperimentPersonByIdList(personIds);
|
if(personIds.size() != basicExperimentPersonList.size()){
|
throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR_DATA_NOT_EXISIST.getCode(),"部分实验人员信息不存在!");
|
}
|
List<ExperimentAndPerson> personInsertList = new ArrayList<>();
|
for(PersonQueryDTO personQueryDTO:basicExperimentPersonList){
|
ExperimentAndPerson experimentAndPerson = new ExperimentAndPerson();
|
experimentAndPerson.setExperimentId(experimentId);
|
experimentAndPerson.setPersonId(personQueryDTO.getId());
|
experimentAndPerson.setPersonAge(personQueryDTO.getPersonAge());
|
experimentAndPerson.setPersonGender(personQueryDTO.getPersonGender());
|
experimentAndPerson.setPersonMajor(personQueryDTO.getPersonMajor());
|
experimentAndPerson.setPersonName(personQueryDTO.getPersonName());
|
experimentAndPerson.setAptitude(personQueryDTO.getAptitude());
|
experimentAndPerson.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
|
experimentAndPerson.setDepName(personQueryDTO.getDepName());
|
experimentAndPerson.setTraining(personQueryDTO.getTraining());
|
experimentAndPerson.setCreateByUserId(currentUserId);
|
experimentAndPerson.setUpdateByUserId(currentUserId);
|
personInsertList.add(experimentAndPerson);
|
}
|
List<ExperimentAndPerson> personList = repository.saveAll(personInsertList);
|
if(!CollectionUtils.isEmpty(personList)){
|
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);
|
}
|
}
|