Commit 497e581e5e26840400f5f2cd1cf083c3de5e66c2

Authored by 648540858
1 parent 3ae18a55

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

sql/mysql.sql
@@ -66,6 +66,7 @@ create table device_alarm @@ -66,6 +66,7 @@ create table device_alarm
66 id int auto_increment 66 id int auto_increment
67 primary key, 67 primary key,
68 deviceId varchar(50) not null, 68 deviceId varchar(50) not null,
  69 + channelId varchar(50) not null,
69 alarmPriority varchar(50) not null, 70 alarmPriority varchar(50) not null,
70 alarmMethod varchar(50), 71 alarmMethod varchar(50),
71 alarmTime varchar(50) not null, 72 alarmTime varchar(50) not null,
@@ -92,6 +93,7 @@ create table log @@ -92,6 +93,7 @@ create table log
92 create table device_mobile_position 93 create table device_mobile_position
93 ( 94 (
94 deviceId varchar(50) not null, 95 deviceId varchar(50) not null,
  96 + channelId varchar(50) not null,
95 deviceName varchar(255) null, 97 deviceName varchar(255) null,
96 time varchar(50) not null, 98 time varchar(50) not null,
97 longitude double not null, 99 longitude double not null,
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
@@ -14,6 +14,11 @@ public class DeviceAlarm { @@ -14,6 +14,11 @@ public class DeviceAlarm {
14 private String deviceId; 14 private String deviceId;
15 15
16 /** 16 /**
  17 + * 通道Id
  18 + */
  19 + private String channelId;
  20 +
  21 + /**
17 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情- 22 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
18 */ 23 */
19 private String alarmPriority; 24 private String alarmPriority;
@@ -121,4 +126,12 @@ public class DeviceAlarm { @@ -121,4 +126,12 @@ public class DeviceAlarm {
121 public void setAlarmType(String alarmType) { 126 public void setAlarmType(String alarmType) {
122 this.alarmType = alarmType; 127 this.alarmType = alarmType;
123 } 128 }
  129 +
  130 + public String getChannelId() {
  131 + return channelId;
  132 + }
  133 +
  134 + public void setChannelId(String channelId) {
  135 + this.channelId = channelId;
  136 + }
124 } 137 }
src/main/java/com/genersoft/iot/vmp/gb28181/bean/MobilePosition.java
@@ -13,6 +13,11 @@ public class MobilePosition { @@ -13,6 +13,11 @@ public class MobilePosition {
13 private String deviceId; 13 private String deviceId;
14 14
15 /** 15 /**
  16 + * 通道Id
  17 + */
  18 + private String channelId;
  19 +
  20 + /**
16 * 设备名称 21 * 设备名称
17 */ 22 */
18 private String deviceName; 23 private String deviceName;
@@ -163,4 +168,12 @@ public class MobilePosition { @@ -163,4 +168,12 @@ public class MobilePosition {
163 public void setCnLat(String cnLat) { 168 public void setCnLat(String cnLat) {
164 this.cnLat = cnLat; 169 this.cnLat = cnLat;
165 } 170 }
  171 +
  172 + public String getChannelId() {
  173 + return channelId;
  174 + }
  175 +
  176 + public void setChannelId(String channelId) {
  177 + this.channelId = channelId;
  178 + }
166 } 179 }
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -5,9 +5,11 @@ import java.text.ParseException; @@ -5,9 +5,11 @@ import java.text.ParseException;
5 import java.util.*; 5 import java.util.*;
6 6
7 import javax.sip.*; 7 import javax.sip.*;
  8 +import javax.sip.address.Address;
8 import javax.sip.address.SipURI; 9 import javax.sip.address.SipURI;
9 10
10 import javax.sip.header.FromHeader; 11 import javax.sip.header.FromHeader;
  12 +import javax.sip.header.Header;
11 import javax.sip.header.HeaderAddress; 13 import javax.sip.header.HeaderAddress;
12 import javax.sip.header.ToHeader; 14 import javax.sip.header.ToHeader;
13 import javax.sip.message.Request; 15 import javax.sip.message.Request;
@@ -34,6 +36,7 @@ import com.genersoft.iot.vmp.service.IDeviceAlarmService; @@ -34,6 +36,7 @@ import com.genersoft.iot.vmp.service.IDeviceAlarmService;
34 import com.genersoft.iot.vmp.storager.IRedisCatchStorage; 36 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
35 import com.genersoft.iot.vmp.storager.IVideoManagerStorager; 37 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
36 import com.genersoft.iot.vmp.utils.GpsUtil; 38 import com.genersoft.iot.vmp.utils.GpsUtil;
  39 +import com.genersoft.iot.vmp.utils.SipUtils;
37 import com.genersoft.iot.vmp.utils.SpringBeanFactory; 40 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
38 import com.genersoft.iot.vmp.utils.redis.RedisUtil; 41 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
39 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; 42 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
@@ -166,18 +169,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -166,18 +169,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
166 */ 169 */
167 private void processMessageMobilePosition(RequestEvent evt) { 170 private void processMessageMobilePosition(RequestEvent evt) {
168 try { 171 try {
169 - Element rootElement = getRootElement(evt); 172 + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
  173 + Device device = storager.queryVideoDevice(deviceId);
  174 + if (device == null) {
  175 + logger.warn("处理MobilePosition移动位置消息时未找到设备信息");
  176 + return;
  177 + }
  178 + Element rootElement = getRootElement(evt, device.getCharset());
  179 +
170 MobilePosition mobilePosition = new MobilePosition(); 180 MobilePosition mobilePosition = new MobilePosition();
171 Element deviceIdElement = rootElement.element("DeviceID"); 181 Element deviceIdElement = rootElement.element("DeviceID");
172 - String deviceId = deviceIdElement.getTextTrim().toString();  
173 - Device device = storager.queryVideoDevice(deviceId);  
174 - if (device != null) {  
175 - rootElement = getRootElement(evt, device.getCharset());  
176 - if (!StringUtils.isEmpty(device.getName())) {  
177 - mobilePosition.setDeviceName(device.getName());  
178 - } 182 + if (!StringUtils.isEmpty(device.getName())) {
  183 + mobilePosition.setDeviceName(device.getName());
179 } 184 }
180 - mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID")); 185 + mobilePosition.setDeviceId(deviceId);
  186 + mobilePosition.setChannelId(XmlUtil.getText(rootElement, "DeviceID"));
181 mobilePosition.setTime(XmlUtil.getText(rootElement, "Time")); 187 mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
182 mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude"))); 188 mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
183 mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude"))); 189 mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
@@ -691,16 +697,18 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -691,16 +697,18 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
691 */ 697 */
692 private void processMessageAlarm(RequestEvent evt) { 698 private void processMessageAlarm(RequestEvent evt) {
693 try { 699 try {
694 - Element rootElement = getRootElement(evt);  
695 - Element deviceIdElement = rootElement.element("DeviceID");  
696 - String deviceId = deviceIdElement.getText().toString();  
697 - // 回复200 OK  
698 - responseAck(evt);  
699 - 700 + String deviceId = SipUtils.getUserIdFromFromHeader(evt.getRequest());
700 Device device = storager.queryVideoDevice(deviceId); 701 Device device = storager.queryVideoDevice(deviceId);
701 if (device == null) { 702 if (device == null) {
  703 + logger.warn("处理alarm设备报警信息未找到设备信息");
702 return; 704 return;
703 } 705 }
  706 + Element rootElement = getRootElement(evt, device.getCharset());
  707 + Element deviceIdElement = rootElement.element("DeviceID");
  708 + String channelId = deviceIdElement.getText().toString();
  709 + // 回复200 OK
  710 + responseAck(evt);
  711 +
704 if (device.getCharset() != null) { 712 if (device.getCharset() != null) {
705 rootElement = getRootElement(evt, device.getCharset()); 713 rootElement = getRootElement(evt, device.getCharset());
706 } 714 }
@@ -708,6 +716,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -708,6 +716,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
708 if (rootElement.getName().equals("Notify")) { // 处理报警通知 716 if (rootElement.getName().equals("Notify")) { // 处理报警通知
709 DeviceAlarm deviceAlarm = new DeviceAlarm(); 717 DeviceAlarm deviceAlarm = new DeviceAlarm();
710 deviceAlarm.setDeviceId(deviceId); 718 deviceAlarm.setDeviceId(deviceId);
  719 + deviceAlarm.setChannelId(channelId);
711 deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority")); 720 deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
712 deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod")); 721 deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
713 deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime")); 722 deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
@@ -792,7 +801,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -792,7 +801,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
792 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); 801 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
793 ServerTransaction serverTransaction = getServerTransaction(evt); 802 ServerTransaction serverTransaction = getServerTransaction(evt);
794 serverTransaction.sendResponse(response); 803 serverTransaction.sendResponse(response);
795 - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); 804 + if (serverTransaction.getDialog() != null) {
  805 + serverTransaction.getDialog().delete();
  806 + }
796 } 807 }
797 808
798 // if (device != null && device.getOnline() == 1) { 809 // if (device != null && device.getOnline() == 1) {
@@ -1006,7 +1017,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -1006,7 +1017,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
1006 Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest()); 1017 Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
1007 ServerTransaction serverTransaction = getServerTransaction(evt); 1018 ServerTransaction serverTransaction = getServerTransaction(evt);
1008 serverTransaction.sendResponse(response); 1019 serverTransaction.sendResponse(response);
1009 - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); 1020 + if (serverTransaction.getDialog() != null) {
  1021 + serverTransaction.getDialog().delete();
  1022 + }
1010 } 1023 }
1011 1024
1012 /*** 1025 /***
@@ -1020,7 +1033,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -1020,7 +1033,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
1020 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest()); 1033 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
1021 ServerTransaction serverTransaction = getServerTransaction(evt); 1034 ServerTransaction serverTransaction = getServerTransaction(evt);
1022 serverTransaction.sendResponse(response); 1035 serverTransaction.sendResponse(response);
1023 - if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete(); 1036 + if (serverTransaction.getDialog() != null) {
  1037 + serverTransaction.getDialog().delete();
  1038 + }
1024 } 1039 }
1025 1040
1026 private Element getRootElement(RequestEvent evt) throws DocumentException { 1041 private Element getRootElement(RequestEvent evt) throws DocumentException {
@@ -1029,7 +1044,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor { @@ -1029,7 +1044,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
1029 } 1044 }
1030 1045
1031 private Element getRootElement(RequestEvent evt, String charset) throws DocumentException { 1046 private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
1032 - if (charset == null) charset = "gb2312"; 1047 + if (charset == null) {
  1048 + charset = "gb2312";
  1049 + }
1033 Request request = evt.getRequest(); 1050 Request request = evt.getRequest();
1034 SAXReader reader = new SAXReader(); 1051 SAXReader reader = new SAXReader();
1035 reader.setEncoding(charset); 1052 reader.setEncoding(charset);
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceAlarmMapper.java
@@ -15,8 +15,8 @@ import java.util.List; @@ -15,8 +15,8 @@ import java.util.List;
15 @Repository 15 @Repository
16 public interface DeviceAlarmMapper { 16 public interface DeviceAlarmMapper {
17 17
18 - @Insert("INSERT INTO device_alarm (deviceId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " +  
19 - "VALUES ('${deviceId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')") 18 + @Insert("INSERT INTO device_alarm (deviceId, channelId, alarmPriority, alarmMethod, alarmTime, alarmDescription, longitude, latitude, alarmType ) " +
  19 + "VALUES ('${deviceId}', '${channelId}', '${alarmPriority}', '${alarmMethod}', '${alarmTime}', '${alarmDescription}', ${longitude}, ${latitude}, '${alarmType}')")
20 int add(DeviceAlarm alarm); 20 int add(DeviceAlarm alarm);
21 21
22 22
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMobilePositionMapper.java
@@ -10,8 +10,8 @@ import org.apache.ibatis.annotations.*; @@ -10,8 +10,8 @@ import org.apache.ibatis.annotations.*;
10 //@Repository 10 //@Repository
11 public interface DeviceMobilePositionMapper { 11 public interface DeviceMobilePositionMapper {
12 12
13 - @Insert("INSERT INTO device_mobile_position (deviceId, deviceName, time, longitude, latitude, altitude, speed, direction, reportSource, geodeticSystem, cnLng, cnLat) " +  
14 - "VALUES ('${deviceId}', '${deviceName}', '${time}', ${longitude}, ${latitude}, ${altitude}, ${speed}, ${direction}, '${reportSource}', '${geodeticSystem}', '${cnLng}', '${cnLat}')") 13 + @Insert("INSERT INTO device_mobile_position (deviceId,channelId, deviceName, time, longitude, latitude, altitude, speed, direction, reportSource, geodeticSystem, cnLng, cnLat) " +
  14 + "VALUES ('${deviceId}','${channelId}', '${deviceName}', '${time}', ${longitude}, ${latitude}, ${altitude}, ${speed}, ${direction}, '${reportSource}', '${geodeticSystem}', '${cnLng}', '${cnLat}')")
15 int insertNewPosition(MobilePosition mobilePosition); 15 int insertNewPosition(MobilePosition mobilePosition);
16 16
17 @Select(value = {" <script>" + 17 @Select(value = {" <script>" +
src/main/java/com/genersoft/iot/vmp/utils/SipUtils.java 0 → 100644
  1 +package com.genersoft.iot.vmp.utils;
  2 +
  3 +import gov.nist.javax.sip.address.AddressImpl;
  4 +import gov.nist.javax.sip.address.SipUri;
  5 +
  6 +import javax.sip.header.FromHeader;
  7 +import javax.sip.message.Request;
  8 +
  9 +/**
  10 + * @author panlinlin
  11 + * @version 1.0.0
  12 + * @Description JAIN SIP的工具类
  13 + * @createTime 2021年09月27日 15:12:00
  14 + */
  15 +public class SipUtils {
  16 +
  17 + public static String getUserIdFromFromHeader(Request request) {
  18 + FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
  19 + AddressImpl address = (AddressImpl)fromHeader.getAddress();
  20 + SipUri uri = (SipUri) address.getURI();
  21 + return uri.getUser();
  22 + }
  23 +}
src/main/resources/wvp.sqlite
No preview for this file type