heheng
2024-11-07 37b0d2560607d1e0bfd5247a59a154704cac60f8
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
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<ExperimentAndEmergencyAppInsertBO> experimentAndEmergencyAppInsertBOList) {
        Boolean flag = false;
        if(!CollectionUtils.isEmpty(experimentAndEmergencyAppInsertBOList)){
            List<ExperimentAndEmergency> 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);
                //暂时处理20241106
                experimentAndEmergency.setId(null);
                experimentAndEmergencyList.add(experimentAndEmergency);
            }
            List<ExperimentAndEmergency> 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);
    }
 
}