heheng
2025-01-13 a27162cb82ef0cabf9b43cbfd1f3eb8c177d1e14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
    }
}