From d739bfa5976e36ced26f906ab16f83c20c8cb27c Mon Sep 17 00:00:00 2001
From: xiaoxie <hotcoffie@163.com>
Date: 星期一, 23 五月 2022 09:44:21 +0800
Subject: [PATCH] 处理冲突

---
 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java |   75 +++++++++++++++++--------------------
 1 files changed, 35 insertions(+), 40 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 1270202..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
@@ -5,7 +5,6 @@
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
-import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
 import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
 import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
 import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
@@ -13,12 +12,12 @@
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor;
 import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
+import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
 import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
 import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
 import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
-import com.genersoft.iot.vmp.utils.GpsUtil;
 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
 import org.dom4j.DocumentException;
 import org.dom4j.Element;
@@ -63,10 +62,6 @@
 
 	@Autowired
 	private EventPublisher publisher;
-
-	@Autowired
-	private DeviceOffLineDetector offLineDetector;
-
 
 	private String method = "NOTIFY";
 
@@ -146,12 +141,15 @@
 			} else {
 				mobilePosition.setAltitude(0.0);
 			}
+			logger.info("[鏀跺埌 绉诲姩浣嶇疆璁㈤槄]锛歿}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(),
+					mobilePosition.getLongitude(), mobilePosition.getLatitude());
 			mobilePosition.setReportSource("Mobile Position");
-			BaiduPoint bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
-			logger.info("鐧惧害鍧愭爣锛�" + bp.getBdLng() + ", " + bp.getBdLat());
-			mobilePosition.setGeodeticSystem("BD-09");
-			mobilePosition.setCnLng(bp.getBdLng());
-			mobilePosition.setCnLat(bp.getBdLat());
+			// 榛樿鏉ユ簮鍧愭爣绯讳负WGS-84澶勭悊
+			Double[] gcj02Point = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());
+			logger.info("GCJ02鍧愭爣锛�" + gcj02Point[0] + ", " + gcj02Point[1]);
+			mobilePosition.setGeodeticSystem("GCJ-02");
+			mobilePosition.setCnLng(gcj02Point[0] + "");
+			mobilePosition.setCnLat(gcj02Point[1] + "");
 			if (!userSetting.getSavePositionHistory()) {
 				storager.clearMobilePositionsByDeviceId(deviceId);
 			}
@@ -213,7 +211,7 @@
 			} else {
 				deviceAlarm.setLatitude(0.00);
 			}
-
+			logger.info("[鏀跺埌Notify-Alarm]锛歿}/{}", device.getDeviceId(), deviceAlarm.getChannelId());
 			if (deviceAlarm.getAlarmMethod().equals("4")) {
 				MobilePosition mobilePosition = new MobilePosition();
 				mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
@@ -221,12 +219,12 @@
 				mobilePosition.setLongitude(deviceAlarm.getLongitude());
 				mobilePosition.setLatitude(deviceAlarm.getLatitude());
 				mobilePosition.setReportSource("GPS Alarm");
-				BaiduPoint bp = new BaiduPoint();
-				bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
-				logger.info("鐧惧害鍧愭爣锛�" + bp.getBdLng() + ", " + bp.getBdLat());
-				mobilePosition.setGeodeticSystem("BD-09");
-				mobilePosition.setCnLng(bp.getBdLng());
-				mobilePosition.setCnLat(bp.getBdLat());
+				// 榛樿鏉ユ簮鍧愭爣绯讳负WGS-84澶勭悊
+				Double[] gcj02Point = Coordtransform.WGS84ToGCJ02(mobilePosition.getLongitude(), mobilePosition.getLatitude());
+				logger.info("GCJ02鍧愭爣锛�" + gcj02Point[0] + ", " + gcj02Point[1]);
+				mobilePosition.setGeodeticSystem("GCJ-02");
+				mobilePosition.setCnLng(gcj02Point[0] + "");
+				mobilePosition.setCnLat(gcj02Point[1] + "");
 				if (!userSetting.getSavePositionHistory()) {
 					storager.clearMobilePositionsByDeviceId(deviceId);
 				}
@@ -236,7 +234,7 @@
 
 			// 鍥炲200 OK
 			responseAck(evt, Response.OK);
-			if (offLineDetector.isOnline(deviceId)) {
+			if (redisCatchStorage.deviceIsOnline(deviceId)) {
 				publisher.deviceAlarmEventPublish(deviceAlarm);
 			}
 		} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
@@ -254,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,41 +275,48 @@
 					Element eventElement = itemDevice.element("Event");
 					DeviceChannel channel = XmlUtil.channelContentHander(itemDevice);
 					channel.setDeviceId(device.getDeviceId());
-					logger.debug("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾: {}銆恵}銆�", device.getDeviceId(), channel.getName(), channel.getChannelId());
+					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);
@@ -325,10 +328,6 @@
 					// 杞彂鍙樺寲淇℃伅
 					eventPublisher.catalogEventPublish(null, channel, eventElement.getText().toUpperCase());
 
-				}
-
-				if (offLineDetector.isOnline(deviceId)) {
-					publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
 				}
 			}
 		} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
@@ -351,10 +350,6 @@
 	}
 
 	public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
-	}
-
-	public void setOffLineDetector(DeviceOffLineDetector offLineDetector) {
-		this.offLineDetector = offLineDetector;
 	}
 
 	public IRedisCatchStorage getRedisCatchStorage() {

--
Gitblit v1.8.0