diff --git a/README.md b/README.md
index aec9555c..ee030127 100644
--- a/README.md
+++ b/README.md
@@ -128,6 +128,8 @@ https://gitee.com/pan648540858/wvp-GB28181-pro.git
QQ群: 901799015, ZLM使用文档[https://github.com/ZLMediaKit/ZLMediaKit](https://github.com/ZLMediaKit/ZLMediaKit)
QQ私信一般不回, 精力有限.欢迎大家在群里讨论.觉得项目对你有帮助,欢迎star和提交pr。
+# 授权协议
+本项目自有代码使用宽松的MIT协议,在保留版权信息的情况下可以自由应用于各自商用、非商业的项目。 但是本项目也零碎的使用了一些其他的开源代码,在商用的情况下请自行替代或剔除; 由于使用本项目而产生的商业纠纷或侵权行为一概与本项目及开发者无关,请自行承担法律风险。 在使用本项目代码时,也应该在授权协议中同时表明本项目依赖的第三方库的协议
# 致谢
感谢作者[夏楚](https://github.com/xia-chu) 提供这么棒的开源流媒体服务框架,并在开发过程中给予支持与帮助。
diff --git a/pom.xml b/pom.xml
index befb74f0..34a07e18 100644
--- a/pom.xml
+++ b/pom.xml
@@ -11,7 +11,7 @@
com.genersoft
wvp-pro
- 2.1.1
+ 2.2.1
web video platform
国标28181视频平台
diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
index e1d7c495..ef4492f8 100644
--- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
+++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
@@ -87,9 +87,12 @@ public class VideoManagerConstants {
// 移动位置订阅通知
public static final String VM_MSG_SUBSCRIBE_MOBILE_POSITION = "mobileposition";
- // 报警订阅的通知
+ // 报警订阅的通知(收到报警向redis发出通知)
public static final String VM_MSG_SUBSCRIBE_ALARM = "alarm";
+ // 报警通知的发送 (收到redis发出的通知,转发给其他平台)
+ public static final String VM_MSG_SUBSCRIBE_ALARM_RECEIVE= "alarm_receive";
+
// 设备状态订阅的通知
public static final String VM_MSG_SUBSCRIBE_DEVICE_STATUS = "device";
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
index d46a8ea9..6b45eb5d 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/RedisConfig.java
@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.conf;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
+import com.genersoft.iot.vmp.service.impl.RedisAlarmMsgListener;
import com.genersoft.iot.vmp.service.impl.RedisGPSMsgListener;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -48,6 +49,9 @@ public class RedisConfig extends CachingConfigurerSupport {
@Autowired
private RedisGPSMsgListener redisGPSMsgListener;
+ @Autowired
+ private RedisAlarmMsgListener redisAlarmMsgListener;
+
@Bean
public JedisPool jedisPool() {
if (StringUtils.isBlank(password)) {
@@ -93,6 +97,7 @@ public class RedisConfig extends CachingConfigurerSupport {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.addMessageListener(redisGPSMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_GPS));
+ container.addMessageListener(redisAlarmMsgListener, new PatternTopic(VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM_RECEIVE));
return container;
}
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
index 6fa802da..bbc946bf 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/SipConfig.java
@@ -29,7 +29,7 @@ public class SipConfig {
Integer registerTimeInterval = 120;
- private boolean alarm = false;
+ private boolean alarm;
public void setIp(String ip) {
this.ip = ip;
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AlarmChannelMessage.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AlarmChannelMessage.java
new file mode 100644
index 00000000..96d25c4e
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AlarmChannelMessage.java
@@ -0,0 +1,46 @@
+package com.genersoft.iot.vmp.gb28181.bean;
+
+/**
+ * 通过redis分发报警消息
+ */
+public class AlarmChannelMessage {
+ /**
+ * 国标编号
+ */
+ private String gbId;
+
+ /**
+ * 报警编号
+ */
+ private int alarmSn;
+
+
+ /**
+ * 报警描述
+ */
+ private String alarmDescription;
+
+ public String getGbId() {
+ return gbId;
+ }
+
+ public void setGbId(String gbId) {
+ this.gbId = gbId;
+ }
+
+ public int getAlarmSn() {
+ return alarmSn;
+ }
+
+ public void setAlarmSn(int alarmSn) {
+ this.alarmSn = alarmSn;
+ }
+
+ public String getAlarmDescription() {
+ return alarmDescription;
+ }
+
+ public void setAlarmDescription(String alarmDescription) {
+ this.alarmDescription = alarmDescription;
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
index 8176c1c9..530bce2d 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
@@ -50,7 +50,30 @@ public class DeviceAlarm {
private double latitude;
/**
- * 报警类型
+ * 报警类型,
+ * 报警方式为2时,不携带 AlarmType为默认的报警设备报警,
+ * 携带 AlarmType取值及对应报警类型如下:
+ * 1-视频丢失报警;
+ * 2-设备防拆报警;
+ * 3-存储设备磁盘满报警;
+ * 4-设备高温报警;
+ * 5-设备低温报警。
+ * 报警方式为5时,取值如下:
+ * 1-人工视频报警;
+ * 2-运动目标检测报警;
+ * 3-遗留物检测报警;
+ * 4-物体移除检测报警;
+ * 5-绊线检测报警;
+ * 6-入侵检测报警;
+ * 7-逆行检测报警;
+ * 8-徘徊检测报警;
+ * 9-流量统计报警;
+ * 10-密度检测报警;
+ * 11-视频异常检测报警;
+ * 12-快速移动报警。
+ * 报警方式为6时,取值下:
+ * 1-存储设备磁盘故障报警;
+ * 2-存储设备风扇故障报警。
*/
private String alarmType;
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
index 1e6ef773..95576f38 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceChannel.java
@@ -4,7 +4,7 @@ public class DeviceChannel {
/**
- * 数据库自赠ID
+ * 数据库自增ID
*/
private int id;
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeInfo.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeInfo.java
index feb6a724..1958b449 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeInfo.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeInfo.java
@@ -25,6 +25,9 @@ public class SubscribeInfo {
this.callId = callIdHeader.getCallId();
}
+ public SubscribeInfo() {
+ }
+
private String id;
private int expires;
private String callId;
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
index e0e4a270..ef78d371 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/KeepaliveTimeoutListenerForPlatform.java
@@ -52,7 +52,6 @@ public class KeepaliveTimeoutListenerForPlatform extends RedisKeyExpirationEvent
public void onMessage(Message message, byte[] pattern) {
// 获取失效的key
String expiredKey = message.toString();
- logger.debug(expiredKey);
// 平台心跳到期,需要重发, 判断是否已经多次未收到心跳回复, 多次未收到,则重新发起注册, 注册尝试多次未得到回复,则认为平台离线
String PLATFORM_KEEPLIVEKEY_PREFIX = VideoManagerConstants.PLATFORM_KEEPALIVE_PREFIX + userSetting.getServerId() + "_";
String PLATFORM_REGISTER_PREFIX = VideoManagerConstants.PLATFORM_REGISTER_PREFIX + userSetting.getServerId() + "_";
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
index b7992e4d..46332566 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/offline/OfflineEventListener.java
@@ -57,10 +57,8 @@ public class OfflineEventListener implements ApplicationListener {
@Override
public void onApplicationEvent(OfflineEvent event) {
-
- if (logger.isDebugEnabled()) {
- logger.debug("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom());
- }
+
+ logger.info("设备离线事件触发,deviceId:" + event.getDeviceId() + ",from:" + event.getFrom());
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDeviceId();
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
index b97457a2..1fc1e469 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/online/OnlineEventListener.java
@@ -59,10 +59,8 @@ public class OnlineEventListener implements ApplicationListener {
@Override
public void onApplicationEvent(OnlineEvent event) {
-
- if (logger.isDebugEnabled()) {
- logger.debug("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom());
- }
+
+ logger.info("设备上线事件触发,deviceId:" + event.getDevice().getDeviceId() + ",from:" + event.getFrom());
Device device = event.getDevice();
if (device == null) return;
String key = VideoManagerConstants.KEEPLIVEKEY_PREFIX + userSetting.getServerId() + "_" + event.getDevice().getDeviceId();
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java
index b2eb7ead..4965026d 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/record/RecordEndEventListener.java
@@ -31,10 +31,8 @@ public class RecordEndEventListener implements ApplicationListener handlerMap = new HashMap<>();
@Override
public void onApplicationEvent(RecordEndEvent event) {
- if (logger.isDebugEnabled()) {
- logger.debug("录像查询完成事件触发,deviceId:{}, channelId: {}, 录像数量{}条", event.getRecordInfo().getDeviceId(),
- event.getRecordInfo().getChannelId(), event.getRecordInfo().getSumNum() );
- }
+ logger.info("录像查询完成事件触发,deviceId:{}, channelId: {}, 录像数量{}条", event.getRecordInfo().getDeviceId(),
+ event.getRecordInfo().getChannelId(), event.getRecordInfo().getSumNum() );
if (handlerMap.size() > 0) {
for (RecordEndEventHandler recordEndEventHandler : handlerMap.values()) {
recordEndEventHandler.handler(event.getRecordInfo());
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
index f9ef10cd..019baf94 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java
@@ -64,7 +64,7 @@ public class CatalogEventLister implements ApplicationListener {
subscribe = subscribeHolder.getCatalogSubscribe(event.getPlatformId());
if (subscribe == null) {
- logger.debug("发送订阅消息时发现订阅信息已经不存在");
+ logger.info("发送订阅消息时发现订阅信息已经不存在");
return;
}
}else {
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
index aea37b6c..a8fae0fb 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
@@ -1,8 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
import com.genersoft.iot.vmp.common.StreamInfo;
-import com.genersoft.iot.vmp.gb28181.bean.Device;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
@@ -336,4 +335,13 @@ public interface ISIPCommander {
* @param cmdString 前端控制指令串
*/
boolean dragZoomCmd(Device device, String channelId, String cmdString);
+
+
+ /**
+ * 向设备发送报警NOTIFY消息, 用于互联结构下,此时将设备当成一个平级平台看待
+ * @param device 设备
+ * @param deviceAlarm 报警信息信息
+ * @return
+ */
+ boolean sendAlarmMessage(Device device, DeviceAlarm deviceAlarm);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
index a900819c..7007e5a6 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java
@@ -1,9 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
-import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
-import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
@@ -75,6 +72,14 @@ public interface ISIPCommanderForPlatform {
*/
boolean sendNotifyMobilePosition(ParentPlatform parentPlatform, GPSMsgInfo gpsMsgInfo, SubscribeInfo subscribeInfo);
+ /**
+ * 向上级回复报警消息
+ * @param parentPlatform 平台信息
+ * @param deviceAlarm 报警信息信息
+ * @return
+ */
+ boolean sendAlarmMessage(ParentPlatform parentPlatform, DeviceAlarm deviceAlarm);
+
/**
* 回复catalog事件-增加/更新
* @param parentPlatform
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
index 89e70d0a..3fcf2fb2 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
@@ -5,10 +5,7 @@ import com.genersoft.iot.vmp.common.StreamInfo;
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.InviteStreamCallback;
-import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo;
-import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
+import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
@@ -23,6 +20,7 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import gov.nist.javax.sip.SipProviderImpl;
import gov.nist.javax.sip.SipStackImpl;
+import gov.nist.javax.sip.message.MessageFactoryImpl;
import gov.nist.javax.sip.message.SIPRequest;
import gov.nist.javax.sip.stack.SIPDialog;
import org.slf4j.Logger;
@@ -35,10 +33,7 @@ import org.springframework.util.StringUtils;
import javax.sip.*;
import javax.sip.address.SipURI;
-import javax.sip.header.CallIdHeader;
-import javax.sip.header.ContentTypeHeader;
-import javax.sip.header.ExpiresHeader;
-import javax.sip.header.ViaHeader;
+import javax.sip.header.*;
import javax.sip.message.Request;
import java.lang.reflect.Field;
import java.text.ParseException;
@@ -1777,4 +1772,101 @@ public class SIPCommander implements ISIPCommander {
e.printStackTrace();
}
}
+
+ @Override
+ public boolean sendAlarmMessage(Device device, DeviceAlarm deviceAlarm) {
+ if (device == null) {
+ return false;
+ }
+ logger.info("[发送 报警通知] {}/{}->{},{}", device.getDeviceId(), deviceAlarm.getChannelId(),
+ deviceAlarm.getLongitude(), deviceAlarm.getLatitude());
+ try {
+ String characterSet = device.getCharset();
+ StringBuffer deviceStatusXml = new StringBuffer(600);
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("Alarm\r\n");
+ deviceStatusXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getChannelId() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmPriority() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmMethod() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmTime() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmDescription() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getLongitude() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getLatitude() + "\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmType() + "\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("\r\n");
+
+ CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProvider.createMessageRequest(device, deviceStatusXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
+ transmitRequest(device, request);
+
+
+ } catch (SipException | ParseException e) {
+ e.printStackTrace();
+ return false;
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+
+ private void sendNotify(Device device, String catalogXmlContent,
+ SubscribeInfo subscribeInfo, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent )
+ throws NoSuchFieldException, IllegalAccessException, SipException, ParseException {
+ MessageFactoryImpl messageFactory = (MessageFactoryImpl) sipFactory.createMessageFactory();
+ String characterSet = device.getCharset();
+ // 设置编码, 防止中文乱码
+ messageFactory.setDefaultContentEncodingCharset(characterSet);
+ Dialog dialog = subscribeInfo.getDialog();
+ if (dialog == null || !dialog.getState().equals(DialogState.CONFIRMED)) return;
+ SIPRequest notifyRequest = (SIPRequest)dialog.createRequest(Request.NOTIFY);
+ ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
+ notifyRequest.setContent(catalogXmlContent, contentTypeHeader);
+
+ SubscriptionStateHeader subscriptionState = sipFactory.createHeaderFactory()
+ .createSubscriptionStateHeader(SubscriptionStateHeader.ACTIVE);
+ notifyRequest.addHeader(subscriptionState);
+
+ EventHeader event = sipFactory.createHeaderFactory().createEventHeader(subscribeInfo.getEventType());
+ if (subscribeInfo.getEventId() != null) {
+ event.setEventId(subscribeInfo.getEventId());
+ }
+ notifyRequest.addHeader(event);
+
+ SipURI sipURI = (SipURI) notifyRequest.getRequestURI();
+ if (subscribeInfo.getTransaction() != null) {
+ SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
+ sipURI.setHost(request.getRemoteAddress().getHostAddress());
+ sipURI.setPort(request.getRemotePort());
+ }else {
+ sipURI.setHost(device.getIp());
+ sipURI.setPort(device.getPort());
+ }
+
+ ClientTransaction transaction = null;
+ if ("TCP".equals(device.getTransport())) {
+ transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
+ } else if ("UDP".equals(device.getTransport())) {
+ transaction = udpSipProvider.getNewClientTransaction(notifyRequest);
+ }
+ // 添加错误订阅
+ if (errorEvent != null) {
+ sipSubscribe.addErrorSubscribe(subscribeInfo.getCallId(), errorEvent);
+ }
+ // 添加订阅
+ if (okEvent != null) {
+ sipSubscribe.addOkSubscribe(subscribeInfo.getCallId(), okEvent);
+ }
+ if (transaction == null) {
+ logger.error("平台{}的Transport错误:{}",device.getDeviceId(), device.getTransport());
+ return;
+ }
+ dialog.sendRequest(transaction);
+
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
index 0fd8cc50..66af757c 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
@@ -435,6 +435,48 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
return true;
}
+ @Override
+ public boolean sendAlarmMessage(ParentPlatform parentPlatform, DeviceAlarm deviceAlarm) {
+ if (parentPlatform == null) {
+ return false;
+ }
+ logger.info("[发送 报警订阅] {}/{}->{},{}", parentPlatform.getServerGBId(), deviceAlarm.getChannelId(),
+ deviceAlarm.getLongitude(), deviceAlarm.getLatitude());
+ try {
+ String characterSet = parentPlatform.getCharacterSet();
+ StringBuffer deviceStatusXml = new StringBuffer(600);
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("Alarm\r\n");
+ deviceStatusXml.append("" + (int)((Math.random()*9+1)*100000) + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getChannelId() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmPriority() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmMethod() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmTime() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmDescription() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getLongitude() + "\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getLatitude() + "\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("" + deviceAlarm.getAlarmType() + "\r\n");
+ deviceStatusXml.append("\r\n");
+ deviceStatusXml.append("\r\n");
+
+ CallIdHeader callIdHeader = parentPlatform.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
+ : udpSipProvider.getNewCallId();
+
+ String tm = Long.toString(System.currentTimeMillis());
+ Request request = headerProviderPlarformProvider.createMessageRequest(parentPlatform, deviceStatusXml.toString(), "FromPtz" + tm, callIdHeader);
+ transmitRequest(parentPlatform, request);
+
+ } catch (SipException | ParseException e) {
+ e.printStackTrace();
+ return false;
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ }
+ return true;
+ }
+
@Override
public boolean sendNotifyForCatalogAddOrUpdate(String type, ParentPlatform parentPlatform, List deviceChannels, SubscribeInfo subscribeInfo, Integer index) {
if (parentPlatform == null || deviceChannels == null || deviceChannels.size() == 0 || subscribeInfo == null) {
@@ -495,11 +537,16 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
event.setEventId(subscribeInfo.getEventId());
}
notifyRequest.addHeader(event);
-
SipURI sipURI = (SipURI) notifyRequest.getRequestURI();
- SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
- sipURI.setHost(request.getRemoteAddress().getHostAddress());
- sipURI.setPort(request.getRemotePort());
+ if (subscribeInfo.getTransaction() != null) {
+ SIPRequest request = (SIPRequest) subscribeInfo.getTransaction().getRequest();
+ sipURI.setHost(request.getRemoteAddress().getHostAddress());
+ sipURI.setPort(request.getRemotePort());
+ }else {
+ sipURI.setHost(parentPlatform.getServerIP());
+ sipURI.setPort(parentPlatform.getServerPort());
+ }
+
ClientTransaction transaction = null;
if ("TCP".equals(parentPlatform.getTransport())) {
transaction = tcpSipProvider.getNewClientTransaction(notifyRequest);
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 8e03510e..420f899d 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
@@ -13,6 +13,7 @@ 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;
@@ -149,11 +150,12 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
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);
}
@@ -223,12 +225,12 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
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);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
index 302ceda1..e5d7aa07 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/AlarmNotifyMessageHandler.java
@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.cmd;
+import com.alibaba.fastjson.JSON;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -8,8 +9,10 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
+import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.GpsUtil;
import org.dom4j.Element;
@@ -20,7 +23,12 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
+import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
+import javax.sip.SipException;
+import javax.sip.message.Response;
+
+import java.text.ParseException;
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.*;
@@ -45,6 +53,9 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
@Autowired
private IVideoManagerStorage storager;
+ @Autowired
+ private IRedisCatchStorage redisCatchStorage;
+
@Autowired
private IDeviceAlarmService deviceAlarmService;
@@ -58,11 +69,22 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
@Override
public void handForDevice(RequestEvent evt, Device device, Element rootElement) {
- if (!sipConfig.isAlarm()) {
- return;
+ logger.info("收到来自设备[{}]的报警通知", device.getDeviceId());
+ // 回复200 OK
+ try {
+ responseAck(evt, Response.OK);
+ } catch (SipException e) {
+ throw new RuntimeException(e);
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
}
+
Element deviceIdElement = rootElement.element("DeviceID");
String channelId = deviceIdElement.getText().toString();
+
+
DeviceAlarm deviceAlarm = new DeviceAlarm();
deviceAlarm.setDeviceId(device.getDeviceId());
deviceAlarm.setChannelId(channelId);
@@ -93,12 +115,12 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
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(device.getDeviceId());
}
@@ -110,9 +132,24 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
}
}
+
+ if (channelId.equals(sipConfig.getId())) {
+ // 发送给平台的报警信息。 发送redis通知
+ AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage();
+ alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod()));
+ alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription());
+ alarmChannelMessage.setGbId(channelId);
+ redisCatchStorage.sendAlarmMsg(alarmChannelMessage);
+
+ return;
+ }
+
logger.debug("存储报警信息、报警分类");
// 存储报警信息、报警分类
- deviceAlarmService.add(deviceAlarm);
+ if (sipConfig.isAlarm()) {
+ deviceAlarmService.add(deviceAlarm);
+ }
+
if (offLineDetector.isOnline(device.getDeviceId())) {
publisher.deviceAlarmEventPublish(deviceAlarm);
@@ -120,7 +157,59 @@ public class AlarmNotifyMessageHandler extends SIPRequestProcessorParent impleme
}
@Override
- public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element element) {
+ public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) {
+ logger.info("收到来自平台[{}]的报警通知", parentPlatform.getServerGBId());
+ // 回复200 OK
+ try {
+ responseAck(evt, Response.OK);
+ } catch (SipException e) {
+ throw new RuntimeException(e);
+ } catch (InvalidArgumentException e) {
+ throw new RuntimeException(e);
+ } catch (ParseException e) {
+ throw new RuntimeException(e);
+ }
+ Element deviceIdElement = rootElement.element("DeviceID");
+ String channelId = deviceIdElement.getText().toString();
+
+
+ DeviceAlarm deviceAlarm = new DeviceAlarm();
+ deviceAlarm.setDeviceId(parentPlatform.getServerGBId());
+ deviceAlarm.setChannelId(channelId);
+ deviceAlarm.setAlarmPriority(getText(rootElement, "AlarmPriority"));
+ deviceAlarm.setAlarmMethod(getText(rootElement, "AlarmMethod"));
+ deviceAlarm.setAlarmTime(getText(rootElement, "AlarmTime"));
+ if (getText(rootElement, "AlarmDescription") == null) {
+ deviceAlarm.setAlarmDescription("");
+ } else {
+ deviceAlarm.setAlarmDescription(getText(rootElement, "AlarmDescription"));
+ }
+ if (NumericUtil.isDouble(getText(rootElement, "Longitude"))) {
+ deviceAlarm.setLongitude(Double.parseDouble(getText(rootElement, "Longitude")));
+ } else {
+ deviceAlarm.setLongitude(0.00);
+ }
+ if (NumericUtil.isDouble(getText(rootElement, "Latitude"))) {
+ deviceAlarm.setLatitude(Double.parseDouble(getText(rootElement, "Latitude")));
+ } else {
+ deviceAlarm.setLatitude(0.00);
+ }
+
+ if (!StringUtils.isEmpty(deviceAlarm.getAlarmMethod())) {
+
+ if (deviceAlarm.getAlarmMethod().equals("5")) {
+ deviceAlarm.setAlarmType(getText(rootElement.element("Info"), "AlarmType"));
+ }
+ }
+ if (channelId.equals(parentPlatform.getDeviceGBId())) {
+ // 发送给平台的报警信息。 发送redis通知
+ AlarmChannelMessage alarmChannelMessage = new AlarmChannelMessage();
+ alarmChannelMessage.setAlarmSn(Integer.parseInt(deviceAlarm.getAlarmMethod()));
+ alarmChannelMessage.setAlarmDescription(deviceAlarm.getAlarmDescription());
+ alarmChannelMessage.setGbId(channelId);
+ redisCatchStorage.sendAlarmMsg(alarmChannelMessage);
+ return;
+ }
}
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
index 471b2d7e..2a53a3fb 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MobilePositionNotifyMessageHandler.java
@@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.notify.NotifyMessageHandler;
+import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.GpsUtil;
@@ -79,12 +80,12 @@ public class MobilePositionNotifyMessageHandler extends SIPRequestProcessorParen
mobilePosition.setAltitude(0.0);
}
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());
+ // 默认来源坐标系为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(device.getDeviceId());
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
index 92d0114d..910524dc 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
@@ -12,6 +12,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
+import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -199,12 +200,12 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
mobilePosition.setAltitude(0.0);
}
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());
+ // 默认来源坐标系为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);
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
index dca28660..b070ed52 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/MobilePositionResponseMessageHandler.java
@@ -8,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
+import com.genersoft.iot.vmp.gb28181.utils.Coordtransform;
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.GpsUtil;
@@ -79,12 +80,12 @@ public class MobilePositionResponseMessageHandler extends SIPRequestProcessorPar
mobilePosition.setAltitude(0.0);
}
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());
+ // 默认来源坐标系为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(device.getDeviceId());
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/Coordtransform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/Coordtransform.java
new file mode 100644
index 00000000..5c12ff6c
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/Coordtransform.java
@@ -0,0 +1,126 @@
+package com.genersoft.iot.vmp.gb28181.utils;
+
+/**
+ * 坐标转换
+ * 一个提供了百度坐标(BD09)、国测局坐标(火星坐标,GCJ02)、和WGS84坐标系之间的转换的工具类
+ * 参考https://github.com/wandergis/coordtransform 写的Java版本
+ * @author Xinconan
+ * @date 2016-03-18
+ * @url https://github.com/xinconan/coordtransform
+ */
+public class Coordtransform {
+
+ private static double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
+ private static double PI = 3.1415926535897932384626;
+ private static double a = 6378245.0;
+ private static double ee = 0.00669342162296594323;
+
+ /**
+ * 百度坐标系 (BD-09) 与 火星坐标系 (GCJ-02)的转换
+ * 即 百度 转 谷歌、高德
+ * @param bd_lon
+ * @param bd_lat
+ * @return Double[lon,lat]
+ */
+ public static Double[] BD09ToGCJ02(Double bd_lon,Double bd_lat){
+ double x = bd_lon - 0.0065;
+ double y = bd_lat - 0.006;
+ double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
+ double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
+ Double[] arr = new Double[2];
+ arr[0] = z * Math.cos(theta);
+ arr[1] = z * Math.sin(theta);
+ return arr;
+ }
+
+ /**
+ * 火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换
+ * 即谷歌、高德 转 百度
+ * @param gcj_lon
+ * @param gcj_lat
+ * @return Double[lon,lat]
+ */
+ public static Double[] GCJ02ToBD09(Double gcj_lon,Double gcj_lat){
+ double z = Math.sqrt(gcj_lon * gcj_lon + gcj_lat * gcj_lat) + 0.00002 * Math.sin(gcj_lat * x_PI);
+ double theta = Math.atan2(gcj_lat, gcj_lon) + 0.000003 * Math.cos(gcj_lon * x_PI);
+ Double[] arr = new Double[2];
+ arr[0] = z * Math.cos(theta) + 0.0065;
+ arr[1] = z * Math.sin(theta) + 0.006;
+ return arr;
+ }
+
+ /**
+ * WGS84转GCJ02
+ * @param wgs_lon
+ * @param wgs_lat
+ * @return Double[lon,lat]
+ */
+ public static Double[] WGS84ToGCJ02(Double wgs_lon,Double wgs_lat){
+ if(outOfChina(wgs_lon, wgs_lat)){
+ return new Double[]{wgs_lon,wgs_lat};
+ }
+ double dlat = transformlat(wgs_lon - 105.0, wgs_lat - 35.0);
+ double dlng = transformlng(wgs_lon - 105.0, wgs_lat - 35.0);
+ double radlat = wgs_lat / 180.0 * PI;
+ double magic = Math.sin(radlat);
+ magic = 1 - ee * magic * magic;
+ double sqrtmagic = Math.sqrt(magic);
+ dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
+ dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
+ Double[] arr = new Double[2];
+ arr[0] = wgs_lon + dlng;
+ arr[1] = wgs_lat + dlat;
+ return arr;
+ }
+
+ /**
+ * GCJ02转WGS84
+ * @param gcj_lon
+ * @param gcj_lat
+ * @return Double[lon,lat]
+ */
+ public static Double[] GCJ02ToWGS84(Double gcj_lon,Double gcj_lat){
+ if(outOfChina(gcj_lon, gcj_lat)){
+ return new Double[]{gcj_lon,gcj_lat};
+ }
+ double dlat = transformlat(gcj_lon - 105.0, gcj_lat - 35.0);
+ double dlng = transformlng(gcj_lon - 105.0, gcj_lat - 35.0);
+ double radlat = gcj_lat / 180.0 * PI;
+ double magic = Math.sin(radlat);
+ magic = 1 - ee * magic * magic;
+ double sqrtmagic = Math.sqrt(magic);
+ dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * PI);
+ dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * PI);
+ double mglat = gcj_lat + dlat;
+ double mglng = gcj_lon + dlng;
+ return new Double[]{gcj_lon * 2 - mglng, gcj_lat * 2 - mglat};
+ }
+
+ private static Double transformlat(double lng, double lat) {
+ double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
+ return ret;
+ }
+
+ private static Double transformlng(double lng,double lat) {
+ double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
+ ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+ ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
+ ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
+ return ret;
+ }
+
+ /**
+ * outOfChina
+ * @描述: 判断是否在国内,不在国内则不做偏移
+ * @param lng
+ * @param lat
+ * @return {boolean}
+ */
+ private static boolean outOfChina(Double lng,Double lat) {
+ return (lng < 72.004 || lng > 137.8347) || ((lat < 0.8293 || lat > 55.8271) || false);
+ };
+
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
index 80258188..eed37635 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
@@ -25,6 +25,7 @@ public class SipUtils {
* */
public static String getChannelIdFromHeader(Request request) {
Header subject = request.getHeader("subject");
+ if (subject == null) return null;
return ((Subject) subject).getSubject().split(":")[0];
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
index 09e7a04f..6ae09bda 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/utils/XmlUtil.java
@@ -211,6 +211,14 @@ public class XmlUtil {
deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
}
deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
+ String parentId = XmlUtil.getText(itemDevice, "ParentID");
+ if (parentId != null && parentId.contains("/")) {
+ String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
+ deviceChannel.setParentId(lastParentId);
+ }else {
+ deviceChannel.setParentId(parentId);
+ }
+
if (XmlUtil.getText(itemDevice, "SafetyWay") == null
|| XmlUtil.getText(itemDevice, "SafetyWay") == "") {
deviceChannel.setSafetyWay(0);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/RedisAlarmMsgListener.java b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisAlarmMsgListener.java
new file mode 100644
index 00000000..2bff8643
--- /dev/null
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/RedisAlarmMsgListener.java
@@ -0,0 +1,69 @@
+package com.genersoft.iot.vmp.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.genersoft.iot.vmp.gb28181.bean.*;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
+import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
+import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.connection.Message;
+import org.springframework.data.redis.connection.MessageListener;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Component;
+
+import java.text.SimpleDateFormat;
+
+@Component
+public class RedisAlarmMsgListener implements MessageListener {
+
+ private final static Logger logger = LoggerFactory.getLogger(RedisAlarmMsgListener.class);
+
+ @Autowired
+ private ISIPCommander commander;
+
+ @Autowired
+ private ISIPCommanderForPlatform commanderForPlatform;
+
+ @Autowired
+ private IVideoManagerStorage storage;
+
+ private final SimpleDateFormat formatForGB = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
+
+ @Override
+ public void onMessage(Message message, byte[] bytes) {
+ logger.info("收到来自REDIS的ALARM通知: {}", new String(message.getBody()));
+ AlarmChannelMessage alarmChannelMessage = JSON.parseObject(message.getBody(), AlarmChannelMessage.class);
+ if (alarmChannelMessage == null) {
+ logger.warn("[REDIS的ALARM通知]消息解析失败");
+ return;
+ }
+ String gbId = alarmChannelMessage.getGbId();
+ Device device = storage.queryVideoDevice(gbId);
+ ParentPlatform platform = storage.queryParentPlatByServerGBId(gbId);
+
+ DeviceAlarm deviceAlarm = new DeviceAlarm();
+ deviceAlarm.setChannelId(gbId);
+ deviceAlarm.setAlarmDescription(alarmChannelMessage.getAlarmDescription());
+ deviceAlarm.setAlarmMethod("" + alarmChannelMessage.getAlarmSn());
+ deviceAlarm.setAlarmPriority("1");
+ deviceAlarm.setAlarmTime(formatForGB.format(System.currentTimeMillis()));
+ deviceAlarm.setAlarmType("1");
+ deviceAlarm.setLongitude(0);
+ deviceAlarm.setLatitude(0);
+
+
+ if (device != null && platform == null) {
+ commander.sendAlarmMessage(device, deviceAlarm);
+ }else if (device == null && platform != null){
+ commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
+ }else {
+ logger.warn("无法确定" + gbId + "是平台还是设备");
+ }
+ }
+}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
index c6b7e648..8d18f528 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
@@ -139,6 +139,12 @@ public interface IRedisCatchStorage {
*/
void sendStreamChangeMsg(String type, JSONObject jsonObject);
+ /**
+ * 发送报警消息
+ * @param msg 消息内容
+ */
+ void sendAlarmMsg(AlarmChannelMessage msg);
+
/**
* 添加流信息到redis
* @param mediaServerItem
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
index 9d12eb58..d3a9ae9e 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java
@@ -5,7 +5,6 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
-import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.github.pagehelper.PageInfo;
@@ -94,12 +93,6 @@ public interface IVideoManagerStorage {
public List queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit);
- /**
- * 获取某个设备的通道树
- * @param deviceId 设备ID
- * @return
- */
- List tree(String deviceId);
/**
* 获取某个设备的通道列表
@@ -180,7 +173,7 @@ public interface IVideoManagerStorage {
* @param count
* @return
*/
- PageInfo querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, String online, int page, int count);
+ PageInfo querySubChannels(String deviceId, String channelId, String query, Boolean hasSubChannel, Boolean online, int page, int count);
/**
@@ -285,7 +278,7 @@ public interface IVideoManagerStorage {
* @param startTime
* @param endTime
*/
- public List queryMobilePositions(String deviceId, String startTime, String endTime);
+ public List queryMobilePositions(String deviceId, String channelId, String startTime, String endTime);
/**
* 查询最新移动位置
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
index 42e46e10..312d3e03 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java
@@ -2,7 +2,6 @@ package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannelInPlatform;
-import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
@@ -236,21 +235,6 @@ public interface DeviceChannelMapper {
@Select("SELECT * FROM device_channel WHERE deviceId=#{deviceId} AND status=1")
List queryOnlineChannelsByDeviceId(String deviceId);
- @Select(" SELECT\n" +
- " id,\n" +
- " channelId,\n" +
- " deviceId,\n" +
- " parentId,\n" +
- " status,\n" +
- " name as title,\n" +
- " channelId as \"value\",\n" +
- " channelId as \"key\",\n" +
- " longitude,\n" +
- " latitude\n" +
- " from device_channel\n" +
- " where deviceId = #{deviceId}")
- List tree(String deviceId);
-
@Delete(value = {" "})
- List queryPositionByDeviceIdAndTime(String deviceId, String startTime, String endTime);
+ List queryPositionByDeviceIdAndTime(String deviceId, String channelId, String startTime, String endTime);
@Select("SELECT * FROM device_mobile_position WHERE deviceId = #{deviceId}" +
" ORDER BY time DESC LIMIT 1")
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
index fc78de4a..e541c310 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
@@ -639,4 +639,10 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage {
redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
}
+ @Override
+ public void sendAlarmMsg(AlarmChannelMessage msg) {
+ String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM;
+ logger.info("[redis 报警通知] {}: {}", key, JSON.toJSON(msg));
+ redis.convertAndSend(key, (JSONObject)JSON.toJSON(msg));
+ }
}
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
index fbb6e38d..661a69b3 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -13,8 +13,6 @@ import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.storager.dao.dto.ChannelSourceInfo;
-import com.genersoft.iot.vmp.utils.node.ForestNodeMerger;
-import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
@@ -354,10 +352,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit);
}
- @Override
- public List tree(String deviceId) {
- return ForestNodeMerger.merge(deviceChannelMapper.tree(deviceId));
- }
@Override
public List queryChannelsByDeviceId(String deviceId) {
@@ -365,9 +359,9 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
@Override
- public PageInfo querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) {
+ public PageInfo querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
PageHelper.startPage(page, count);
- List all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, null, null, null);
+ List all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, query, hasSubChannel, online);
return new PageInfo<>(all);
}
@@ -504,8 +498,8 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
* @param endTime
*/
@Override
- public synchronized List queryMobilePositions(String deviceId, String startTime, String endTime) {
- return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, startTime, endTime);
+ public synchronized List queryMobilePositions(String deviceId, String channelId, String startTime, String endTime) {
+ return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, channelId, startTime, endTime);
}
@Override
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java
deleted file mode 100644
index 89e35a54..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/BaseNode.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * 节点基类
- *
- */
-public class BaseNode implements INode {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * 主键ID
- */
- protected String channelId;
-
- /**
- * 父节点ID
- */
- protected String parentId;
-
- /**
- * 子孙节点
- */
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- protected List children = new ArrayList();
-
- /**
- * 是否有子孙节点
- */
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- private Boolean hasChildren;
-
- /**
- * 是否有子孙节点
- *
- * @return Boolean
- */
- @Override
- public Boolean getHasChildren() {
- if (children.size() > 0) {
- return true;
- } else {
- return this.hasChildren;
- }
- }
-
- @Override
- public String getChannelId() {
- return channelId;
- }
-
- @Override
- public String getParentId() {
- return parentId;
- }
-
- @Override
- public List getChildren() {
- return children;
- }
-
- public void setChildren(List children) {
- this.children = children;
- }
-
- public void setHasChildren(Boolean hasChildren) {
- this.hasChildren = hasChildren;
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java
deleted file mode 100644
index d983c56b..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNode.java
+++ /dev/null
@@ -1,31 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-
-
-/**
- * 森林节点类
- *
- */
-public class ForestNode extends BaseNode {
-
- private static final long serialVersionUID = 1L;
-
- /**
- * 节点内容
- */
- private Object content;
-
- public ForestNode(String id, String parentId, Object content) {
- this.channelId = id;
- this.parentId = parentId;
- this.content = content;
- }
-
- public Object getContent() {
- return content;
- }
-
- public void setContent(Object content) {
- this.content = content;
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java
deleted file mode 100644
index affce9d1..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeManager.java
+++ /dev/null
@@ -1,68 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Maps;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-/**
- * 森林管理类
- *
- * @author smallchill
- */
-public class ForestNodeManager> {
-
- /**
- * 森林的所有节点
- */
- private final ImmutableMap nodeMap;
-
- /**
- * 森林的父节点ID
- */
- private final Map parentIdMap = Maps.newHashMap();
-
- public ForestNodeManager(List nodes) {
- nodeMap = Maps.uniqueIndex(nodes, INode::getChannelId);
- }
-
- /**
- * 根据节点ID获取一个节点
- *
- * @param id 节点ID
- * @return 对应的节点对象
- */
- public INode getTreeNodeAt(String id) {
- if (nodeMap.containsKey(id)) {
- return nodeMap.get(id);
- }
- return null;
- }
-
- /**
- * 增加父节点ID
- *
- * @param parentId 父节点ID
- */
- public void addParentId(String parentId) {
- parentIdMap.put(parentId, "");
- }
-
- /**
- * 获取树的根节点(一个森林对应多颗树)
- *
- * @return 树的根节点集合
- */
- public List getRoot() {
- List roots = new ArrayList<>();
- nodeMap.forEach((key, node) -> {
- if (node.getParentId() == null || parentIdMap.containsKey(node.getChannelId())) {
- roots.add(node);
- }
- });
- return roots;
- }
-
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java b/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java
deleted file mode 100644
index 8df6f503..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/ForestNodeMerger.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-import com.genersoft.iot.vmp.utils.CollectionUtil;
-
-import java.util.List;
-
-/**
- * 森林节点归并类
- *
- */
-public class ForestNodeMerger {
-
- /**
- * 将节点数组归并为一个森林(多棵树)(填充节点的children域)
- * 时间复杂度为O(n^2)
- *
- * @param items 节点域
- * @return 多棵树的根节点集合
- */
- public static > List merge(List items) {
- ForestNodeManager forestNodeManager = new ForestNodeManager<>(items);
- items.forEach(forestNode -> {
- if (forestNode.getParentId() != null) {
- INode node = forestNodeManager.getTreeNodeAt(forestNode.getParentId());
- if (node != null) {
- node.getChildren().add(forestNode);
- } else {
- forestNodeManager.addParentId(forestNode.getChannelId());
- }
- }
- });
- return forestNodeManager.getRoot();
- }
-
- public static > List merge(List items, String[] parentIds) {
- ForestNodeManager forestNodeManager = new ForestNodeManager<>(items);
- items.forEach(forestNode -> {
- if (forestNode.getParentId() != null) {
- INode node = forestNodeManager.getTreeNodeAt(forestNode.getParentId());
- if (CollectionUtil.contains(parentIds, forestNode.getChannelId())){
- forestNodeManager.addParentId(forestNode.getChannelId());
- } else {
- if (node != null){
- node.getChildren().add(forestNode);
- }
- }
- }
- });
- return forestNodeManager.getRoot();
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java
deleted file mode 100644
index 27727470..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/INode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-import java.io.Serializable;
-import java.util.List;
-
-/**
- *
- * 节点
- */
-public interface INode extends Serializable {
-
- /**
- * 主键
- *
- * @return String
- */
- String getChannelId();
-
- /**
- * 父主键
- *
- * @return String
- */
- String getParentId();
-
- /**
- * 子孙节点
- *
- * @return List
- */
- List getChildren();
-
- /**
- * 是否有子孙节点
- *
- * @return Boolean
- */
- default Boolean getHasChildren() {
- return false;
- }
-
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/utils/node/TreeNode.java b/src/main/java/com/genersoft/iot/vmp/utils/node/TreeNode.java
deleted file mode 100644
index 71f1b2b5..00000000
--- a/src/main/java/com/genersoft/iot/vmp/utils/node/TreeNode.java
+++ /dev/null
@@ -1,42 +0,0 @@
-package com.genersoft.iot.vmp.utils.node;
-
-
-
-/**
- * 树型节点类
- *
- */
-public class TreeNode extends BaseNode {
-
- private static final long serialVersionUID = 1L;
-
- private String title;
-
- private String key;
-
- private String value;
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTree.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTree.java
deleted file mode 100644
index 73928a46..00000000
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTree.java
+++ /dev/null
@@ -1,121 +0,0 @@
-package com.genersoft.iot.vmp.vmanager.bean;
-
-import com.fasterxml.jackson.annotation.JsonInclude;
-import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
-import com.genersoft.iot.vmp.utils.node.INode;
-import io.swagger.annotations.ApiModel;
-
-import java.util.ArrayList;
-import java.util.List;
-
-@ApiModel(value = "DeviceChannelTree对象", description = "DeviceChannelTree对象")
-public class DeviceChannelTree extends DeviceChannel implements INode {
- private static final long serialVersionUID = 1L;
-
- /**
- * 主键ID
- */
- private int id;
-
- /**
- * 父节点ID
- */
- private String parentId;
-
- private String parentName;
-
- private String title;
-
- private String key;
-
- private String value;
-
- /**
- * 子孙节点
- */
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- private List children;
-
- /**
- * 是否有子孙节点
- */
- @JsonInclude(JsonInclude.Include.NON_EMPTY)
- private Boolean hasChildren;
-
- @Override
- public List getChildren() {
- if (this.children == null) {
- this.children = new ArrayList<>();
- }
- return this.children;
- }
-
- @Override
- public Boolean getHasChildren() {
- if (children.size() > 0) {
- return true;
- } else {
- return this.hasChildren;
- }
- }
-
- @Override
- public int getId() {
- return id;
- }
-
- @Override
- public void setId(int id) {
- this.id = id;
- }
-
- @Override
- public String getParentId() {
- return parentId;
- }
-
- @Override
- public void setParentId(String parentId) {
- this.parentId = parentId;
- }
-
- public String getParentName() {
- return parentName;
- }
-
- public void setParentName(String parentName) {
- this.parentName = parentName;
- }
-
- public String getTitle() {
- return title;
- }
-
- public void setTitle(String title) {
- this.title = title;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public void setChildren(List children) {
- this.children = children;
- }
-
- public void setHasChildren(Boolean hasChildren) {
- this.hasChildren = hasChildren;
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTreeNode.java b/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTreeNode.java
deleted file mode 100644
index 96577d1f..00000000
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/bean/DeviceChannelTreeNode.java
+++ /dev/null
@@ -1,56 +0,0 @@
-package com.genersoft.iot.vmp.vmanager.bean;
-
-import com.genersoft.iot.vmp.utils.node.TreeNode;
-
-public class DeviceChannelTreeNode extends TreeNode {
-
- private Integer status;
-
- private String deviceId;
-
- private String channelId;
-
- private Double lng;
-
- private Double lat;
-
- public Integer getStatus() {
- return status;
- }
-
- public void setStatus(Integer status) {
- this.status = status;
- }
-
- public String getDeviceId() {
- return deviceId;
- }
-
- public void setDeviceId(String deviceId) {
- this.deviceId = deviceId;
- }
-
- public String getChannelId() {
- return channelId;
- }
-
- public void setChannelId(String channelId) {
- this.channelId = channelId;
- }
-
- public Double getLng() {
- return lng;
- }
-
- public void setLng(Double lng) {
- this.lng = lng;
- }
-
- public Double getLat() {
- return lat;
- }
-
- public void setLat(Double lat) {
- this.lat = lat;
- }
-}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
index c360843d..7d11b15c 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/MobilePosition/MobilePositionController.java
@@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
+import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.util.StringUtil;
import io.swagger.annotations.Api;
@@ -65,10 +66,11 @@ public class MobilePositionController {
@ApiImplicitParam(name = "start", value = "开始时间", required = true, dataTypeClass = String.class),
@ApiImplicitParam(name = "end", value = "结束时间", required = true, dataTypeClass = String.class),
})
- @GetMapping("/history/{deviceId}")
- public ResponseEntity> positions(@PathVariable String deviceId,
- @RequestParam(required = false) String start,
- @RequestParam(required = false) String end) {
+ @GetMapping("/history/{deviceId}/{channelId}")
+ public ResponseEntity>> positions(@PathVariable String deviceId,
+ @PathVariable String channelId,
+ @RequestParam(required = false) String start,
+ @RequestParam(required = false) String end) {
// if (logger.isDebugEnabled()) {
// logger.debug("查询设备" + deviceId + "的历史轨迹");
// }
@@ -79,9 +81,11 @@ public class MobilePositionController {
if (StringUtil.isEmpty(end)) {
end = null;
}
-
- List result = storager.queryMobilePositions(deviceId, start, end);
- return new ResponseEntity<>(result, HttpStatus.OK);
+ WVPResult> wvpResult = new WVPResult<>();
+ wvpResult.setCode(0);
+ List result = storager.queryMobilePositions(deviceId, channelId, start, end);
+ wvpResult.setData(result);
+ return new ResponseEntity<>(wvpResult, HttpStatus.OK);
}
/**
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
index 434bbd49..e7858569 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/alarm/AlarmController.java
@@ -1,8 +1,14 @@
package com.genersoft.iot.vmp.vmanager.gb28181.alarm;
+import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
+import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
+import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.service.IGbStreamService;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
@@ -31,7 +37,17 @@ public class AlarmController {
@Autowired
private IDeviceAlarmService deviceAlarmService;
+ @Autowired
+ private ISIPCommander commander;
+
+ @Autowired
+ private ISIPCommanderForPlatform commanderForPlatform;
+
+ @Autowired
+ private IVideoManagerStorage storage;
+
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ private SimpleDateFormat formatForGB = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
/**
* 分页查询报警
@@ -133,5 +149,51 @@ public class AlarmController {
return new ResponseEntity>(wvpResult, HttpStatus.OK);
}
+ /**
+ * 测试向上级/设备发送模拟报警通知
+ *
+ * @param deviceId 报警id
+ * @return
+ */
+ @ApiOperation("测试向上级/设备发送模拟报警通知")
+ @GetMapping("/test/notify/alarm")
+ @ApiImplicitParams({
+ @ApiImplicitParam(name="deviceId", value = "deviceId", required = true ,dataTypeClass = Integer.class)
+ })
+ public ResponseEntity> delete(
+ @RequestParam(required = false) String deviceId
+ ) {
+ if (StringUtils.isEmpty(deviceId)) {
+ return new ResponseEntity<>(HttpStatus.NOT_FOUND);
+ }
+ Device device = storage.queryVideoDevice(deviceId);
+ ParentPlatform platform = storage.queryParentPlatByServerGBId(deviceId);
+ DeviceAlarm deviceAlarm = new DeviceAlarm();
+ deviceAlarm.setChannelId(deviceId);
+ deviceAlarm.setAlarmDescription("test");
+ deviceAlarm.setAlarmMethod("1");
+ deviceAlarm.setAlarmPriority("1");
+ deviceAlarm.setAlarmTime(formatForGB.format(System.currentTimeMillis()));
+ deviceAlarm.setAlarmType("1");
+ deviceAlarm.setLongitude(115.33333);
+ deviceAlarm.setLatitude(39.33333);
+
+ if (device != null && platform == null) {
+ commander.sendAlarmMessage(device, deviceAlarm);
+ }else if (device == null && platform != null){
+ commanderForPlatform.sendAlarmMessage(platform, deviceAlarm);
+ }else {
+ WVPResult wvpResult = new WVPResult();
+ wvpResult.setCode(0);
+ wvpResult.setMsg("无法确定" + deviceId + "是平台还是设备");
+ return new ResponseEntity>(wvpResult, HttpStatus.OK);
+ }
+
+ WVPResult wvpResult = new WVPResult();
+ wvpResult.setCode(0);
+ wvpResult.setMsg("success");
+ return new ResponseEntity>(wvpResult, HttpStatus.OK);
+ }
+
}
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
index 95d2843d..ab153ad4 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java
@@ -9,7 +9,6 @@ import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask;
import com.genersoft.iot.vmp.gb28181.task.impl.CatalogSubscribeTask;
-import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeHandlerTask;
import com.genersoft.iot.vmp.gb28181.task.impl.MobilePositionSubscribeTask;
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
@@ -17,14 +16,12 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
-import com.genersoft.iot.vmp.vmanager.bean.DeviceChannelTree;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
-import org.kxml2.wap.wv.WV;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -235,7 +232,7 @@ public class DeviceQuery {
@ApiImplicitParam(name="page", value = "当前页", required = true, dataTypeClass = Integer.class),
@ApiImplicitParam(name="count", value = "每页条数", required = true, dataTypeClass = Integer.class),
@ApiImplicitParam(name="query", value = "查询内容", dataTypeClass = String.class),
- @ApiImplicitParam(name="online", value = "是否在线", dataTypeClass = String.class),
+ @ApiImplicitParam(name="online", value = "是否在线", dataTypeClass = Boolean.class),
@ApiImplicitParam(name="channelType", value = "通道类型, 子目录", dataTypeClass = Boolean.class),
})
@GetMapping("/sub_channels/{deviceId}/{channelId}/channels")
@@ -244,7 +241,7 @@ public class DeviceQuery {
int page,
int count,
@RequestParam(required = false) String query,
- @RequestParam(required = false) String online,
+ @RequestParam(required = false) Boolean online,
@RequestParam(required = false) Boolean channelType){
// if (logger.isDebugEnabled()) {
@@ -450,11 +447,6 @@ public class DeviceQuery {
return result;
}
- @GetMapping("/{deviceId}/tree")
- @ApiOperation(value = "通道树形结构", notes = "通道树形结构")
- public WVPResult> tree(@PathVariable String deviceId) {
- return WVPResult.Data(storager.tree(deviceId));
- }
@GetMapping("/{deviceId}/sync_status")
@ApiOperation(value = "获取通道同步进度", notes = "获取通道同步进度")
diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
index 9d6b8fcf..6fdadf26 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/record/GBRecordController.java
@@ -63,7 +63,7 @@ public class GBRecordController {
public DeferredResult> recordinfo(@PathVariable String deviceId,@PathVariable String channelId, String startTime, String endTime){
if (logger.isDebugEnabled()) {
- logger.debug(String.format("录像信息查询 API调用,deviceId:%s ,startTime:%s, startTime:%s",deviceId, startTime, endTime));
+ logger.debug(String.format("录像信息查询 API调用,deviceId:%s ,startTime:%s, endTime:%s",deviceId, startTime, endTime));
}
Device device = storager.queryVideoDevice(deviceId);
diff --git a/web_src/index.html b/web_src/index.html
index ca1b842e..f69f16be 100644
--- a/web_src/index.html
+++ b/web_src/index.html
@@ -12,8 +12,26 @@
-
+