From f6893cf95b15531dfc45950fea7e780e045ba2ae Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 11 五月 2022 18:37:24 +0800
Subject: [PATCH] 优化设备在线状态

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java |   33 +++++++++++++++++----------------
 1 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
index 98cb3aa..e923a54 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java
@@ -252,14 +252,12 @@
 			FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
 			String deviceId = SipUtils.getUserIdFromFromHeader(fromHeader);
 
-			Element rootElement = getRootElement(evt);
 			Device device = redisCatchStorage.getDevice(deviceId);
-			if (device == null) {
+			if (device == null || device.getOnline() == 0) {
+				logger.warn("[鏀跺埌 鐩綍璁㈤槄]锛歿}, 浣嗘槸璁惧宸茬粡绂荤嚎", (device != null ? device.getDeviceId():"" ));
 				return;
 			}
-			if (device != null ) {
-				rootElement = getRootElement(evt, device.getCharset());
-			}
+			Element rootElement = getRootElement(evt, device.getCharset());
 			Element deviceListElement = rootElement.element("DeviceList");
 			if (deviceListElement == null) {
 				return;
@@ -279,39 +277,46 @@
 					channel.setDeviceId(device.getDeviceId());
 					logger.info("[鏀跺埌 鐩綍璁㈤槄]锛歿}/{}", device.getDeviceId(), channel.getChannelId());
 					switch (eventElement.getText().toUpperCase()) {
-						case CatalogEvent.ON: // 涓婄嚎
+						case CatalogEvent.ON:
+							// 涓婄嚎
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戜笂绾块�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.deviceChannelOnline(deviceId, channel.getChannelId());
 							// 鍥炲200 OK
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.OFF : // 绂荤嚎
+						case CatalogEvent.OFF :
+							// 绂荤嚎
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戠绾块�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.deviceChannelOffline(deviceId, channel.getChannelId());
 							// 鍥炲200 OK
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.VLOST: // 瑙嗛涓㈠け
+						case CatalogEvent.VLOST:
+							// 瑙嗛涓㈠け
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戣棰戜涪澶遍�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.deviceChannelOffline(deviceId, channel.getChannelId());
 							// 鍥炲200 OK
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.DEFECT: // 鏁呴殰
+						case CatalogEvent.DEFECT:
+							// 鏁呴殰
 							// 鍥炲200 OK
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.ADD: // 澧炲姞
+						case CatalogEvent.ADD:
+							// 澧炲姞
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑澧炲姞閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.updateChannel(deviceId, channel);
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.DEL: // 鍒犻櫎
+						case CatalogEvent.DEL:
+							// 鍒犻櫎
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑鍒犻櫎閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.delChannel(deviceId, channel.getChannelId());
 							responseAck(evt, Response.OK);
 							break;
-						case CatalogEvent.UPDATE: // 鏇存柊
+						case CatalogEvent.UPDATE:
+							// 鏇存柊
 							logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑鏇存柊閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
 							storager.updateChannel(deviceId, channel);
 							responseAck(evt, Response.OK);
@@ -323,10 +328,6 @@
 					// 杞彂鍙樺寲淇℃伅
 					eventPublisher.catalogEventPublish(null, channel, eventElement.getText().toUpperCase());
 
-				}
-
-				if (!redisCatchStorage.deviceIsOnline(deviceId)) {
-					publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
 				}
 			}
 		} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {

--
Gitblit v1.8.0