From 62f716be9cd1cee2a5fba566db3fcd43bd9fc4cc Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 03 四月 2024 15:04:33 +0800
Subject: [PATCH] 添加idea logo
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java | 120 +++++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 95 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
old mode 100644
new mode 100755
index 56fa187..cd97786
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestForCatalogProcessor.java
@@ -1,6 +1,8 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
+import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.conf.DynamicTask;
+import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
@@ -11,6 +13,7 @@
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.service.IDeviceChannelService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.utils.DateUtil;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.slf4j.Logger;
@@ -20,7 +23,10 @@
import javax.sip.RequestEvent;
import javax.sip.header.FromHeader;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -56,6 +62,12 @@
@Autowired
private DynamicTask dynamicTask;
+ @Autowired
+ private CivilCodeFileConf civilCodeFileConf;
+
+ @Autowired
+ private SipConfig sipConfig;
+
private final static String talkKey = "notify-request-for-catalog-task";
public void process(RequestEvent evt) {
@@ -65,7 +77,7 @@
String deviceId = SipUtils.getUserIdFromFromHeader(fromHeader);
Device device = redisCatchStorage.getDevice(deviceId);
- if (device == null || device.getOnline() == 0) {
+ if (device == null || !device.isOnLine()) {
logger.warn("[鏀跺埌鐩綍璁㈤槄]锛歿}, 浣嗘槸璁惧宸茬粡绂荤嚎", (device != null ? device.getDeviceId():"" ));
return;
}
@@ -96,8 +108,14 @@
}else {
event = eventElement.getText().toUpperCase();
}
- DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event);
-
+ DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event);
+ if (channel == null) {
+ logger.info("[鏀跺埌鐩綍璁㈤槄]锛氫絾鏄В鏋愬け璐� {}", new String(evt.getRequest().getRawContent()));
+ continue;
+ }
+ if (channel.getParentId() != null && channel.getParentId().equals(sipConfig.getId())) {
+ channel.setParentId(null);
+ }
channel.setDeviceId(device.getDeviceId());
logger.info("[鏀跺埌鐩綍璁㈤槄]锛歿}/{}", device.getDeviceId(), channel.getChannelId());
switch (event) {
@@ -108,41 +126,58 @@
if (updateChannelOnlineList.size() > 300) {
executeSaveForOnline();
}
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), true);
+ }
+
break;
case CatalogEvent.OFF :
// 绂荤嚎
logger.info("[鏀跺埌閫氶亾绂荤嚎閫氱煡] 鏉ヨ嚜璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
+ logger.info("[鏀跺埌閫氶亾绂荤嚎閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ }else {
updateChannelOfflineList.add(channel);
if (updateChannelOfflineList.size() > 300) {
executeSaveForOffline();
}
- }else {
- logger.info("[鏀跺埌閫氶亾绂荤嚎閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
+ }
}
break;
case CatalogEvent.VLOST:
// 瑙嗛涓㈠け
logger.info("[鏀跺埌閫氶亾瑙嗛涓㈠け閫氱煡] 鏉ヨ嚜璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
+ logger.info("[鏀跺埌閫氶亾瑙嗛涓㈠け閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ }else {
updateChannelOfflineList.add(channel);
if (updateChannelOfflineList.size() > 300) {
executeSaveForOffline();
}
- }else {
- logger.info("[鏀跺埌閫氶亾瑙嗛涓㈠け閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
+ }
}
break;
case CatalogEvent.DEFECT:
// 鏁呴殰
logger.info("[鏀跺埌閫氶亾瑙嗛鏁呴殰閫氱煡] 鏉ヨ嚜璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
+ logger.info("[鏀跺埌閫氶亾瑙嗛鏁呴殰閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ }else {
updateChannelOfflineList.add(channel);
if (updateChannelOfflineList.size() > 300) {
executeSaveForOffline();
}
- }else {
- logger.info("[鏀跺埌閫氶亾瑙嗛鏁呴殰閫氱煡] 浣嗘槸骞冲彴宸查厤缃嫆缁濇娑堟伅锛屾潵鑷澶�: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false);
+ }
}
break;
case CatalogEvent.ADD:
@@ -151,6 +186,7 @@
// 鍒ゆ柇姝ら�氶亾鏄惁瀛樺湪
DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId, channel.getChannelId());
if (deviceChannel != null) {
+ logger.info("[澧炲姞閫氶亾] 宸插瓨鍦紝涓嶅彂閫侀�氱煡鍙洿鏂帮紝璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
channel.setId(deviceChannel.getId());
updateChannelMap.put(channel.getChannelId(), channel);
if (updateChannelMap.keySet().size() > 300) {
@@ -158,6 +194,11 @@
}
}else {
addChannelMap.put(channel.getChannelId(), channel);
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true);
+ }
+
if (addChannelMap.keySet().size() > 300) {
executeSaveForAdd();
}
@@ -168,6 +209,10 @@
// 鍒犻櫎
logger.info("[鏀跺埌鍒犻櫎閫氶亾閫氱煡] 鏉ヨ嚜璁惧: {}, 閫氶亾 {}", device.getDeviceId(), channel.getChannelId());
deleteChannelList.add(channel);
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), false);
+ }
if (deleteChannelList.size() > 300) {
executeSaveForDelete();
}
@@ -179,6 +224,7 @@
DeviceChannel deviceChannelForUpdate = deviceChannelService.getOne(deviceId, channel.getChannelId());
if (deviceChannelForUpdate != null) {
channel.setId(deviceChannelForUpdate.getId());
+ channel.setUpdateTime(DateUtil.getNow());
updateChannelMap.put(channel.getChannelId(), channel);
if (updateChannelMap.keySet().size() > 300) {
executeSaveForUpdate();
@@ -187,6 +233,10 @@
addChannelMap.put(channel.getChannelId(), channel);
if (addChannelMap.keySet().size() > 300) {
executeSaveForAdd();
+ }
+ if (userSetting.getDeviceStatusNotify()) {
+ // 鍙戦�乺edis娑堟伅
+ redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true);
}
}
break;
@@ -197,11 +247,11 @@
// 杞彂鍙樺寲淇℃伅
eventPublisher.catalogEventPublish(null, channel, event);
- if (updateChannelMap.keySet().size() > 0
- || addChannelMap.keySet().size() > 0
- || updateChannelOnlineList.size() > 0
- || updateChannelOfflineList.size() > 0
- || deleteChannelList.size() > 0) {
+ if (!updateChannelMap.keySet().isEmpty()
+ || !addChannelMap.keySet().isEmpty()
+ || !updateChannelOnlineList.isEmpty()
+ || !updateChannelOfflineList.isEmpty()
+ || !deleteChannelList.isEmpty()) {
if (!dynamicTask.contains(talkKey)) {
dynamicTask.startDelay(talkKey, this::executeSave, 1000);
@@ -215,16 +265,36 @@
}
private void executeSave(){
- System.out.println("瀹氭椂瀛樺偍鏁版嵁");
- executeSaveForUpdate();
- executeSaveForDelete();
- executeSaveForOnline();
- executeSaveForOffline();
+ try {
+ executeSaveForAdd();
+ } catch (Exception e) {
+ logger.error("[瀛樺偍鏀跺埌鐨勫鍔犻�氶亾] 寮傚父锛� ", e );
+ }
+ try {
+ executeSaveForUpdate();
+ } catch (Exception e) {
+ logger.error("[瀛樺偍鏀跺埌鐨勬洿鏂伴�氶亾] 寮傚父锛� ", e );
+ }
+ try {
+ executeSaveForDelete();
+ } catch (Exception e) {
+ logger.error("[瀛樺偍鏀跺埌鐨勫垹闄ら�氶亾] 寮傚父锛� ", e );
+ }
+ try {
+ executeSaveForOnline();
+ } catch (Exception e) {
+ logger.error("[瀛樺偍鏀跺埌鐨勯�氶亾涓婄嚎] 寮傚父锛� ", e );
+ }
+ try {
+ executeSaveForOffline();
+ } catch (Exception e) {
+ logger.error("[瀛樺偍鏀跺埌鐨勯�氶亾绂荤嚎] 寮傚父锛� ", e );
+ }
dynamicTask.stop(talkKey);
}
private void executeSaveForUpdate(){
- if (updateChannelMap.values().size() > 0) {
+ if (!updateChannelMap.values().isEmpty()) {
ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(updateChannelMap.values());
updateChannelMap.clear();
deviceChannelService.batchUpdateChannel(deviceChannels);
@@ -233,7 +303,7 @@
}
private void executeSaveForAdd(){
- if (addChannelMap.values().size() > 0) {
+ if (!addChannelMap.values().isEmpty()) {
ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(addChannelMap.values());
addChannelMap.clear();
deviceChannelService.batchAddChannel(deviceChannels);
@@ -241,21 +311,21 @@
}
private void executeSaveForDelete(){
- if (deleteChannelList.size() > 0) {
+ if (!deleteChannelList.isEmpty()) {
deviceChannelService.deleteChannels(deleteChannelList);
deleteChannelList.clear();
}
}
private void executeSaveForOnline(){
- if (updateChannelOnlineList.size() > 0) {
+ if (!updateChannelOnlineList.isEmpty()) {
deviceChannelService.channelsOnline(updateChannelOnlineList);
updateChannelOnlineList.clear();
}
}
private void executeSaveForOffline(){
- if (updateChannelOfflineList.size() > 0) {
+ if (!updateChannelOfflineList.isEmpty()) {
deviceChannelService.channelsOffline(updateChannelOfflineList);
updateChannelOfflineList.clear();
}
--
Gitblit v1.8.0