From e7f5cfc422cb9ac8dc72f0c0faf063bf5fcb711c Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 06 五月 2022 17:26:36 +0800
Subject: [PATCH] test
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/NotifyRequestProcessor.java | 116 +++++++++++++++++++++++++++++++--------------------------
1 files changed, 63 insertions(+), 53 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 c3e434d..98cb3aa 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
@@ -1,22 +1,23 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
+import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.SipConfig;
-import com.genersoft.iot.vmp.conf.UserSetup;
+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;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
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.IVideoManagerStorager;
-import com.genersoft.iot.vmp.utils.GpsUtil;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import org.dom4j.DocumentException;
import org.dom4j.Element;
@@ -45,10 +46,13 @@
private final static Logger logger = LoggerFactory.getLogger(NotifyRequestProcessor.class);
@Autowired
- private UserSetup userSetup;
+ private UserSetting userSetting;
@Autowired
- private IVideoManagerStorager storager;
+ private IVideoManagerStorage storager;
+
+ @Autowired
+ private EventPublisher eventPublisher;
@Autowired
private SipConfig sipConfig;
@@ -59,12 +63,6 @@
@Autowired
private EventPublisher publisher;
- @Autowired
- private DeviceOffLineDetector offLineDetector;
-
- private static final String NOTIFY_CATALOG = "Catalog";
- private static final String NOTIFY_ALARM = "Alarm";
- private static final String NOTIFY_MOBILE_POSITION = "MobilePosition";
private String method = "NOTIFY";
@Autowired
@@ -82,13 +80,13 @@
Element rootElement = getRootElement(evt);
String cmd = XmlUtil.getText(rootElement, "CmdType");
- if (NOTIFY_CATALOG.equals(cmd)) {
+ if (CmdType.CATALOG.equals(cmd)) {
logger.info("鎺ユ敹鍒癈atalog閫氱煡");
processNotifyCatalogList(evt);
- } else if (NOTIFY_ALARM.equals(cmd)) {
+ } else if (CmdType.ALARM.equals(cmd)) {
logger.info("鎺ユ敹鍒癆larm閫氱煡");
processNotifyAlarm(evt);
- } else if (NOTIFY_MOBILE_POSITION.equals(cmd)) {
+ } else if (CmdType.MOBILE_POSITION.equals(cmd)) {
logger.info("鎺ユ敹鍒癕obilePosition閫氱煡");
processNotifyMobilePosition(evt);
} else {
@@ -107,11 +105,15 @@
*/
private void processNotifyMobilePosition(RequestEvent evt) {
try {
+ FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
+ String deviceId = SipUtils.getUserIdFromFromHeader(fromHeader);
+
// 鍥炲 200 OK
Element rootElement = getRootElement(evt);
+
MobilePosition mobilePosition = new MobilePosition();
Element deviceIdElement = rootElement.element("DeviceID");
- String deviceId = deviceIdElement.getTextTrim().toString();
+ String channelId = deviceIdElement.getTextTrim().toString();
Device device = redisCatchStorage.getDevice(deviceId);
if (device != null) {
if (!StringUtils.isEmpty(device.getName())) {
@@ -119,7 +121,9 @@
}
}
mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID"));
- mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
+ mobilePosition.setChannelId(channelId);
+ String time = XmlUtil.getText(rootElement, "Time");
+ mobilePosition.setTime(time);
mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
@@ -137,17 +141,31 @@
} else {
mobilePosition.setAltitude(0.0);
}
+ logger.info("[鏀跺埌 绉诲姩浣嶇疆璁㈤槄]锛歿}/{}->{}.{}", mobilePosition.getDeviceId(), mobilePosition.getChannelId(),
+ mobilePosition.getLongitude(), mobilePosition.getLatitude());
mobilePosition.setReportSource("Mobile Position");
- 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());
- if (!userSetup.getSavePositionHistory()) {
+ // 榛樿鏉ユ簮鍧愭爣绯讳负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);
}
storager.insertMobilePosition(mobilePosition);
+ storager.updateChannelPotion(deviceId, channelId, mobilePosition.getLongitude(), mobilePosition.getLatitude() );
+ // 鍙戦�乺edis娑堟伅銆� 閫氱煡浣嶇疆淇℃伅鐨勫彉鍖�
+ JSONObject jsonObject = new JSONObject();
+ jsonObject.put("time", time);
+ jsonObject.put("serial", deviceId);
+ jsonObject.put("code", channelId);
+ jsonObject.put("longitude", mobilePosition.getLongitude());
+ jsonObject.put("latitude", mobilePosition.getLatitude());
+ jsonObject.put("altitude", mobilePosition.getAltitude());
+ jsonObject.put("direction", mobilePosition.getDirection());
+ jsonObject.put("speed", mobilePosition.getSpeed());
+ redisCatchStorage.sendMobilePositionMsg(jsonObject);
responseAck(evt, Response.OK);
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
e.printStackTrace();
@@ -193,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());
@@ -201,13 +219,13 @@
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());
- if (!userSetup.getSavePositionHistory()) {
+ // 榛樿鏉ユ簮鍧愭爣绯讳负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);
}
storager.insertMobilePosition(mobilePosition);
@@ -216,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) {
@@ -259,41 +277,41 @@
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 "ON" : // 涓婄嚎
+ case CatalogEvent.ON: // 涓婄嚎
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戜笂绾块�氱煡", device.getDeviceId(), channel.getChannelId());
storager.deviceChannelOnline(deviceId, channel.getChannelId());
// 鍥炲200 OK
responseAck(evt, Response.OK);
break;
- case "OFF" : // 绂荤嚎
+ case CatalogEvent.OFF : // 绂荤嚎
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戠绾块�氱煡", device.getDeviceId(), channel.getChannelId());
storager.deviceChannelOffline(deviceId, channel.getChannelId());
// 鍥炲200 OK
responseAck(evt, Response.OK);
break;
- case "VLOST" : // 瑙嗛涓㈠け
+ case CatalogEvent.VLOST: // 瑙嗛涓㈠け
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑閫氶亾銆恵}銆戣棰戜涪澶遍�氱煡", device.getDeviceId(), channel.getChannelId());
storager.deviceChannelOffline(deviceId, channel.getChannelId());
// 鍥炲200 OK
responseAck(evt, Response.OK);
break;
- case "DEFECT" : // 鏁呴殰
+ case CatalogEvent.DEFECT: // 鏁呴殰
// 鍥炲200 OK
responseAck(evt, Response.OK);
break;
- case "ADD" : // 澧炲姞
+ case CatalogEvent.ADD: // 澧炲姞
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑澧炲姞閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
storager.updateChannel(deviceId, channel);
responseAck(evt, Response.OK);
break;
- case "DEL" : // 鍒犻櫎
+ case CatalogEvent.DEL: // 鍒犻櫎
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑鍒犻櫎閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
storager.delChannel(deviceId, channel.getChannelId());
responseAck(evt, Response.OK);
break;
- case "UPDATE" : // 鏇存柊
+ case CatalogEvent.UPDATE: // 鏇存柊
logger.info("鏀跺埌鏉ヨ嚜璁惧銆恵}銆戠殑鏇存柊閫氶亾銆恵}銆戦�氱煡", device.getDeviceId(), channel.getChannelId());
storager.updateChannel(deviceId, channel);
responseAck(evt, Response.OK);
@@ -302,16 +320,12 @@
responseAck(evt, Response.BAD_REQUEST, "event not found");
}
+ // 杞彂鍙樺寲淇℃伅
+ eventPublisher.catalogEventPublish(null, channel, eventElement.getText().toUpperCase());
}
- // RequestMessage msg = new RequestMessage();
- // msg.setDeviceId(deviceId);
- // msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
- // msg.setData(device);
- // deferredResultHolder.invokeResult(msg);
-
- if (offLineDetector.isOnline(deviceId)) {
+ if (!redisCatchStorage.deviceIsOnline(deviceId)) {
publisher.onlineEventPublish(device, VideoManagerConstants.EVENT_ONLINE_MESSAGE);
}
}
@@ -323,7 +337,7 @@
public void setCmder(SIPCommander cmder) {
}
- public void setStorager(IVideoManagerStorager storager) {
+ public void setStorager(IVideoManagerStorage storager) {
this.storager = storager;
}
@@ -335,10 +349,6 @@
}
public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
- }
-
- public void setOffLineDetector(DeviceOffLineDetector offLineDetector) {
- this.offLineDetector = offLineDetector;
}
public IRedisCatchStorage getRedisCatchStorage() {
--
Gitblit v1.8.0