处理报警和位置上报时使用fromHeader获取deviceId, xml的deviceId作为channelId使用。

pull/183/head
648540858 2021-09-27 15:36:41 +08:00
parent 3ae18a5583
commit 497e581e5e
8 changed files with 91 additions and 23 deletions

View File

@ -66,6 +66,7 @@ create table device_alarm
id int auto_increment id int auto_increment
primary key, primary key,
deviceId varchar(50) not null, deviceId varchar(50) not null,
channelId varchar(50) not null,
alarmPriority varchar(50) not null, alarmPriority varchar(50) not null,
alarmMethod varchar(50), alarmMethod varchar(50),
alarmTime varchar(50) not null, alarmTime varchar(50) not null,
@ -92,6 +93,7 @@ create table log
create table device_mobile_position create table device_mobile_position
( (
deviceId varchar(50) not null, deviceId varchar(50) not null,
channelId varchar(50) not null,
deviceName varchar(255) null, deviceName varchar(255) null,
time varchar(50) not null, time varchar(50) not null,
longitude double not null, longitude double not null,

View File

@ -13,6 +13,11 @@ public class DeviceAlarm {
*/ */
private String deviceId; private String deviceId;
/**
* Id
*/
private String channelId;
/** /**
* , 1, 2, 3, 4 - * , 1, 2, 3, 4 -
*/ */
@ -121,4 +126,12 @@ public class DeviceAlarm {
public void setAlarmType(String alarmType) { public void setAlarmType(String alarmType) {
this.alarmType = alarmType; this.alarmType = alarmType;
} }
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
} }

View File

@ -12,6 +12,11 @@ public class MobilePosition {
*/ */
private String deviceId; private String deviceId;
/**
* Id
*/
private String channelId;
/** /**
* *
*/ */
@ -163,4 +168,12 @@ public class MobilePosition {
public void setCnLat(String cnLat) { public void setCnLat(String cnLat) {
this.cnLat = cnLat; this.cnLat = cnLat;
} }
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
} }

View File

@ -5,9 +5,11 @@ import java.text.ParseException;
import java.util.*; import java.util.*;
import javax.sip.*; import javax.sip.*;
import javax.sip.address.Address;
import javax.sip.address.SipURI; import javax.sip.address.SipURI;
import javax.sip.header.FromHeader; import javax.sip.header.FromHeader;
import javax.sip.header.Header;
import javax.sip.header.HeaderAddress; import javax.sip.header.HeaderAddress;
import javax.sip.header.ToHeader; import javax.sip.header.ToHeader;
import javax.sip.message.Request; import javax.sip.message.Request;
@ -34,6 +36,7 @@ import com.genersoft.iot.vmp.service.IDeviceAlarmService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager; import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.utils.GpsUtil; import com.genersoft.iot.vmp.utils.GpsUtil;
import com.genersoft.iot.vmp.utils.SipUtils;
import com.genersoft.iot.vmp.utils.SpringBeanFactory; import com.genersoft.iot.vmp.utils.SpringBeanFactory;
import com.genersoft.iot.vmp.utils.redis.RedisUtil; import com.genersoft.iot.vmp.utils.redis.RedisUtil;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
@ -166,18 +169,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void processMessageMobilePosition(RequestEvent evt) { private void processMessageMobilePosition(RequestEvent evt) {
try { try {
Element rootElement = getRootElement(evt); String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
logger.warn("处理MobilePosition移动位置消息时未找到设备信息");
return;
}
Element rootElement = getRootElement(evt, device.getCharset());
MobilePosition mobilePosition = new MobilePosition(); MobilePosition mobilePosition = new MobilePosition();
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getTextTrim().toString();
Device device = storager.queryVideoDevice(deviceId);
if (device != null) {
rootElement = getRootElement(evt, device.getCharset());
if (!StringUtils.isEmpty(device.getName())) { if (!StringUtils.isEmpty(device.getName())) {
mobilePosition.setDeviceName(device.getName()); mobilePosition.setDeviceName(device.getName());
} }
} mobilePosition.setDeviceId(deviceId);
mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID")); mobilePosition.setChannelId(XmlUtil.getText(rootElement, "DeviceID"));
mobilePosition.setTime(XmlUtil.getText(rootElement, "Time")); mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
@ -691,16 +697,18 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
*/ */
private void processMessageAlarm(RequestEvent evt) { private void processMessageAlarm(RequestEvent evt) {
try { try {
Element rootElement = getRootElement(evt); String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
logger.warn("处理alarm设备报警信息未找到设备信息");
return;
}
Element rootElement = getRootElement(evt, device.getCharset());
Element deviceIdElement = rootElement.element("DeviceID"); Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString(); String channelId = deviceIdElement.getText().toString();
// 回复200 OK // 回复200 OK
responseAck(evt); responseAck(evt);
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
if (device.getCharset() != null) { if (device.getCharset() != null) {
rootElement = getRootElement(evt, device.getCharset()); rootElement = getRootElement(evt, device.getCharset());
} }
@ -708,6 +716,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
if (rootElement.getName().equals("Notify")) { // 处理报警通知 if (rootElement.getName().equals("Notify")) { // 处理报警通知
DeviceAlarm deviceAlarm = new DeviceAlarm(); DeviceAlarm deviceAlarm = new DeviceAlarm();
deviceAlarm.setDeviceId(deviceId); deviceAlarm.setDeviceId(deviceId);
deviceAlarm.setChannelId(channelId);
deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod")); deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime")); deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
@ -792,7 +801,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
ServerTransaction serverTransaction = getServerTransaction(evt); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response); serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
} }
// if (device != null && device.getOnline() == 1) { // if (device != null && device.getOnline() == 1) {
@ -1006,7 +1017,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
ServerTransaction serverTransaction = getServerTransaction(evt); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response); serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
} }
/*** /***
@ -1020,7 +1033,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
ServerTransaction serverTransaction = getServerTransaction(evt); ServerTransaction serverTransaction = getServerTransaction(evt);
serverTransaction.sendResponse(response); serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); if (serverTransaction.getDialog() != null) {
serverTransaction.getDialog().delete();
}
} }
private Element getRootElement(RequestEvent evt) throws DocumentException { private Element getRootElement(RequestEvent evt) throws DocumentException {
@ -1029,7 +1044,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
} }
private Element getRootElement(RequestEvent evt, String charset) throws DocumentException { private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
if (charset == null) charset = "gb2312"; if (charset == null) {
charset = "gb2312";
}
Request request = evt.getRequest(); Request request = evt.getRequest();
SAXReader reader = new SAXReader(); SAXReader reader = new SAXReader();
reader.setEncoding(charset); reader.setEncoding(charset);

View File

@ -15,8 +15,8 @@ import java.util.List;
@Repository @Repository
public interface DeviceAlarmMapper { public interface DeviceAlarmMapper {
@Insert("INSERT INTO device_alarm (deviceId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " + @Insert("INSERT INTO device_alarm (deviceId, channelId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " +
"VALUES ('${deviceId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')") "VALUES ('${deviceId}', '${channelId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')")
int add(DeviceAlarm alarm); int add(DeviceAlarm alarm);

View File

@ -10,8 +10,8 @@ import org.apache.ibatis.annotations.*;
//@Repository //@Repository
public interface DeviceMobilePositionMapper { public interface DeviceMobilePositionMapper {
@Insert("INSERT INTO device_mobile_position (deviceId, deviceName, time, longitude, latitude, altitude, speed, direction, reportSource, geodeticSystem, cnLng, cnLat) " + @Insert("INSERT INTO device_mobile_position (deviceId,channelId, deviceName, time, longitude, latitude, altitude, speed, direction, reportSource, geodeticSystem, cnLng, cnLat) " +
"VALUES ('${deviceId}', '${deviceName}', '${time}', ${longitude}, ${latitude}, ${altitude}, ${speed}, ${direction}, '${reportSource}', '${geodeticSystem}', '${cnLng}', '${cnLat}')") "VALUES ('${deviceId}','${channelId}', '${deviceName}', '${time}', ${longitude}, ${latitude}, ${altitude}, ${speed}, ${direction}, '${reportSource}', '${geodeticSystem}', '${cnLng}', '${cnLat}')")
int insertNewPosition(MobilePosition mobilePosition); int insertNewPosition(MobilePosition mobilePosition);
@Select(value = {" <script>" + @Select(value = {" <script>" +

View File

@ -0,0 +1,23 @@
package com.genersoft.iot.vmp.utils;
import gov.nist.javax.sip.address.AddressImpl;
import gov.nist.javax.sip.address.SipUri;
import javax.sip.header.FromHeader;
import javax.sip.message.Request;
/**
* @author panlinlin
* @version 1.0.0
* @Description JAIN SIP
* @createTime 20210927 15:12:00
*/
public class SipUtils {
public static String getUserIdFromFromHeader(Request request) {
FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
AddressImpl address = (AddressImpl)fromHeader.getAddress();
SipUri uri = (SipUri) address.getURI();
return uri.getUser();
}
}

Binary file not shown.