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
package com.gkhy.labRiskManage.domain.experiment.service.impl;
 
import com.gkhy.labRiskManage.application.experiment.dto.bo.ExperimentHazardousWasteAppInsertBO;
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.ExperimentHazardousWaste;
import com.gkhy.labRiskManage.domain.experiment.enums.HazardousWasteStorageEnum;
import com.gkhy.labRiskManage.domain.experiment.enums.HazardousWasteTypeEnum;
import com.gkhy.labRiskManage.domain.experiment.repository.jpa.ExperimentHazardousWasteRepository;
import com.gkhy.labRiskManage.domain.experiment.service.ExperimentHazardousWasteService;
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;
 
 
/**
 * 实验危废物
 */
@Service
public class ExperimentHazardousWasteServiceImpl implements ExperimentHazardousWasteService {
    @Autowired
    private ExperimentHazardousWasteRepository repository;
 
 
    @Override
    public boolean saveBatch(Long currentUserId, List<ExperimentHazardousWasteAppInsertBO> hazardousWasteAppInsertBOList) {
        Boolean flag = false;
        if(!CollectionUtils.isEmpty(hazardousWasteAppInsertBOList)){
            for(ExperimentHazardousWasteAppInsertBO experimentHazardousWasteInsertBO:hazardousWasteAppInsertBOList){
                if(ObjectUtils.isEmpty(HazardousWasteTypeEnum.prase(experimentHazardousWasteInsertBO.getClassify()))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_ILLEGAL.getCode(),"危废类型校验非法!");
                }
                if(ObjectUtils.isEmpty(HazardousWasteStorageEnum.prase(experimentHazardousWasteInsertBO.getWasteStorage()))){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"危废存储方式校验非法!");
                }
                if(ObjectUtils.isEmpty(experimentHazardousWasteInsertBO.getHandAmount())){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"请填写危废存预估处理数量!");
                }
                if(ObjectUtils.isEmpty(experimentHazardousWasteInsertBO.getExperimentId())){
                    throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(),"实验主键不可为空!");
                }
            }
            List<ExperimentHazardousWaste> experimentHazardousWasteInsertList = new ArrayList<>();
            for (ExperimentHazardousWasteAppInsertBO wasteInsertBO:hazardousWasteAppInsertBOList){
                ExperimentHazardousWaste waste = new ExperimentHazardousWaste();
                BeanUtils.copyProperties(wasteInsertBO,waste);
                waste.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
                waste.setCreateByUserId(currentUserId);
                waste.setUpdateByUserId(currentUserId);
                experimentHazardousWasteInsertList.add(waste);
            }
            List<ExperimentHazardousWaste> experimentHazardousWasteList = repository.saveAll(experimentHazardousWasteInsertList);
            if(!CollectionUtils.isEmpty(experimentHazardousWasteList)){
                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);
    }
}