huangzhen
2024-02-22 a928eac9193b5ef2498777b5fbfee6fad06534e3
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
package com.gkhy.fourierSpecialGasMonitor.service.impl;
 
import com.alibaba.fastjson.JSON;
import com.gkhy.fourierSpecialGasMonitor.commons.domain.ForeignResult;
import com.gkhy.fourierSpecialGasMonitor.commons.domain.Result;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ForeignResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.exception.DataReceiveException;
import com.gkhy.fourierSpecialGasMonitor.decorator.WarningThresholdUpdateEvent;
import com.gkhy.fourierSpecialGasMonitor.entity.*;
import com.gkhy.fourierSpecialGasMonitor.entity.req.DeviceMonitorReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasConcentrationReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.UploadGasFluxReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.resp.GasCategoryListRespDTO;
import com.gkhy.fourierSpecialGasMonitor.enums.*;
import com.gkhy.fourierSpecialGasMonitor.repository.GasConcentrationRepository;
import com.gkhy.fourierSpecialGasMonitor.service.*;
import com.gkhy.fourierSpecialGasMonitor.utils.SendMessageUtil;
import com.gkhy.fourierSpecialGasMonitor.websocket.GasConcentrationExcWebsocketServer;
import com.gkhy.fourierSpecialGasMonitor.websocket.GasConcentrationWebsocketServer;
import com.gkhy.fourierSpecialGasMonitor.websocket.GasDeviceExcWebsocketServer;
import com.gkhy.fourierSpecialGasMonitor.websocket.GasFluxWebsocketServer;
import io.micrometer.core.instrument.util.StringUtils;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
 
import javax.annotation.PostConstruct;
import java.io.IOException;
import java.lang.reflect.Field;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
 
import static org.apache.el.lang.ELArithmetic.isNumberType;
 
/**
 * @author Mr.huang
 * @decription
 * @date 2023/8/7 14:25
 */
@Service
public class DataReceiveServiceImpl implements DataReceiveService {
 
    @Autowired
    private GasConcentrationService gasConcentrationService;
 
    @Autowired
    private GasCategoryService gasCategoryService;
 
    @Autowired
    private GasThresholdService gasThresholdService;
 
    @Autowired
    private GasWarnLogService gasWarnLogService;
 
    @Autowired
    private RedissonClient redissonClient;
 
    @Autowired
    private GasFluxService gasFluxService;
 
    @Autowired
    private SendMessageUtil sendMessageUtil;
 
    @Autowired
    private GasWarnLogSmsUserService gasWarnLogSmsUserService;
 
    @Autowired
    private GasWarnUserService gasWarnUserService;
 
    @Autowired
    private DeviceExceptionLogService deviceExceptionLogService;
 
    @Autowired
    private GasConcentrationWebsocketServer gasConcentrationWebsocketServer;
 
    @Autowired
    private GasFluxWebsocketServer gasFluxWebsocketServer;
 
    private static final ReentrantLock lock = new ReentrantLock();
 
    @Autowired
    private GasConcentrationExcWebsocketServer gasConcentrationExcWebsocketServer;
 
    private Map<Integer,Integer> gasExcCountMap = new HashMap<>();
 
    private static Integer yellowWarningThreshold = 2;
 
    private static Integer redWarningThreshold = 5;
 
    @Value("${sms.send.enabled}")
    private String smsSendEnabledStatus;
 
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
 
    private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
 
    private static String gasConcentrationCachePrefix = "gas_concentration_cache_";
 
    private static final String warnContentFormat = "【气体监测预警提示】{0} {1}气体浓度连续超标系统判断为{2},请相关负责人及时检查处置。";
 
    private static final String deviceExcLogFormat = "【设备预警提示】{0} 硬件设备离线。";
 
    private static final DateTimeFormatter deviceExcLogFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
 
    private static final DateTimeFormatter warnLogFormatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss");
 
    private static final String[] DEVICE_EXC_RECEIVER = {"17625323889","18019908965"};
 
    @PostConstruct
    public void init() {
        List<GasCategory> gasCategories = gasCategoryService.list();
        if (!CollectionUtils.isEmpty(gasCategories)){
            List<GasCategory> collect = gasCategories.stream().map(gasCategory -> {
                gasExcCountMap.put(gasCategory.getId(), 0);
                return gasCategory;
            }).collect(Collectors.toList());
        }
        logger.info("[GasExcMap] init complete");
    }
 
    @PostConstruct
    public void warningThresholdInit() {
        List<GasThreshold> gasThresholds = gasThresholdService.findAll();
        if (!CollectionUtils.isEmpty(gasThresholds)){
            for (int i = 0; i < gasThresholds.size(); i++) {
                if (WarningThresholdEnum.YELLOW.getCode().equals(gasThresholds.get(i).getId())){
                    yellowWarningThreshold = gasThresholds.get(i).getThreshold();
                }
                if (WarningThresholdEnum.RED.getCode().equals(gasThresholds.get(i).getId())){
                    redWarningThreshold = gasThresholds.get(i).getThreshold();
                }
            }
        }
        logger.info("[WarningThreshold] init complete");
    }
 
    @Override
    public ForeignResult listGasCategory() {
        Result result = gasCategoryService.gasCategoryList();
        List<GasCategoryListRespDTO> data = (List<GasCategoryListRespDTO>) result.getData();
        ForeignResult success = ForeignResult.success();
        success.setData(data);
        return success;
    }
 
    @Override
    public ForeignResult uploadGasFlux(UploadGasFluxReqDTO reqDto) {
        //gasFluxParameterVerification(reqDto);
        GasFlux gasFlux = new GasFlux();
        BeanUtils.copyProperties(reqDto,gasFlux);
        gasFlux.setDataReceivingTime(LocalDateTime.now());
        GasFlux save = gasFluxService.save(gasFlux);
        if (save == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"气体通量数据保存失败");
        gasFluxDataCacheAndPush();
        return ForeignResult.success();
    }
 
    @Override
    public ForeignResult deviceMonitor(DeviceMonitorReqDTO reqDTO) {
        if (reqDTO == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"数据为空");
        if (CollectionUtils.isEmpty(reqDTO.getHardwareState()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"硬件设备状态不能为空");
        if (reqDTO.getConState() < 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"浓度数据状态不能为空");
        if (reqDTO.getFluxState() < 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"通量数据状态不能为空");
        Boolean push = false;
        List<String> descs = new ArrayList<>();
        if (!(reqDTO.getHardwareState().size() == 1 && reqDTO.getHardwareState().get(0) == 0)){
            push = true;
            for (int i = 0; i < reqDTO.getHardwareState().size(); i++) {
                descs.add(HardwareStateEnum.getValue(reqDTO.getHardwareState().get(i)));
            }
        }
        if (GasConcentrationStateEnum.NO_DATA_FROM_ONSITE_EQUIPMENT_FOR_5_MINUTES.getState().equals(reqDTO.getConState())){
            push = true;
            descs.add(GasConcentrationStateEnum.NO_DATA_FROM_ONSITE_EQUIPMENT_FOR_5_MINUTES.getDesc());
        }
        if (GasFluxStateEnum.INVERSION_FAILED_10_MINUTES_NO_DATA.getState().equals(reqDTO.getFluxState())){
            push = true;
            descs.add(GasFluxStateEnum.INVERSION_FAILED_10_MINUTES_NO_DATA.getDesc());
        }
        String message = JSON.toJSONString(reqDTO);
        //todo 暂时改为实时推送给前端
        try {
            GasDeviceExcWebsocketServer.sendInfo(message,null);
        } catch (IOException e) {
            logger.info("【警告】设备异常提醒推送>>>>>>>>>>>>>>>>>>失败");
        }
        if (push){
            DeviceExceptionLog lastLog = deviceExceptionLogService.getLastLog();
            LocalDateTime now = LocalDateTime.now();
            if (lastLog == null || now.compareTo(lastLog.getTime().plusHours(1)) >= 0) {
                Map<String, String> mesMap = new HashMap<>();
                mesMap.put("message","数据异常,无法进行监测");
                mesMap.put(" level","设备离线");
                //// TODO: 2024/2/22
                List<String> deviceExcReceiver = Arrays.asList(DEVICE_EXC_RECEIVER);
                if (!CollectionUtils.isEmpty(deviceExcReceiver)) {
                    List<String> distinctPhone = deviceExcReceiver.stream().distinct().collect(Collectors.toList());
                    logger.info("【气体浓度异常短信发送】-----发送内容:" + "数据异常,无法进行监测 气体浓度连续超标,系统判断为设备离线,请相关负责人及时检查处置。"
                            + " 发送时间: " + LocalDateTime.now()+ " 接收人手机号:" + distinctPhone);
                    if (!org.springframework.util.StringUtils.isEmpty(smsSendEnabledStatus) && "true".equals(smsSendEnabledStatus)) {
                        sendMessageUtil.sendMessageCheck(deviceExcReceiver.toArray(new String[deviceExcReceiver.size()]), mesMap);
                    }
                }
            }
            String execInfo = JSON.toJSONString(descs);
            logger.info("【警告】设备异常,异常原因: "+ execInfo);
            DeviceExceptionLog log = new DeviceExceptionLog();
            String content  = MessageFormat.format(deviceExcLogFormat,deviceExcLogFormatter.format(now));
            log.setContent(content);
            log.setTime(now);
            log.setExecDesc(execInfo);
            DeviceExceptionLog save =  deviceExceptionLogService.save(log);
            if (save == null) {
                logger.info("【警告】设备异常日志保存>>>>>>>>>>>>>>>>>>失败");
            }
 
        }
        return ForeignResult.success();
    }
 
    private void gasFluxDataCacheAndPush(){
        LocalDateTime time = LocalDateTime.now();
        LocalDateTime startTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
        List<GasFlux> gasFluxes =  gasFluxService.listTodayGasFluxData(startTime,time);
        String message = "";
        if (!CollectionUtils.isEmpty(gasFluxes)){
            message = JSON.toJSONString(gasFluxes);
        }
        try {
            gasFluxWebsocketServer.sendInfo(message,null);
        } catch (IOException e) {
            logger.info("【警告】气体通量数据推送>>>>>>>>>>>>>>>>>>失败");
        }
    }
 
 
    @Override
    @Transactional
    public ForeignResult uploadGasConcentration(UploadGasConcentrationReqDTO reqDto) {
        //gasConcentrationParameterVerification(reqDto);
        GasConcentration gasConcentration = new GasConcentration();
        BeanUtils.copyProperties(reqDto,gasConcentration);
        gasConcentration.setDataReceivingTime(LocalDateTime.now());
        GasConcentration save = gasConcentrationService.save(gasConcentration);
        if (save == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"气体实时数据保存失败");
        dataCacheAndPush(save);
        execDataCountAndPush(reqDto);
        return ForeignResult.success();
    }
 
 
    private  void execDataCountAndPush(UploadGasConcentrationReqDTO reqDto){
        RBucket<List<GasCategory>> bucket = redissonClient.getBucket("gas_category_cache_info");
        List<GasCategory> gasCategoryCache = bucket.get();
        if (CollectionUtils.isEmpty(gasCategoryCache)){
            gasCategoryCache = gasCategoryService.list();
            if (CollectionUtils.isEmpty(gasCategoryCache)){
                throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"气体对照表为空");
            }
            bucket.set(gasCategoryCache);
        }
        Map<Integer, Double> threshold = gasCategoryCache.stream().collect(Collectors.toMap(GasCategory::getId, GasCategory::getThreshold));
        Map<Integer,GasCategory> gasCategory = gasCategoryCache.stream().collect(Collectors.toMap(GasCategory::getId,g -> g));
        lock.lock();
        try{
            for (int i = 1; i <= gasCategoryCache.size(); i++) {
                String fileNamePrefix = "gasValue";
                String fileName = fileNamePrefix + i;
                if (i < 10) {
                    fileName = fileNamePrefix + "0" + i;
                }
                Field[] fields = reqDto.getClass().getDeclaredFields();
                for (Field field : fields) {
                    field.setAccessible(true);  // 设置字段可访问,即使是私有字段
                    if (field.getName().equals(fileName)) {
                        Double value = null;
                        try {
                            value = (Double) field.get(reqDto);
                        } catch (IllegalAccessException e) {
                            logger.info("【警告】反射获取气体浓度失败");
                        }
                        if (value != null) {
                            if (value > threshold.get(i)) {
                                Integer integer = gasExcCountMap.get(i);
                                Integer count = integer + 1;
                                gasExcCountMap.put(i, count);
                                if (yellowWarningThreshold.equals(count)) {
                                    warnLogGenerateAndExecPush(WarningThresholdEnum.YELLOW.getCode(), gasCategory.get(i), value);
                                }
                                if (redWarningThreshold.equals(count)) {
                                    warnLogGenerateAndExecPush(WarningThresholdEnum.RED.getCode(), gasCategory.get(i), value);
                                }
                            } else {
                                Integer integer = gasExcCountMap.get(i);
                                if (integer != null) {
                                    gasExcCountMap.put(i, 0);
                                }
                            }
                        }
                    }
                }
            }
        }finally {
            lock.unlock();
        }
    }
 
    private void warnLogGenerateAndExecPush(Integer warnThresholdEnumCode,GasCategory gasCategory,Double value){
        if (gasCategory == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"该气体不存在于对照表");
        GasWarnLog gasWarnLog = new GasWarnLog();
        String warnThresholdName = WarningThresholdEnum.getValue(warnThresholdEnumCode);
        LocalDateTime now = LocalDateTime.now();
        String warnTime = now.format(warnLogFormatter);
        String content  = MessageFormat.format(warnContentFormat,warnTime,gasCategory.getName(),warnThresholdName);
        gasWarnLog.setGasConcentration(value);
        gasWarnLog.setGasName(gasCategory.getName());
        gasWarnLog.setGasUnit(gasCategory.getUnit());
        gasWarnLog.setGasConcentrationThreshold(gasCategory.getThreshold());
        gasWarnLog.setGasMolecularFormula(gasCategory.getMolecularFormula());
        gasWarnLog.setContent(content);
        gasWarnLog.setStatus(WarnHandleStatusEnum.HANDLE_NO.getStatus());
        gasWarnLog.setWarnTime(now);
        gasWarnLog.setGasCategoryId(gasCategory.getId());
        gasWarnLog.setGasThresholdId(warnThresholdEnumCode);
        gasWarnLog.setGasThresholdName(warnThresholdName);
        GasWarnLog save = gasWarnLogService.save(gasWarnLog);
        if (save == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"预警异常日志保存失败");
        String gasConcentrationExcInfo = JSON.toJSONString(save);
        try {
            gasConcentrationExcWebsocketServer.sendInfo(gasConcentrationExcInfo,null);
        } catch (IOException e) {
            logger.info("【警告】气体浓度异常推送>>>>>>>>>>>>>>>>>>失败");
        }
 
        List<GasWarnUser> gasWarnUsers = gasWarnUserService.findAll();
        if (!CollectionUtils.isEmpty(gasWarnUsers)){
            List<String> phone = new ArrayList<>();
            List<GasWarnLogSmsUser> gasWarnLogSmsUsers = gasWarnUsers.stream().map(gasWarnUser -> {
                phone.add(gasWarnUser.getPhone());
                GasWarnLogSmsUser gasWarnLogSmsUser = new GasWarnLogSmsUser();
                BeanUtils.copyProperties(gasWarnUser, gasWarnLogSmsUser, "id");
                gasWarnLogSmsUser.setWarnLogId(save.getId());
                return gasWarnLogSmsUser;
            }).collect(Collectors.toList());
            List<GasWarnLogSmsUser> saveAll = gasWarnLogSmsUserService.saveAll(gasWarnLogSmsUsers);
            if (saveAll == null)
                throw new DataReceiveException(this.getClass(), ForeignResultCode.SYSTEM_ERROR_DATABASE_FAIL.getCode(),"预警异常短信接收人保存失败");
            Map<String, String> mesMap = new HashMap<>();
            mesMap.put("message",warnTime+" "+gasCategory.getName());
            mesMap.put(" level",warnThresholdName);
            //todo
            if (!CollectionUtils.isEmpty(phone)) {
                List<String> distinctPhone = phone.stream().distinct().collect(Collectors.toList());
                logger.info("【气体浓度异常短信发送】-----发送内容:" + content + " 发送时间: " + now + " 接收人手机号:" + distinctPhone);
                if (!org.springframework.util.StringUtils.isEmpty(smsSendEnabledStatus) && "true".equals(smsSendEnabledStatus)) {
                    sendMessageUtil.sendMessageCheck(phone.toArray(new String[phone.size()]), mesMap);
                }
            }
        }
    }
 
    private void dataCacheAndPush(GasConcentration save){
        LocalDateTime startTime = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0).withNano(0);
        LocalDateTime time = LocalDateTime.now();
        String cacheName = time.format(formatter);
        RBucket<String> bucket = redissonClient.getBucket(gasConcentrationCachePrefix+cacheName);
        String cache = bucket.get();
        List<GasConcentration> gasConcentrations = JSON.parseArray(cache,GasConcentration.class);
        if (CollectionUtils.isEmpty(gasConcentrations)){
            List<GasConcentration> concentrations = gasConcentrationService.listDatabyTimeSlot(startTime, time);
            if (CollectionUtils.isEmpty(concentrations)){
                gasConcentrations = new ArrayList<>();
            }else {
                gasConcentrations = concentrations;
            }
            gasConcentrations.add(save);
        }else {
            gasConcentrations.add(save);
        }
        String gasConcentrationsToJson = JSON.toJSONString(gasConcentrations);
        bucket.set(gasConcentrationsToJson);
        try {
            gasConcentrationWebsocketServer.sendInfo(gasConcentrationsToJson,null);
        } catch (IOException e) {
            logger.info("【警告】气体浓度实时推送>>>>>>>>>>>>>>>>>>失败");
        }
    }
 
    private void gasConcentrationParameterVerification(UploadGasConcentrationReqDTO reqDto){
        if (reqDto == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"数据为空");
        if (StringUtils.isBlank(reqDto.getEquipmentId()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"设备id为空");
        if (reqDto.getTime() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"扫描时间为空");
        if (reqDto.getType() <= 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"设备类型异常");
        if (StringUtils.isBlank(reqDto.getLng()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"经度为空");
        if (StringUtils.isBlank(reqDto.getLat()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"纬度为空");
        if (StringUtils.isBlank(reqDto.getAngle()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"角度为空");
        if (reqDto.getTemp() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时温度数据为空");
        if (reqDto.getHumidity() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时相对湿度数据为空");
        if (reqDto.getWindSpeed() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时风速数据为空");
        if (reqDto.getWindDirection() <= 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时风向数据为空");
        if (reqDto.getPressure() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时气压数据为空");
        //if (reqDto.getGasName01() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类01编号异常");
        //if (reqDto.getGasName02() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类02编号异常");
        //if (reqDto.getGasName03() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类03编号异常");
        //if (reqDto.getGasName04() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类04编号异常");
        //if (reqDto.getGasName05() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类05编号异常");
        //if (reqDto.getGasName06() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类06编号异常");
        //if (reqDto.getGasName07() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类07编号异常");
        //if (reqDto.getGasName08() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类08编号异常");
        //if (reqDto.getGasName09() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类09编号异常");
        //if (reqDto.getGasName10() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类10编号异常");
        //if (reqDto.getGasName11() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类11编号异常");
        //if (reqDto.getGasName12() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类12编号异常");
        //if (reqDto.getGasName13() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类13编号异常");
        //if (reqDto.getGasName14() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类14编号异常");
        //if (reqDto.getGasName15() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类15编号异常");
        //if (reqDto.getGasName16() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类16编号异常");
        //if (reqDto.getGasName17() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类17编号异常");
        //if (reqDto.getGasName18() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类18编号异常");
        //if (reqDto.getGasName19() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类19编号异常");
        //if (reqDto.getGasName20() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类20编号异常");
        //if (reqDto.getGasName21() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类21编号异常");
        //if (reqDto.getGasName22() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类22编号异常");
        //if (reqDto.getGasName23() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类23编号异常");
        //if (reqDto.getGasName24() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类24编号异常");
        //if (reqDto.getGasName25() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类25编号异常");
        //if (reqDto.getGasName26() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类26编号异常");
        //if (reqDto.getGasName27() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类27编号异常");
        //if (reqDto.getGasName28() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类28编号异常");
        //if (reqDto.getGasName29() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类29编号异常");
        //if (reqDto.getGasName30() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类30编号异常");
    }
 
    private void gasFluxParameterVerification(UploadGasFluxReqDTO reqDto){
        if (reqDto == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"数据为空");
        if (StringUtils.isBlank(reqDto.getEquipmentId()))
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"设备id为空");
        if (reqDto.getAreaId() <= 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"区域id为空");
        if (reqDto.getTime() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"扫描时间为空");
        if (reqDto.getType() <= 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"设备类型异常");
        if (reqDto.getWindSpeed() == null)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时风速数据为空");
        if (reqDto.getWindDirection() <= 0)
            throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"实时风向数据为空");
        //if (reqDto.getGasName01() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类01编号异常");
        //if (reqDto.getGasName02() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类02编号异常");
        //if (reqDto.getGasName03() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类03编号异常");
        //if (reqDto.getGasName04() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类04编号异常");
        //if (reqDto.getGasName05() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类05编号异常");
        //if (reqDto.getGasName06() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类06编号异常");
        //if (reqDto.getGasName07() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类07编号异常");
        //if (reqDto.getGasName08() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类08编号异常");
        //if (reqDto.getGasName09() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类09编号异常");
        //if (reqDto.getGasName10() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类10编号异常");
        //if (reqDto.getGasName11() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类11编号异常");
        //if (reqDto.getGasName12() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类12编号异常");
        //if (reqDto.getGasName13() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类13编号异常");
        //if (reqDto.getGasName14() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类14编号异常");
        //if (reqDto.getGasName15() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类15编号异常");
        //if (reqDto.getGasName16() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类16编号异常");
        //if (reqDto.getGasName17() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类17编号异常");
        //if (reqDto.getGasName18() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类18编号异常");
        //if (reqDto.getGasName19() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类19编号异常");
        //if (reqDto.getGasName20() <= 0)
        //    throw new DataReceiveException(this.getClass(), ForeignResultCode.PARAM_ERROR_NULL.getCode(),"气体种类20编号异常");
    }
 
 
    //@Async   // 异步方式
    @EventListener   // 监听器注解
    public void updateWarningThreshold(WarningThresholdUpdateEvent event){
        List<GasThreshold> gasThresholds = gasThresholdService.findAll();
        if (!CollectionUtils.isEmpty(gasThresholds)){
            for (int i = 0; i < gasThresholds.size(); i++) {
                if (WarningThresholdEnum.YELLOW.getCode().equals(gasThresholds.get(i).getId())){
                    yellowWarningThreshold = gasThresholds.get(i).getThreshold();
                }
                if (WarningThresholdEnum.RED.getCode().equals(gasThresholds.get(i).getId())){
                    redWarningThreshold = gasThresholds.get(i).getThreshold();
                }
            }
        }
        logger.info("【预警阈值】更新完成");
    }
}