Parcourir la source

这是 小时的异常数据记录

zjs il y a 2 semaines
Parent
commit
bda88247a7
1 fichiers modifiés avec 103 ajouts et 14 suppressions
  1. 103 14
      src/main/java/com/cn/esermis/dpld/business/MonitorBusiness.java

+ 103 - 14
src/main/java/com/cn/esermis/dpld/business/MonitorBusiness.java

@@ -10,6 +10,7 @@ import com.cn.esermis.dpld.service.*;
10 10
 import com.cn.esermis.model.CP;
11 11
 import com.cn.esermis.model.FactorModel;
12 12
 import lombok.extern.log4j.Log4j2;
13
+import org.apache.logging.log4j.core.util.UuidUtil;
13 14
 import org.springframework.beans.factory.annotation.Autowired;
14 15
 import org.springframework.data.redis.core.RedisTemplate;
15 16
 import org.springframework.stereotype.Component;
@@ -41,7 +42,9 @@ public class MonitorBusiness {
41 42
     private IExcepLogService excepLogService;
42 43
     @Resource
43 44
     private IAirMonitorHourRecordService airMonitorHourRecordService;
44
-    @Autowired
45
+    @Resource
46
+    private IPostMarkingService postMarkingService;
47
+    @Resource
45 48
     private RedisTemplate<String, Object> redisTemplate;
46 49
 
47 50
 
@@ -104,9 +107,9 @@ public class MonitorBusiness {
104 107
                             airMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
105 108
                                     x.getMin()!=null?x.getMin().doubleValue():0,
106 109
                                     x.getAvg()!=null?x.getAvg().doubleValue():0));
107
-                            if ((airMonitorMinuteRecord.getIsExceed()!=null && !airMonitorMinuteRecord.getIsExceed().equals("Y") )||
108
-                                    (airMonitorMinuteRecord.getIsLose()!=null && !airMonitorMinuteRecord.getIsLose().equals("Y") )||
109
-                                    (airMonitorMinuteRecord.getIsSix()!=null && !airMonitorMinuteRecord.getIsSix().equals("Y"))){
110
+                            if ((airMonitorMinuteRecord.getIsExceed()!=null && !airMonitorMinuteRecord.getIsExceed().equals("1") )||
111
+                                    (airMonitorMinuteRecord.getIsLose()!=null && !airMonitorMinuteRecord.getIsLose().equals("1") )||
112
+                                    (airMonitorMinuteRecord.getIsSix()!=null && !airMonitorMinuteRecord.getIsSix().equals("1"))){
110 113
                                 saveExcepLog(x, airMonitorMinuteRecord);
111 114
                             }
112 115
                         } catch (Exception e) {
@@ -185,15 +188,20 @@ public class MonitorBusiness {
185 188
                         airMonitorHourRecord.setZsMin(x.getZsMin());
186 189
                         airMonitorHourRecord.setRtd(x.getRtd());
187 190
                         try {
191
+                            airMonitorHourRecord.setWorkCondition(sendHoursMessage(factorModel.getDataTime(),factorModel.getMN()));
192
+                        } catch (Exception e) {
193
+                            throw new RuntimeException(e);
194
+                        }
195
+                        try {
188 196
                             airMonitorHourRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
189 197
                             airMonitorHourRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
190 198
                                     x.getMin()!=null?x.getMin().doubleValue():0,
191 199
                                     x.getAvg()!=null?x.getAvg().doubleValue():0));
192 200
                             airMonitorHourRecord.setIsSix(exceptionDataDispose.SixData(factorModel.getMN(), x.getFactor(),x.getAvg()!=null?x.getAvg().doubleValue():0, factorModel.getDataTime()));
193 201
 //                            if (!airMonitorHourRecord.getIsExceed().equals("Y") || !airMonitorHourRecord.getIsLose().equals("Y") || !airMonitorHourRecord.getIsSix().equals("Y")){
194
-                            if ((airMonitorHourRecord.getIsExceed()!=null && !airMonitorHourRecord.getIsExceed().equals("Y") )||
195
-                                    (airMonitorHourRecord.getIsLose()!=null && !airMonitorHourRecord.getIsLose().equals("Y") )||
196
-                                    (airMonitorHourRecord.getIsSix()!=null && !airMonitorHourRecord.getIsSix().equals("Y"))){
202
+                            if ((airMonitorHourRecord.getIsExceed()!=null && !airMonitorHourRecord.getIsExceed().equals("1") )||
203
+                                    (airMonitorHourRecord.getIsLose()!=null && !airMonitorHourRecord.getIsLose().equals("1") )||
204
+                                    (airMonitorHourRecord.getIsSix()!=null && !airMonitorHourRecord.getIsSix().equals("1"))){
197 205
                                 saveExcepLog(x, airMonitorHourRecord);
198 206
                             }
199 207
                         } catch (Exception e) {
@@ -234,9 +242,9 @@ public class MonitorBusiness {
234 242
                             waterMonitorMinuteRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
235 243
                                     x.getMin()!=null?x.getMin().doubleValue():0,
236 244
                                     x.getAvg()!=null?x.getAvg().doubleValue():0));
237
-                            if ((waterMonitorMinuteRecord.getIsExceed()!=null && !waterMonitorMinuteRecord.getIsExceed().equals("Y") )||
238
-                                    (waterMonitorMinuteRecord.getIsLose()!=null && !waterMonitorMinuteRecord.getIsLose().equals("Y") )||
239
-                                    (waterMonitorMinuteRecord.getIsSix()!=null && !waterMonitorMinuteRecord.getIsSix().equals("Y"))){
245
+                            if ((waterMonitorMinuteRecord.getIsExceed()!=null && !waterMonitorMinuteRecord.getIsExceed().equals("1") )||
246
+                                    (waterMonitorMinuteRecord.getIsLose()!=null && !waterMonitorMinuteRecord.getIsLose().equals("1") )||
247
+                                    (waterMonitorMinuteRecord.getIsSix()!=null && !waterMonitorMinuteRecord.getIsSix().equals("1"))){
240 248
                                 saveExcepLog(x, waterMonitorMinuteRecord);
241 249
                             }
242 250
                         } catch (Exception e) {
@@ -311,14 +319,19 @@ public class MonitorBusiness {
311 319
                         waterMonitorHourRecord.setFactorFlag(x.getFlag());
312 320
                         waterMonitorHourRecord.setRtd(x.getRtd());
313 321
                         try {
322
+                            waterMonitorHourRecord.setWorkCondition(sendHoursMessage(factorModel.getDataTime(),factorModel.getMN()));
323
+                        } catch (Exception e) {
324
+                            throw new RuntimeException(e);
325
+                        }
326
+                        try {
314 327
                             waterMonitorHourRecord.setIsExceed(exceptionDataDispose.ExceedData(factorModel.getMN(), x.getFactor(), x.getAvg()!=null?x.getAvg().doubleValue():x.getRtd().doubleValue()));
315 328
                             waterMonitorHourRecord.setIsLose(exceptionDataDispose.LoseData(x.getMax()!=null?x.getMax().doubleValue():0,
316 329
                                     x.getMin()!=null?x.getMin().doubleValue():0,
317 330
                                     x.getAvg()!=null?x.getAvg().doubleValue():0));
318 331
                             waterMonitorHourRecord.setIsSix(exceptionDataDispose.SixData(factorModel.getMN(), x.getFactor(),x.getAvg()!=null?x.getAvg().doubleValue():0, factorModel.getDataTime()));
319
-                            if ((waterMonitorHourRecord.getIsExceed()!=null && !waterMonitorHourRecord.getIsExceed().equals("Y") )||
320
-                                    (waterMonitorHourRecord.getIsLose()!=null && !waterMonitorHourRecord.getIsLose().equals("Y") )||
321
-                                    (waterMonitorHourRecord.getIsSix()!=null && !waterMonitorHourRecord.getIsSix().equals("Y"))){
332
+                            if ((waterMonitorHourRecord.getIsExceed()!=null && !waterMonitorHourRecord.getIsExceed().equals("1") )||
333
+                                    (waterMonitorHourRecord.getIsLose()!=null && !waterMonitorHourRecord.getIsLose().equals("1") )||
334
+                                    (waterMonitorHourRecord.getIsSix()!=null && !waterMonitorHourRecord.getIsSix().equals("1"))){
322 335
                                 saveExcepLog(x, waterMonitorHourRecord);
323 336
                             }
324 337
                         } catch (Exception e) {
@@ -348,7 +361,15 @@ public class MonitorBusiness {
348 361
             excepLog.setLoseData(record.getIsLose());
349 362
             excepLogService.save(excepLog);
350 363
         }
351
-
364
+        if (record.getIsLose()!=null && !record.getIsLose().equals("1")){
365
+            addExcepLog(record.getFactor(), "1");
366
+        }
367
+        if (record.getIsSix()!=null && !record.getIsSix().equals("1")){
368
+            addExcepLog(record.getFactor(), "2");
369
+        }
370
+        if (record.getIsExceed()!=null && !record.getIsExceed().equals("1")){
371
+            addExcepLog(record.getFactor(), "3");
372
+        }
352 373
     }
353 374
 
354 375
     private void saveExcepLog(CP x, AirMonitorHourRecord record) {
@@ -364,6 +385,15 @@ public class MonitorBusiness {
364 385
             excepLog.setLoseData(record.getIsLose());
365 386
             excepLogService.save(excepLog);
366 387
         }
388
+        if (record.getIsLose()!=null && !record.getIsLose().equals("1")){
389
+            addExcepLog(record.getFactor(), "1");
390
+        }
391
+        if (record.getIsSix()!=null && !record.getIsSix().equals("1")){
392
+            addExcepLog(record.getFactor(), "2");
393
+        }
394
+        if (record.getIsExceed()!=null && !record.getIsExceed().equals("1")){
395
+            addExcepLog(record.getFactor(), "3");
396
+        }
367 397
     }
368 398
 
369 399
     private void saveExcepLog(CP x, WaterMonitorMinuteRecord record) {
@@ -379,6 +409,15 @@ public class MonitorBusiness {
379 409
             excepLog.setLoseData(record.getIsLose());
380 410
             excepLogService.save(excepLog);
381 411
         }
412
+        if (record.getIsLose()!=null && !record.getIsLose().equals("1")){
413
+            addExcepLog(record.getFactor(), "1");
414
+        }
415
+        if (record.getIsSix()!=null && !record.getIsSix().equals("1")){
416
+            addExcepLog(record.getFactor(), "2");
417
+        }
418
+        if (record.getIsExceed()!=null && !record.getIsExceed().equals("1")){
419
+            addExcepLog(record.getFactor(), "3");
420
+        }
382 421
     }
383 422
     private void saveExcepLog(CP x, WaterMonitorHourRecord record) {
384 423
         ExcepLog excepLog = new ExcepLog();
@@ -393,6 +432,15 @@ public class MonitorBusiness {
393 432
             excepLog.setLoseData(record.getIsLose());
394 433
             excepLogService.save(excepLog);
395 434
         }
435
+        if (record.getIsLose()!=null && !record.getIsLose().equals("1")){
436
+            addExcepLog(record.getFactor(), "1");
437
+        }
438
+        if (record.getIsSix()!=null && !record.getIsSix().equals("1")){
439
+            addExcepLog(record.getFactor(), "2");
440
+        }
441
+        if (record.getIsExceed()!=null && !record.getIsExceed().equals("1")){
442
+            addExcepLog(record.getFactor(), "3");
443
+        }
396 444
     }
397 445
 
398 446
     public Integer sendMessage(String time,String mn) throws ParseException {
@@ -407,6 +455,20 @@ public class MonitorBusiness {
407 455
         }
408 456
         return 1;
409 457
     }
458
+
459
+    public Integer sendHoursMessage(String time,String mn){
460
+        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHH");
461
+        Object o = redisTemplate.opsForValue().get(mn);
462
+        if (o != null){
463
+            PreMarking preMarking = JSON.parseObject(o.toString(), PreMarking.class);
464
+//            Date date = formatter.parse(time);
465
+            String format = formatter.format(preMarking.getStartTime().getTime());
466
+            if (time.contains(format)){
467
+                return preMarking.getWorkingCondition();
468
+            }
469
+        }
470
+        return 1;
471
+    }
410 472
     /**
411 473
      * 获取工厂排口信息
412 474
      */
@@ -421,5 +483,32 @@ public class MonitorBusiness {
421 483
         }
422 484
         return dataAcquisitionInstruments;
423 485
     }
486
+    /**
487
+     * 添加事后处置单信息
488
+     */
489
+    public void addExcepLog(String factor,String dataType) {
490
+        PostMarking postMarking = new PostMarking();
491
+        Optional<OutletAndFactorVo> first = getloadData().stream().filter(d -> d.getFactor()!=null && d.getFactor().equals(factor)).findFirst();
492
+        if (first.isPresent()) {
493
+            postMarking.setOutletName(first.get().getOutletName());
494
+            postMarking.setOutletNumber(first.get().getOutletCode());
495
+            postMarking.setManagementNumber(String.valueOf(UuidUtil.getTimeBasedUuid()));
496
+            switch (dataType){
497
+                case "1":
498
+                    //判断是否为负值数据
499
+                    postMarking.setManagementContent("数据异常:采集数据为负数。");
500
+                    break;
501
+                case "2":
502
+                    // //判断是否为六小时恒值数据
503
+                    postMarking.setManagementContent("数据异常:6小时恒值异常。");
504
+                    break;
505
+                case "3":
506
+                    //瞬时值是否为超标数据
507
+                    postMarking.setManagementContent("数据异常:瞬时值超标。");
508
+                    break;
509
+            }
510
+            postMarkingService.save(postMarking);
511
+        }
512
+    }
424 513
 
425 514
 }