From be65526c48eaa674afe2601e2c53556d5797f2f3 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期一, 07 八月 2023 12:37:59 +0800
Subject: [PATCH] 优化雷达报警
---
ard-work/src/main/java/com/ruoyi/alarm/global/service/impl/GlobalAlarmServiceImpl.java | 149 +++++++++++++++++--------------------------------
1 files changed, 53 insertions(+), 96 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 1ae7064..fec6e6f 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
@@ -97,6 +97,8 @@
@Resource
private QueueManager queueManager;
//endregion
+ //姣忎釜鐐逛綅鏈紩瀵兼鏁�
+ private Map<String, Integer> unGuideCountMap = new HashMap<>();
/**
* @鎻忚堪 鏌ヨ鎵�鏈夋姤璀︾殑褰撳墠鏁伴噺
@@ -432,7 +434,6 @@
}
}
- private Map<String,Integer> guideCountMap=new HashMap<>();
/**
* @鎻忚堪 寮傛澶勭悊鎺ユ敹鐨勬姤璀�
* @鍙傛暟 [topic, message]
@@ -544,81 +545,45 @@
}
double[] coordinate = new double[]{ardAlarmRadar.getLongitude(), ardAlarmRadar.getLatitude()};//鎶ヨ鍧愭爣
- //鍒ゆ柇褰撳墠鎶ヨ鐐�5鍒嗛挓鍐呮槸鍚﹀凡寮曞
- ardAlarmRadar.setGuideFlag(1);
- // ArdAlarmRadar AlarmRadar = ardAlarmRadarMapper.getArdAlarmRadarWithGuide(ardAlarmRadar);
- ArdAlarmRadar AlarmRadar = redisCache.getCacheObject("global_alarm:"+ardAlarmRadar.getName());//浠巖edis涓彇鍑烘渶鏂板紩瀵肩殑鎶ヨ鏁版嵁
- if (AlarmRadar==null) {
- //5鍒嗛挓鍐呮湭寮曞鐩存帴鍏ュ簱
- ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
- 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)) {
- log.info("鑾峰彇鍒伴浄杈惧涓婄殑鍏夌數:" + cameraIdWithTower);
- //濡傛灉闆疯揪濉斾笂鏈夊厜鐢�
- messagesEnqueued(cameraIdWithTower, uuid, alarmType, ardAlarmRadar.getCreateTime(), 1, 1, 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(), 1, 2, coordinate);
- }
- } else {
- //鑾峰彇褰撳墠鎶ヨ鐐圭殑鏈紩瀵兼鏁�
- 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;
+ //浠巖edis涓彇鍑哄綋鍓嶆姤璀︾偣鐨�5鍒嗛挓鍐呮槸鍚︽湁寮曞
+ ArdAlarmRadar AlarmRadar = redisCache.getCacheObject("global_alarm:" + ardAlarmRadar.getName());//浠巖edis涓彇鍑烘渶鏂板紩瀵肩殑鎶ヨ鏁版嵁
+ if (AlarmRadar == null) {
+ //5鍒嗛挓鍐卹edis涓病鏈夋暟鎹紝璇存槑5鍒嗛挓鍐呮病鏈夊紩瀵兼暟鎹�
+ ardAlarmRadar.setGuideFlag(1);
+ //灏嗗紩瀵兼暟鎹啓鍏edis 璁剧疆5鍒嗛挓杩囨湡
+ redisCache.setCacheObject("global_alarm:" + ardAlarmRadar.getName(), ardAlarmRadar, 5, TimeUnit.MINUTES);//寮曞鏁版嵁鍐欏叆redis
+ unGuideCountMap.put(ardAlarmRadar.getName(), 0);
+ //寮曞鍏ラ槦
+ radarGuide(radarAlarmData.getRadarId(), alarmpointName, alarmType, ardAlarmRadar.getCreateTime(), coordinate);
- //鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
- 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;
- }
- log.info("鑾峰彇鍒版姤璀︾偣鍏宠仈鐨勫厜鐢�:" + cameraId);
- //濡傛灉鎶ヨ鐐瑰叧鑱斾簡鍏夌數
- messagesEnqueued(cameraId, uuid, alarmType, ardAlarmRadar.getCreateTime(), count, 2, coordinate);
- }
- }
- else
- {
+ } else {
+ //5鍒嗛挓鍐卹edis涓湁鏁版嵁锛岃鏄�5鍒嗛挓鍐呮湁寮曞鏁版嵁,鑾峰彇褰撳墠鎶ヨ鐐圭殑鏈紩瀵兼鏁�
+ Integer count = unGuideCountMap.get(ardAlarmRadar.getName());
+ if (count != null) {
+ if (count > 2) {
+ //鏈紩瀵兼鏁�3娆″悗杩涜寮曞
+ ardAlarmRadar.setGuideFlag(1);
+ //灏嗗紩瀵兼暟鎹啓鍏edis 璁剧疆5鍒嗛挓杩囨湡
+ redisCache.setCacheObject("global_alarm:" + ardAlarmRadar.getName(), ardAlarmRadar, 5, TimeUnit.MINUTES);
+ count = 0;
+ //寮曞鍏ラ槦
+ radarGuide(radarAlarmData.getRadarId(), alarmpointName, alarmType, ardAlarmRadar.getCreateTime(), coordinate);
+ } else {
ardAlarmRadar.setGuideFlag(0);
count++;
}
- }
- else
- {
+ } else {
ardAlarmRadar.setGuideFlag(0);
- count=0;
+ count = 0;
}
- guideCountMap.put(ardAlarmRadar.getName(),count);
- ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
+ unGuideCountMap.put(ardAlarmRadar.getName(), count);
}
+ //鍏ュ簱
+ ardAlarmRadarMapper.insertArdAlarmRadar(ardAlarmRadar);
// 缁撴潫鏃堕棿
long etime = System.currentTimeMillis();
// 璁$畻鎵ц鏃堕棿
- log.info("闆疯揪鎶ヨ澶勭悊鏃堕暱锛�"+(etime-stime)+"姣");
+ log.info("闆疯揪鎶ヨ澶勭悊鏃堕暱锛�" + (etime - stime) + "姣");
}
//endregion
@@ -754,7 +719,7 @@
private Boolean IsEnableGuide(String cameraId) {
boolean enabled = false;
ArdCameras ardCameras = redisCache.getCacheObject(CacheConstants.CAMERA_LIST_KEY + cameraId);
- if(ardCameras!=null) {
+ if (ardCameras != null) {
if (ardCameras.getCamAlarmGuideEnable().equals(1)) {
enabled = true;
}
@@ -796,37 +761,29 @@
return minDistanceCameraId;
}
- public static void main(String[] args) {
- Comparator<Obj> PriorityDescCom = Comparator.comparingInt(Obj::getPriority).reversed();
- Comparator<Obj> NumDescCom = Comparator.comparingInt(Obj::getNum).reversed();
- Comparator<Obj> receiveTimeAscCom = Comparator.comparing(Obj::getAlarmTime);
- Comparator<Obj> comparator = PriorityDescCom.thenComparing(NumDescCom).thenComparing(receiveTimeAscCom);
-
- PriorityBlockingQueue<Obj> priorityQueue = new PriorityBlockingQueue<>(1000, comparator);
-
- priorityQueue.add(new Obj(999, 1, "2023-07-01 16:00:01"));
- priorityQueue.add(new Obj(999, 2, "2023-07-01 16:00:01"));
- priorityQueue.add(new Obj(999, 3, "2023-07-01 16:00:01"));
-
- List<Obj> elements = new ArrayList<>(priorityQueue);
- elements.sort(priorityQueue.comparator()); // 浣跨敤闃熷垪鐨勬瘮杈冨櫒杩涜鎺掑簭
- for (Obj task : elements) {
- log.info("姝e湪鎺掗槦銆恜riority銆�" + task.getPriority() + "銆恘um銆�" + task.getNum() + "銆恆larmTime銆�" + task.getAlarmTime());
+ /**
+ * 闆疯揪寮曞鍏ラ槦
+ */
+ private void radarGuide(String radarId, String alarmpointName, String alarmType, Date createTime, double[] coordinate) {
+ String uuid = IdUtils.simpleUUID();
+ //鑾峰彇闆疯揪鎵�鍦ㄥ涓婄殑澶у厜鐢�
+ String cameraIdWithTower = ardAlarmRadarMapper.getCameraByRadar(radarId);
+ if (StringUtils.isNotNull(cameraIdWithTower) && StringUtils.isNotEmpty(cameraIdWithTower)) {
+ log.info("鑾峰彇鍒伴浄杈惧涓婄殑鍏夌數:" + cameraIdWithTower);
+ //濡傛灉闆疯揪濉斾笂鏈夊厜鐢�
+ messagesEnqueued(cameraIdWithTower, uuid, alarmType, createTime, 1, 1, coordinate);
}
- log.info("===================================================================");
- priorityQueue.add(new Obj(999, 5, "2023-07-01 16:00:01"));
- PriorityBlockingQueue queue = new PriorityBlockingQueue<>(priorityQueue);
- while (queue.size() > 0) {
- Obj task = (Obj) queue.poll();
- log.info("姝e湪鎺掗槦銆恜riority銆�" + task.getPriority() + "銆恘um銆�" + task.getNum() + "銆恆larmTime銆�" + task.getAlarmTime());
+ //鑾峰彇鎶ヨ鐐瑰叧鑱旂殑澶у厜鐢�
+ 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, createTime, 1, 2, coordinate);
}
}
- @Data
- @AllArgsConstructor
- static class Obj {
- Integer priority;
- Integer num;
- String alarmTime;
- }
}
--
Gitblit v1.9.3