16639036659
2023-08-28 8f76ba99a6d20fb5ca45b6029a47d59cb8efe7bb
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package com.gkhy.labRiskManage.domain.riskReport.service.impl;
 
import com.gkhy.labRiskManage.api.controller.riskReport.dto.respDto.ReportRiskSourceQueryRespDTO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportSourceAppInsertBO;
import com.gkhy.labRiskManage.application.riskReport.dto.bo.ReportSourceAppUpdateBO;
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.commons.utils.BeanCopyUtils;
import com.gkhy.labRiskManage.domain.account.service.UserDomainService;
import com.gkhy.labRiskManage.domain.riskReport.entity.ReportExperimentRiskSource;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportSourceInsertBO;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.ReportSourceUpdateBO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportPersonInsertDTO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportRiskSourceDTO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.ReportSourceTypeInsertDTO;
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.ReportExperimentRiskSourceRepository;
import com.gkhy.labRiskManage.domain.riskReport.service.ReportExperimentRiskSourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
 
 
/**
 *
 */
@Service
public class ReportExperimentRiskSourceServiceImpl implements ReportExperimentRiskSourceService {
 
    @Autowired
    private ReportExperimentRiskSourceRepository riskSourceRepository;
    @Autowired
    private UserDomainService userDomainService;
    /**
     * 风险评估报告-危险因素 - 插入
     */
    @Override
    public List<ReportRiskSourceDTO> insertReportSource(Long currentUserId, List<ReportSourceAppInsertBO> riskSourceInsertBO) {
 
        if (riskSourceInsertBO.size() < 1){
            List<ReportRiskSourceDTO> list= new ArrayList<>();
            return list;
        }
 
        List<ReportSourceInsertBO> reportSourceInsertBO = BeanCopyUtils.copyBeanList(riskSourceInsertBO, ReportSourceInsertBO.class);
 
        List<ReportExperimentRiskSource> riskSourceLists = new ArrayList<>();
 
        for (ReportSourceInsertBO sourceInsertBO : reportSourceInsertBO) {
            if (ObjectUtils.isEmpty(sourceInsertBO.getReportId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "报告id不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSource())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险源不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskCharacteristic())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险特性不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getNumber())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "数量不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSourceIndex())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "排序不能为空");
            }
 
            ReportExperimentRiskSource riskSource = BeanCopyUtils.copyBean(sourceInsertBO, ReportExperimentRiskSource.class);
 
            //补全数据
            LocalDateTime date = LocalDateTime.now();
 
            riskSource.setCreateTime(date);
            riskSource.setUpdateTime(date);
            riskSource.setCreateByUserId(currentUserId);
            riskSource.setUpdateByUserId(currentUserId);
            riskSource.setDescription(sourceInsertBO.getDesc());
            riskSource.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
 
            riskSourceLists.add(riskSource);
        }
 
        List<ReportExperimentRiskSource> insertResult = riskSourceRepository.saveAll(riskSourceLists);
        if (insertResult.size() != reportSourceInsertBO.size()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险源写入失败");
        }
 
        return BeanCopyUtils.copyBeanList(insertResult, ReportRiskSourceDTO.class);
    }
 
    /**
     * 风险评估报告-危险因素 - 修改
     */
    @Override
    public List<ReportRiskSourceDTO> updateReportSource(Long currentUserId, List<ReportSourceAppUpdateBO> riskSourceUpdateBO) {
 
        if (riskSourceUpdateBO.size() < 1){
            List<ReportRiskSourceDTO> list= new ArrayList<>();
            return list;
        }
 
        List<ReportSourceUpdateBO> reportSourceUpdateBO = BeanCopyUtils.copyBeanList(riskSourceUpdateBO, ReportSourceUpdateBO.class);
 
        List<ReportExperimentRiskSource> riskSourceLists = new ArrayList<>();
 
        for (ReportSourceUpdateBO sourceInsertBO : reportSourceUpdateBO) {
            if (ObjectUtils.isEmpty(sourceInsertBO.getId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险因素id不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getReportId())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "报告id不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSource())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险源不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskCharacteristic())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "危险特性不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getNumber())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "数量不能为空");
            }
            if (ObjectUtils.isEmpty(sourceInsertBO.getRiskSourceIndex())){
                throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "排序不能为空");
            }
            ReportExperimentRiskSource riskSource = riskSourceRepository.getRiskSourceById(sourceInsertBO.getId());
 
            //补全数据
            LocalDateTime date = LocalDateTime.now();
 
            riskSource.setUpdateTime(date);
            riskSource.setUpdateByUserId(currentUserId);
            riskSource.setRiskSourceIndex(sourceInsertBO.getRiskSourceIndex());
            riskSource.setRiskSource(sourceInsertBO.getRiskSource());
            riskSource.setRiskCharacteristic(sourceInsertBO.getRiskCharacteristic());
            riskSource.setNumber(sourceInsertBO.getNumber());
            riskSource.setDescription(sourceInsertBO.getDesc());
 
            riskSourceLists.add(riskSource);
        }
 
        List<ReportExperimentRiskSource> insertResult = riskSourceRepository.saveAll(riskSourceLists);
        if (insertResult.size() != riskSourceUpdateBO.size()){
            throw new BusinessException(this.getClass(), ResultCode.BUSINESS_ERROR.getCode(), "风险源写入失败");
        }
 
        return BeanCopyUtils.copyBeanList(insertResult, ReportRiskSourceDTO.class);
    }
 
    /**
     * 风险评估报告-危险因素 - 查询by 报告id
     */
    @Override
    public List<ReportRiskSourceQueryRespDTO> getRiskSourceByReportId(Long id) {
 
        List<ReportExperimentRiskSource> riskSourceByReportId = riskSourceRepository.getRiskSourceByReportId(id);
        if (ObjectUtils.isEmpty(riskSourceByReportId)){
            return null;
        }
        List<ReportRiskSourceQueryRespDTO> reportRiskSourceDTOS = BeanCopyUtils.copyBeanList(riskSourceByReportId, ReportRiskSourceQueryRespDTO.class);
        return reportRiskSourceDTOS;
    }
 
    @Override
    public List<ReportExperimentRiskSource> insertAllReportSource(List<ReportExperimentRiskSource> riskSourceList) {
        List<ReportExperimentRiskSource> riskSources = riskSourceRepository.saveAll(riskSourceList);
        return riskSources;
    }
}