Commit 6811b8dc5c77a6b3c450e1980f976a23ac084788

Authored by Lawrence
1 parent e4215917

增加设备报警事件响应、发布和信息处理

src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
@@ -11,7 +11,7 @@ public class DeviceAlarm { @@ -11,7 +11,7 @@ public class DeviceAlarm {
11 /** 11 /**
12 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情- 12 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
13 */ 13 */
14 - private String alarmPriorit; 14 + private String alarmPriority;
15 15
16 /** 16 /**
17 * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警, 17 * 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
@@ -53,12 +53,12 @@ public class DeviceAlarm { @@ -53,12 +53,12 @@ public class DeviceAlarm {
53 this.deviceId = deviceId; 53 this.deviceId = deviceId;
54 } 54 }
55 55
56 - public String getAlarmPriorit() {  
57 - return alarmPriorit; 56 + public String getAlarmPriority() {
  57 + return alarmPriority;
58 } 58 }
59 59
60 - public void setAlarmPriorit(String alarmPriorit) {  
61 - this.alarmPriorit = alarmPriorit; 60 + public void setAlarmPriority(String alarmPriority) {
  61 + this.alarmPriority = alarmPriority;
62 } 62 }
63 63
64 public String getAlarmMethod() { 64 public String getAlarmMethod() {
src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java
@@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
6 import org.springframework.context.ApplicationEventPublisher; 6 import org.springframework.context.ApplicationEventPublisher;
7 import org.springframework.stereotype.Component; 7 import org.springframework.stereotype.Component;
8 8
  9 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  10 +import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
9 import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent; 11 import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
10 import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent; 12 import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent;
11 13
@@ -52,5 +54,15 @@ public class EventPublisher { @@ -52,5 +54,15 @@ public class EventPublisher {
52 PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this); 54 PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this);
53 platformNotRegisterEvent.setPlatformGbID(platformGbId); 55 platformNotRegisterEvent.setPlatformGbID(platformGbId);
54 applicationEventPublisher.publishEvent(platformNotRegisterEvent); 56 applicationEventPublisher.publishEvent(platformNotRegisterEvent);
55 - } 57 + }
  58 +
  59 + /**
  60 + * 设备报警事件
  61 + * @param deviceAlarm
  62 + */
  63 + public void deviceAlarmEventPublish(DeviceAlarm deviceAlarm) {
  64 + AlarmEvent alarmEvent = new AlarmEvent(this);
  65 + alarmEvent.setAlarmInfo(deviceAlarm);
  66 + applicationEventPublisher.publishEvent(alarmEvent);
  67 + }
56 } 68 }
src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.event.alarm;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  4 +import org.springframework.context.ApplicationEvent;
  5 +
  6 +/**
  7 + * @description: 报警事件
  8 + * @author: lawrencehj
  9 + * @data: 2021-01-20
  10 + */
  11 +
  12 +public class AlarmEvent extends ApplicationEvent {
  13 + public AlarmEvent(Object source) {
  14 + super(source);
  15 + }
  16 +
  17 + private DeviceAlarm deviceAlarm;
  18 +
  19 + public DeviceAlarm getAlarmInfo() {
  20 + return deviceAlarm;
  21 + }
  22 +
  23 + public void setAlarmInfo(DeviceAlarm deviceAlarm) {
  24 + this.deviceAlarm = deviceAlarm;
  25 + }
  26 +}
src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEventListener.java 0 → 100644
  1 +package com.genersoft.iot.vmp.gb28181.event.alarm;
  2 +
  3 +import org.springframework.context.ApplicationListener;
  4 +import org.springframework.stereotype.Component;
  5 +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
  6 +import java.io.IOException;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +
  10 +/**
  11 + * @description: 报警事件监听
  12 + * @author: lawrencehj
  13 + * @data: 2021-01-20
  14 + */
  15 +
  16 +@Component
  17 +public class AlarmEventListener implements ApplicationListener<AlarmEvent> {
  18 +
  19 + private final static Logger logger = LoggerFactory.getLogger(AlarmEventListener.class);
  20 +
  21 + private static SseEmitter emitter = new SseEmitter();
  22 +
  23 + public void addSseEmitters(SseEmitter sseEmitter) {
  24 + emitter = sseEmitter;
  25 + }
  26 +
  27 + @Override
  28 + public void onApplicationEvent(AlarmEvent event) {
  29 + if (logger.isDebugEnabled()) {
  30 + logger.debug("设备报警事件触发,deviceId:" + event.getAlarmInfo().getDeviceId() + ", "
  31 + + event.getAlarmInfo().getAlarmDescription());
  32 + }
  33 + try {
  34 + String msg = "<strong>设备编码:</strong> <i>" + event.getAlarmInfo().getDeviceId() + "</i>"
  35 + + "<br><strong>报警描述:</strong> <i>" + event.getAlarmInfo().getAlarmDescription() + "</i>"
  36 + + "<br><strong>报警时间:</strong> <i>" + event.getAlarmInfo().getAlarmTime() + "</i>"
  37 + + "<br><strong>定位经度:</strong> <i>" + event.getAlarmInfo().getLongitude() + "</i>"
  38 + + "<br><strong>定位纬度:</strong> <i>" + event.getAlarmInfo().getLatitude() + "</i>";
  39 + emitter.send(msg);
  40 + } catch (IOException e) {
  41 + if (logger.isDebugEnabled()) {
  42 + logger.debug("SSE 通道已关闭");
  43 + }
  44 + // e.printStackTrace();
  45 + }
  46 + }
  47 +}
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -174,7 +174,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -174,7 +174,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
174 SipUri uri = (SipUri) address.getURI(); 174 SipUri uri = (SipUri) address.getURI();
175 String platformId = uri.getUser(); 175 String platformId = uri.getUser();
176 // if (deviceListElement == null) { // 存在DeviceList则为响应 catalog, 不存在DeviceList则为查询请求 176 // if (deviceListElement == null) { // 存在DeviceList则为响应 catalog, 不存在DeviceList则为查询请求
177 - if (name == "Query") { // 区分是Response——查询响应,还是Query——查询请求 177 + if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
178 // TODO 后续将代码拆分 178 // TODO 后续将代码拆分
179 ParentPlatform parentPlatform = storager.queryParentPlatById(platformId); 179 ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
180 if (parentPlatform == null) { 180 if (parentPlatform == null) {
@@ -324,19 +324,41 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -324,19 +324,41 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
324 // storager.queryChannel(deviceId) 324 // storager.queryChannel(deviceId)
325 return; 325 return;
326 } 326 }
327 - device.setName(XmlUtil.getText(rootElement, "DeviceName"));  
328 - device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));  
329 - device.setModel(XmlUtil.getText(rootElement, "Model"));  
330 - device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));  
331 - if (StringUtils.isEmpty(device.getStreamMode())) {  
332 - device.setStreamMode("UDP"); 327 +
  328 + DeviceAlarm deviceAlarm = new DeviceAlarm();
  329 + deviceAlarm.setDeviceId(deviceId);
  330 + deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
  331 + deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
  332 + deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
  333 + if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
  334 + deviceAlarm.setAlarmDescription("");
  335 + } else {
  336 + deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
333 } 337 }
334 - storager.updateDevice(device); 338 + if (XmlUtil.getText(rootElement, "Longitude") == null || XmlUtil.getText(rootElement, "Longitude") == "") {
  339 + deviceAlarm.setLongitude(0.00);
  340 + } else {
  341 + deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
  342 + }
  343 + if (XmlUtil.getText(rootElement, "Latitude") == null || XmlUtil.getText(rootElement, "Latitude") =="") {
  344 + deviceAlarm.setLatitude(0.00);
  345 + } else {
  346 + deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
  347 + }
  348 +
  349 + // device.setName(XmlUtil.getText(rootElement, "DeviceName"));
  350 + // device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
  351 + // device.setModel(XmlUtil.getText(rootElement, "Model"));
  352 + // device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
  353 + // if (StringUtils.isEmpty(device.getStreamMode())) {
  354 + // device.setStreamMode("UDP");
  355 + // }
  356 + // storager.updateDevice(device);
335 //cmder.catalogQuery(device, null); 357 //cmder.catalogQuery(device, null);
336 // 回复200 OK 358 // 回复200 OK
337 responseAck(evt); 359 responseAck(evt);
338 if (offLineDetector.isOnline(deviceId)) { 360 if (offLineDetector.isOnline(deviceId)) {
339 - publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE); 361 + publisher.deviceAlarmEventPublish(deviceAlarm);
340 } 362 }
341 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { 363 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
342 // } catch (DocumentException e) { 364 // } catch (DocumentException e) {