增加设备报警事件响应、发布和信息处理
This commit is contained in:
parent
867e937805
commit
8e9579f253
@ -11,7 +11,7 @@ public class DeviceAlarm {
|
||||
/**
|
||||
* 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
|
||||
*/
|
||||
private String alarmPriorit;
|
||||
private String alarmPriority;
|
||||
|
||||
/**
|
||||
* 报警方式 , 1为电话报警, 2为设备报警, 3为短信报警, 4为 GPS报警, 5为视频报警, 6为设备故障报警,
|
||||
@ -53,12 +53,12 @@ public class DeviceAlarm {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getAlarmPriorit() {
|
||||
return alarmPriorit;
|
||||
public String getAlarmPriority() {
|
||||
return alarmPriority;
|
||||
}
|
||||
|
||||
public void setAlarmPriorit(String alarmPriorit) {
|
||||
this.alarmPriorit = alarmPriorit;
|
||||
public void setAlarmPriority(String alarmPriority) {
|
||||
this.alarmPriority = alarmPriority;
|
||||
}
|
||||
|
||||
public String getAlarmMethod() {
|
||||
|
@ -6,6 +6,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.offline.OfflineEvent;
|
||||
import com.genersoft.iot.vmp.gb28181.event.online.OnlineEvent;
|
||||
|
||||
@ -52,5 +54,15 @@ public class EventPublisher {
|
||||
PlatformNotRegisterEvent platformNotRegisterEvent = new PlatformNotRegisterEvent(this);
|
||||
platformNotRegisterEvent.setPlatformGbID(platformGbId);
|
||||
applicationEventPublisher.publishEvent(platformNotRegisterEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备报警事件
|
||||
* @param deviceAlarm
|
||||
*/
|
||||
public void deviceAlarmEventPublish(DeviceAlarm deviceAlarm) {
|
||||
AlarmEvent alarmEvent = new AlarmEvent(this);
|
||||
alarmEvent.setAlarmInfo(deviceAlarm);
|
||||
applicationEventPublisher.publishEvent(alarmEvent);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.alarm;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @description: 报警事件
|
||||
* @author: lawrencehj
|
||||
* @data: 2021-01-20
|
||||
*/
|
||||
|
||||
public class AlarmEvent extends ApplicationEvent {
|
||||
public AlarmEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
private DeviceAlarm deviceAlarm;
|
||||
|
||||
public DeviceAlarm getAlarmInfo() {
|
||||
return deviceAlarm;
|
||||
}
|
||||
|
||||
public void setAlarmInfo(DeviceAlarm deviceAlarm) {
|
||||
this.deviceAlarm = deviceAlarm;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event.alarm;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
import java.io.IOException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @description: 报警事件监听
|
||||
* @author: lawrencehj
|
||||
* @data: 2021-01-20
|
||||
*/
|
||||
|
||||
@Component
|
||||
public class AlarmEventListener implements ApplicationListener<AlarmEvent> {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AlarmEventListener.class);
|
||||
|
||||
private static SseEmitter emitter = new SseEmitter();
|
||||
|
||||
public void addSseEmitters(SseEmitter sseEmitter) {
|
||||
emitter = sseEmitter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(AlarmEvent event) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("设备报警事件触发,deviceId:" + event.getAlarmInfo().getDeviceId() + ", "
|
||||
+ event.getAlarmInfo().getAlarmDescription());
|
||||
}
|
||||
try {
|
||||
String msg = "<strong>设备编码:</strong> <i>" + event.getAlarmInfo().getDeviceId() + "</i>"
|
||||
+ "<br><strong>报警描述:</strong> <i>" + event.getAlarmInfo().getAlarmDescription() + "</i>"
|
||||
+ "<br><strong>报警时间:</strong> <i>" + event.getAlarmInfo().getAlarmTime() + "</i>"
|
||||
+ "<br><strong>定位经度:</strong> <i>" + event.getAlarmInfo().getLongitude() + "</i>"
|
||||
+ "<br><strong>定位纬度:</strong> <i>" + event.getAlarmInfo().getLatitude() + "</i>";
|
||||
emitter.send(msg);
|
||||
} catch (IOException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("SSE 通道已关闭");
|
||||
}
|
||||
// e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
@ -174,7 +174,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
SipUri uri = (SipUri) address.getURI();
|
||||
String platformId = uri.getUser();
|
||||
// if (deviceListElement == null) { // 存在DeviceList则为响应 catalog, 不存在DeviceList则为查询请求
|
||||
if (name == "Query") { // 区分是Response——查询响应,还是Query——查询请求
|
||||
if (name.equalsIgnoreCase("Query")) { // 区分是Response——查询响应,还是Query——查询请求
|
||||
// TODO 后续将代码拆分
|
||||
ParentPlatform parentPlatform = storager.queryParentPlatById(platformId);
|
||||
if (parentPlatform == null) {
|
||||
@ -324,19 +324,41 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
// storager.queryChannel(deviceId)
|
||||
return;
|
||||
}
|
||||
device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
||||
device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
||||
device.setModel(XmlUtil.getText(rootElement, "Model"));
|
||||
device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
||||
if (StringUtils.isEmpty(device.getStreamMode())) {
|
||||
device.setStreamMode("UDP");
|
||||
|
||||
DeviceAlarm deviceAlarm = new DeviceAlarm();
|
||||
deviceAlarm.setDeviceId(deviceId);
|
||||
deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
|
||||
deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
|
||||
deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
|
||||
if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
|
||||
deviceAlarm.setAlarmDescription("");
|
||||
} else {
|
||||
deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
|
||||
}
|
||||
storager.updateDevice(device);
|
||||
if (XmlUtil.getText(rootElement, "Longitude") == null || XmlUtil.getText(rootElement, "Longitude") == "") {
|
||||
deviceAlarm.setLongitude(0.00);
|
||||
} else {
|
||||
deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
||||
}
|
||||
if (XmlUtil.getText(rootElement, "Latitude") == null || XmlUtil.getText(rootElement, "Latitude") =="") {
|
||||
deviceAlarm.setLatitude(0.00);
|
||||
} else {
|
||||
deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
||||
}
|
||||
|
||||
// device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
||||
// device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
||||
// device.setModel(XmlUtil.getText(rootElement, "Model"));
|
||||
// device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
||||
// if (StringUtils.isEmpty(device.getStreamMode())) {
|
||||
// device.setStreamMode("UDP");
|
||||
// }
|
||||
// storager.updateDevice(device);
|
||||
//cmder.catalogQuery(device, null);
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
publisher.deviceAlarmEventPublish(deviceAlarm);
|
||||
}
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
// } catch (DocumentException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user