heheng
2025-05-23 761bdc5b3f17df62aae1b424f2d2dabc11e844bc
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
package com.gkhy.labRiskManage.domain.riskReport.service.impl;
 
import com.gkhy.labRiskManage.api.controller.riskReport.dto.repDto.RiskAssessPlanEvaluateDeleteReqBO;
import com.gkhy.labRiskManage.commons.enums.MethodEnum;
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.riskReport.entity.RiskAssessPlanEvaluateLec;
import com.gkhy.labRiskManage.domain.riskReport.entity.RiskAssessPlanEvaluateLs;
import com.gkhy.labRiskManage.domain.riskReport.model.bo.AssessLSInsertBO;
import com.gkhy.labRiskManage.domain.riskReport.model.dto.*;
import com.gkhy.labRiskManage.domain.riskReport.repository.jpa.RiskAssessPlanEvaluateLsRepository;
import com.gkhy.labRiskManage.domain.riskReport.service.RiskAssessPlanEvaluateLsService;
import com.gkhy.labRiskManage.domain.riskReport.utils.IdentificationMethodCheck;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
 
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;
 
/**
 * 评价方法LS
 */
@Service
public class RiskAssessPlanEvaluateLsServiceImpl implements RiskAssessPlanEvaluateLsService {
 
    @Autowired
    private RiskAssessPlanEvaluateLsRepository lsRepository;
 
    /**
     * 评价方法LS - 插入
     */
    @Override
    public LsInsertDTO insertLs(Long currentUserId, AssessLSInsertBO lsInsertBO) {
 
        EvaluateInsertDTO insertDTO = new EvaluateInsertDTO();
        insertDTO.setResult(1);
        IdentificationMethodCheck methodCheck = new IdentificationMethodCheck();
 
        //校验辨识方法是否存在
        int result = methodCheck.identificationMethodCheck(lsInsertBO.getIdentificationId(), lsInsertBO.getIdentificationMethod());
        if (result == 0){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "辨识方法不存在");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getAssessPlanId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价的计划不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getLsL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LS_L的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getLsS())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LS_S的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getRiskValue())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalLsL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LS_L的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalLsS())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LS_S的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalRiskValue())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有风险数值不能为空");
        }
        RiskAssessPlanEvaluateLs lsByIdentification = lsRepository.getLsByIdentification(lsInsertBO.getIdentificationId(), lsInsertBO.getIdentificationMethod());
        if (!ObjectUtils.isEmpty(lsByIdentification)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "该辨识已经被评价,无需重复操作");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getEvaluateDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价专家意见不能为空");
        }
        BigDecimal value = lsInsertBO.getLsL().multiply(lsInsertBO.getLsS());
        //BigDecimal类型比较,结果为0是相等
        if (value.compareTo(lsInsertBO.getRiskValue()) != 0){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值计算有误,无法保存");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getSafeRiskAnalysis())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "安全风险分析内容不能为空");
        }
 
        RiskAssessPlanEvaluateLs ls = new RiskAssessPlanEvaluateLs();
        //设置参数
        if (value.compareTo(new BigDecimal(10)) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_1.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_1.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_1.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_1.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_2.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_2.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_2.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_3.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_3.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_3.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) > 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_4.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_4.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_4.getCode());
        }
        LocalDateTime date = LocalDateTime.now();
        ls.setIdentificationId(lsInsertBO.getIdentificationId());
        ls.setIdentificationMethod(lsInsertBO.getIdentificationMethod());
        ls.setAssessPlanId(lsInsertBO.getAssessPlanId());
        ls.setLsL(lsInsertBO.getLsL());
        ls.setLsS(lsInsertBO.getLsS());
        ls.setDeleteStatus(StatusEnum.DELETE_NOT.getCode().byteValue());
        ls.setCreateTime(date);
        ls.setUpdateTime(date);
        ls.setRiskValue(lsInsertBO.getRiskValue());
        ls.setManageLevel(lsInsertBO.getManageLevel());
        ls.setStatus((byte) 1);
        ls.setEvaluateDesc(lsInsertBO.getEvaluateDesc());
 
        ls.setEducationMeasure(lsInsertBO.getEducationMeasure());
        ls.setTechnologyMeasure(lsInsertBO.getTechnologyMeasure());
        ls.setManageMeasure(lsInsertBO.getManageMeasure());
        ls.setPersonalProtectionMeasure(lsInsertBO.getPersonalProtectionMeasure());
        ls.setEmergencyMeasure(lsInsertBO.getEmergencyMeasure());
 
        ls.setOriginalLsL(lsInsertBO.getOriginalLsL());
        ls.setOriginalLsS(lsInsertBO.getOriginalLsS());
        ls.setOriginalRiskValue(lsInsertBO.getOriginalRiskValue());
        ls.setOriginalRiskLevelValue(lsInsertBO.getOriginalRiskLevelValue());
        ls.setOriginalRiskLevel(lsInsertBO.getOriginalRiskLevel());
        ls.setOriginalRiskColor(lsInsertBO.getOriginalRiskColor());
        ls.setOriginalManageLevel(lsInsertBO.getOriginalManageLevel());
        ls.setAdviseTechnologyMeasure(lsInsertBO.getAdviseTechnologyMeasure());
        ls.setAdviseManageMeasure(lsInsertBO.getAdviseManageMeasure());
        ls.setAdviseEmergencyMeasure(lsInsertBO.getAdviseEmergencyMeasure());
        ls.setAdviseEducationMeasure(lsInsertBO.getAdviseEducationMeasure());
        ls.setAdvisePersonalProtectionMeasure(lsInsertBO.getAdvisePersonalProtectionMeasure());
        ls.setSafeRiskAnalysis(lsInsertBO.getSafeRiskAnalysis());
 
        RiskAssessPlanEvaluateLs insertResult = lsRepository.save(ls);
 
        return BeanCopyUtils.copyBean(insertResult, LsInsertDTO.class);
    }
 
    /**
     * 评价方法LS - 修改
     */
    @Override
    public LecInsertDTO updateLs(Long currentUserId, AssessLSInsertBO lsInsertBO) {
 
        EvaluateInsertDTO insertDTO = new EvaluateInsertDTO();
        insertDTO.setResult(1);
 
        if (ObjectUtils.isEmpty(lsInsertBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的评价内容不能为空");
        }
        RiskAssessPlanEvaluateLs lsById = lsRepository.getLsById(lsInsertBO.getId());
        if (ObjectUtils.isEmpty(lsById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要修改的评价不存在");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getAssessPlanId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价的计划不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getLsL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LS_L的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getLsS())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "LS_S的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getRiskValue())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getEvaluateDesc())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价专家意见不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalLsL())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LS_L的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalLsS())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有LS_S的数值不能为空");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getOriginalRiskValue())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "固有风险数值不能为空");
        }
        BigDecimal value = lsInsertBO.getLsL().multiply(lsInsertBO.getLsS());
        //BigDecimal类型比较,结果为0是相等
        if (value.compareTo(lsInsertBO.getRiskValue()) != 0){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "风险数值计算有误,无法保存");
        }
        if (ObjectUtils.isEmpty(lsInsertBO.getSafeRiskAnalysis())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "安全风险分析内容不能为空");
        }
 
        //设置参数
        LocalDateTime date = LocalDateTime.now();
        RiskAssessPlanEvaluateLs ls = BeanCopyUtils.copyBean(lsById, RiskAssessPlanEvaluateLs.class);
        if (value.compareTo(new BigDecimal(10)) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_1.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_1.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_1.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_1.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_2.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_2.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_2.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_2.getCode())) > 0 && value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) < 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_3.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_3.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_3.getCode());
        }else if (value.compareTo(new BigDecimal(MethodEnum.RISK_EVALUATE_VALUE_3.getCode())) > 0){
            ls.setRiskLevel(MethodEnum.RISK_LEVEL_4.getCode());
            ls.setRiskLevelValue(MethodEnum.RISK_LEVEL_4.getCode());
            ls.setRiskColor(MethodEnum.RISK_LEVEL_4.getCode());
        }
        ls.setLsL(lsInsertBO.getLsL());
        ls.setLsS(lsInsertBO.getLsS());
        ls.setUpdateTime(date);
        ls.setRiskValue(lsInsertBO.getRiskValue());
        ls.setManageLevel(lsInsertBO.getManageLevel());
        ls.setEvaluateDesc(lsInsertBO.getEvaluateDesc());
 
        ls.setEducationMeasure(lsInsertBO.getEducationMeasure());
        ls.setTechnologyMeasure(lsInsertBO.getTechnologyMeasure());
        ls.setManageMeasure(lsInsertBO.getManageMeasure());
        ls.setPersonalProtectionMeasure(lsInsertBO.getPersonalProtectionMeasure());
        ls.setEmergencyMeasure(lsInsertBO.getEmergencyMeasure());
 
        ls.setOriginalLsL(lsInsertBO.getOriginalLsL());
        ls.setOriginalLsS(lsInsertBO.getOriginalLsS());
        ls.setOriginalRiskValue(lsInsertBO.getOriginalRiskValue());
        ls.setOriginalRiskLevelValue(lsInsertBO.getOriginalRiskLevelValue());
        ls.setOriginalRiskLevel(lsInsertBO.getOriginalRiskLevel());
        ls.setOriginalRiskColor(lsInsertBO.getOriginalRiskColor());
        ls.setOriginalManageLevel(lsInsertBO.getOriginalManageLevel());
        ls.setAdviseTechnologyMeasure(lsInsertBO.getAdviseTechnologyMeasure());
        ls.setAdviseManageMeasure(lsInsertBO.getAdviseManageMeasure());
        ls.setAdviseEmergencyMeasure(lsInsertBO.getAdviseEmergencyMeasure());
        ls.setAdviseEducationMeasure(lsInsertBO.getAdviseEducationMeasure());
        ls.setAdvisePersonalProtectionMeasure(lsInsertBO.getAdvisePersonalProtectionMeasure());
        ls.setSafeRiskAnalysis(lsInsertBO.getSafeRiskAnalysis());
 
        RiskAssessPlanEvaluateLs insertResult = lsRepository.save(ls);
 
        return BeanCopyUtils.copyBean(insertResult, LecInsertDTO.class);
    }
 
    /**
     * 评价方法LS - 查询
     */
    @Override
    public LsQueryDTO getLsByPlanId(Long id) {
 
        RiskAssessPlanEvaluateLs lsById = lsRepository.getLsById(id);
        if (ObjectUtils.isEmpty(lsById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "ls评价方法不存在或已被删除");
        }
        return BeanCopyUtils.copyBean(lsById, LsQueryDTO.class);
    }
 
    /**
     * 评价方法LS - 删除
     */
    @Override
    public EvaluateMethodDeleteDTO deleteLsByPlanId(Long currentUserId, RiskAssessPlanEvaluateDeleteReqBO deleteReqBO) {
 
        if (ObjectUtils.isEmpty(deleteReqBO.getLsId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要删除的评价项目不能为空");
        }
        RiskAssessPlanEvaluateLs lsById = lsRepository.getLsById(deleteReqBO.getLsId());
        if (ObjectUtils.isEmpty(lsById)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "要删除的评价项目为空,或已被删除");
        }
        if (!lsById.getAssessPlanId().equals(deleteReqBO.getId())){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评估计划与评价项不匹配,无法删除");
        }
 
        EvaluateMethodDeleteDTO deleteDTO = new EvaluateMethodDeleteDTO();
 
        lsById.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
        LocalDateTime date = LocalDateTime.now();
        lsById.setUpdateTime(date);
 
        RiskAssessPlanEvaluateLs deleteResult = lsRepository.save(lsById);
        if (ObjectUtils.isEmpty(deleteResult)){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价方法不存在或已被删除");
        }
        deleteDTO.setResult(StatusEnum.DELETED.getCode().byteValue());
 
        return deleteDTO;
    }
 
    /**
     * 评价方法LS - list
     */
    @Override
    public List<LsQueryDTO> listLsByPlanId(Long id) {
        List<RiskAssessPlanEvaluateLs>  lsList = lsRepository.listLsByPlanId(id);
        return BeanCopyUtils.copyBeanList(lsList, LsQueryDTO.class);
    }
 
    @Override
    public List<RiskAssessPlanEvaluateLs> getLsByIds(List<Long> assessPlanIds) {
        return lsRepository.getLsByIds(assessPlanIds);
    }
 
    @Override
    public int deleteLsByAssessPlanId(Long id) {
 
        List<RiskAssessPlanEvaluateLs> lsList = lsRepository.getLsByAssessPlanId(id);
        if (lsList.size() < 1){
            throw new BusinessException(this.getClass(), ResultCode.PARAM_ERROR_NULL.getCode(), "评价方法不存在或已被删除");
        }
        int i = 0;
        for (RiskAssessPlanEvaluateLs ls : lsList) {
            ls.setDeleteStatus(StatusEnum.DELETED.getCode().byteValue());
            RiskAssessPlanEvaluateLs save = lsRepository.save(ls);
            if (ObjectUtils.isEmpty(save)){
                i = 1;
            }
        }
        return i;
    }
 
    @Override
    public int deleteLsByPlan(Long id) {
        List<RiskAssessPlanEvaluateLs> lsListByPlanId = lsRepository.getLsByPlanId(id);
        if (ObjectUtils.isEmpty(lsListByPlanId)){
            return StatusEnum.SUCCESS.getCode();
        }
        for (RiskAssessPlanEvaluateLs riskAssessPlanEvaluateLs : lsListByPlanId) {
            riskAssessPlanEvaluateLs.setEvaluateDesc(StatusEnum.DELETED.getDesc());
        }
        List<RiskAssessPlanEvaluateLs> result = lsRepository.saveAll(lsListByPlanId);
        if (result.size() != lsListByPlanId.size()){
            return StatusEnum.FAIL.getCode();
        }
        return StatusEnum.SUCCESS.getCode();
    }
 
    @Override
    public RiskAssessPlanEvaluateLs getLsByIdentificationId(Long id, Byte identificationMethod) {
        return lsRepository.getLsByIdentification(id, identificationMethod);
    }
 
    @Override
    public List<RiskAssessPlanEvaluateLs> listLsByParam(Long id, Long identificationId, Byte identificationMethod) {
        return lsRepository.getLsByParam(id, identificationId, identificationMethod);
    }
}