From 167d184121945c0d6098b92fcaeec5e3c8fd4fa3 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期一, 07 八月 2023 11:56:27 +0800
Subject: [PATCH] 优化雷达报警
---
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java | 77 +++++++++++++++++++++++---------------
1 files changed, 46 insertions(+), 31 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
index 6d761a0..1ae7064 100644
--- a/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java
@@ -52,6 +52,7 @@
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
@@ -431,6 +432,7 @@
}
}
+ private Map<String,Integer> guideCountMap=new HashMap<>();
/**
* @鎻忚堪 寮傛澶勭悊鎺ユ敹鐨勬姤璀�
* @鍙傛暟 [topic, message]
@@ -545,11 +547,12 @@
//鍒ゆ柇褰撳墠鎶ヨ鐐�5鍒嗛挓鍐呮槸鍚﹀凡寮曞
ardAlarmRadar.setGuideFlag(1);
// ArdAlarmRadar AlarmRadar = ardAlarmRadarMapper.getArdAlarmRadarWithGuide(ardAlarmRadar);
- ArdAlarmRadar AlarmRadar = redisCache.getCacheObject("global_alarm:guideNew");//浠巖edis涓彇鍑烘渶鏂板紩瀵肩殑鎶ヨ鏁版嵁
- if (StringUtils.isNull(AlarmRadar)) {
+ ArdAlarmRadar AlarmRadar = redisCache.getCacheObject("global_alarm:"+ardAlarmRadar.getName());//浠巖edis涓彇鍑烘渶鏂板紩瀵肩殑鎶ヨ鏁版嵁
+ if (AlarmRadar==null) {
//5鍒嗛挓鍐呮湭寮曞鐩存帴鍏ュ簱
ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
- redisCache.setCacheObject("global_alarm:guideNew",ardAlarmRadar);//寮曞鏁版嵁鍐欏叆redis
+ redisCache.setCacheObject("global_alarm:"+ardAlarmRadar.getName(),ardAlarmRadar,5, TimeUnit.MINUTES);//寮曞鏁版嵁鍐欏叆redis
+ guideCountMap.put(ardAlarmRadar.getName(),0);
//鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
@@ -569,41 +572,53 @@
messagesEnqueued(cameraId, uuid, alarmType, ardAlarmRadar.getCreateTime(), 1, 2, coordinate);
}
} else {
- //5鍒嗛挓鍐呮湁寮曞
- ardAlarmRadar.setGuideFlag(0);
- int count = ardAlarmRadarMapper.getArdAlarmRadarWithNotGuide(ardAlarmRadar, AlarmRadar.getCreateTime());
- //鏈紩瀵艰秴杩�3娆★紝鐩存帴鍏ュ簱鍏ラ槦
- if (count >= 3) {
- ardAlarmRadar.setGuideFlag(1);
- ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
- redisCache.setCacheObject("global_alarm:guideNew",ardAlarmRadar);//寮曞鏁版嵁鍐欏叆redis
- //鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
- String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
- if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
- log.info("鑾峰彇鍒伴浄杈惧涓婄殑鍏夌數:" + cameraIdWithTower);
- //濡傛灉闆疯揪濉斾笂鏈夊厜鐢�
- messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 1, coordinate);
- }
- //鑾峰彇鎶ヨ鐐瑰叧鑱旂殑澶у厜鐢�
- ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
- if (StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId())) {
- String cameraId = ardAlarmpointsWell.getCameraId();
- if (cameraId.equals(cameraIdWithTower)) {
- return;
+ //鑾峰彇褰撳墠鎶ヨ鐐圭殑鏈紩瀵兼鏁�
+ Integer count = guideCountMap.get(ardAlarmRadar.getName());
+ if(count!=null)
+ {
+ if(count>2)
+ {
+ ardAlarmRadar.setGuideFlag(1);
+ redisCache.setCacheObject("global_alarm:"+ardAlarmRadar.getName(),ardAlarmRadar,5, TimeUnit.MINUTES);//寮曞鏁版嵁鍐欏叆redis
+ count=0;
+
+ //鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
+ String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarAlarmData.getRadarId());
+ if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
+ log.info("鑾峰彇鍒伴浄杈惧涓婄殑鍏夌數:" + cameraIdWithTower);
+ //濡傛灉闆疯揪濉斾笂鏈夊厜鐢�
+ messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 1, coordinate);
}
- log.info("鑾峰彇鍒版姤璀︾偣鍏宠仈鐨勫厜鐢�:" + cameraId);
- //濡傛灉鎶ヨ鐐瑰叧鑱斾簡鍏夌數
- messagesEnqueued(cameraId, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 2, coordinate);
+ //鑾峰彇鎶ヨ鐐瑰叧鑱旂殑澶у厜鐢�
+ ArdAlarmpointsWell ardAlarmpointsWell = ardAlarmpointsWellMapper.selectArdAlarmpointsWellByWellId(alarmpointName);
+ if (StringUtils.isNotNull(ardAlarmpointsWell) && StringUtils.isNotEmpty(ardAlarmpointsWell.getCameraId())) {
+ String cameraId = ardAlarmpointsWell.getCameraId();
+ if (cameraId.equals(cameraIdWithTower)) {
+ return;
+ }
+ log.info("鑾峰彇鍒版姤璀︾偣鍏宠仈鐨勫厜鐢�:" + cameraId);
+ //濡傛灉鎶ヨ鐐瑰叧鑱斾簡鍏夌數
+ messagesEnqueued(cameraId, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 2, coordinate);
+ }
}
- } else {
- //鏈紩瀵兼湭瓒呰繃3娆★紝鐩存帴鍏ュ簱
- ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
+ else
+ {
+ ardAlarmRadar.setGuideFlag(0);
+ count++;
+ }
}
+ else
+ {
+ ardAlarmRadar.setGuideFlag(0);
+ count=0;
+ }
+ guideCountMap.put(ardAlarmRadar.getName(),count);
+ ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
}
// 缁撴潫鏃堕棿
long etime = System.currentTimeMillis();
// 璁$畻鎵ц鏃堕棿
- log.info("鏌ヨAPI鎵ц鏃堕暱锛�"+(etime-stime)+"姣");
+ log.info("闆疯揪鎶ヨ澶勭悊鏃堕暱锛�"+(etime-stime)+"姣");
}
//endregion
--
Gitblit v1.9.3