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 66 id int auto_increment
67 67 primary key,
68 68 deviceId varchar(50) not null,
  69 + channelId varchar(50) not null,
69 70 alarmPriority varchar(50) not null,
70 71 alarmMethod varchar(50),
71 72 alarmTime varchar(50) not null,
... ... @@ -92,6 +93,7 @@ create table log
92 93 create table device_mobile_position
93 94 (
94 95 deviceId varchar(50) not null,
  96 + channelId varchar(50) not null,
95 97 deviceName varchar(255) null,
96 98 time varchar(50) not null,
97 99 longitude double not null,
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/bean/DeviceAlarm.java
... ... @@ -14,6 +14,11 @@ public class DeviceAlarm {
14 14 private String deviceId;
15 15  
16 16 /**
  17 + * 通道Id
  18 + */
  19 + private String channelId;
  20 +
  21 + /**
17 22 * 报警级别, 1为一级警情, 2为二级警情, 3为三级警情, 4为四级 警情-
18 23 */
19 24 private String alarmPriority;
... ... @@ -121,4 +126,12 @@ public class DeviceAlarm {
121 126 public void setAlarmType(String alarmType) {
122 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 13 private String deviceId;
14 14  
15 15 /**
  16 + * 通道Id
  17 + */
  18 + private String channelId;
  19 +
  20 + /**
16 21 * 设备名称
17 22 */
18 23 private String deviceName;
... ... @@ -163,4 +168,12 @@ public class MobilePosition {
163 168 public void setCnLat(String cnLat) {
164 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 5 import java.util.*;
6 6  
7 7 import javax.sip.*;
  8 +import javax.sip.address.Address;
8 9 import javax.sip.address.SipURI;
9 10  
10 11 import javax.sip.header.FromHeader;
  12 +import javax.sip.header.Header;
11 13 import javax.sip.header.HeaderAddress;
12 14 import javax.sip.header.ToHeader;
13 15 import javax.sip.message.Request;
... ... @@ -34,6 +36,7 @@ import com.genersoft.iot.vmp.service.IDeviceAlarmService;
34 36 import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
35 37 import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
36 38 import com.genersoft.iot.vmp.utils.GpsUtil;
  39 +import com.genersoft.iot.vmp.utils.SipUtils;
37 40 import com.genersoft.iot.vmp.utils.SpringBeanFactory;
38 41 import com.genersoft.iot.vmp.utils.redis.RedisUtil;
39 42 import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
... ... @@ -166,18 +169,21 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
166 169 */
167 170 private void processMessageMobilePosition(RequestEvent evt) {
168 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 180 MobilePosition mobilePosition = new MobilePosition();
171 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 187 mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
182 188 mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
183 189 mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
... ... @@ -691,16 +697,18 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
691 697 */
692 698 private void processMessageAlarm(RequestEvent evt) {
693 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 701 Device device = storager.queryVideoDevice(deviceId);
701 702 if (device == null) {
  703 + logger.warn("处理alarm设备报警信息未找到设备信息");
702 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 712 if (device.getCharset() != null) {
705 713 rootElement = getRootElement(evt, device.getCharset());
706 714 }
... ... @@ -708,6 +716,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
708 716 if (rootElement.getName().equals("Notify")) { // 处理报警通知
709 717 DeviceAlarm deviceAlarm = new DeviceAlarm();
710 718 deviceAlarm.setDeviceId(deviceId);
  719 + deviceAlarm.setChannelId(channelId);
711 720 deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
712 721 deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
713 722 deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
... ... @@ -792,7 +801,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
792 801 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
793 802 ServerTransaction serverTransaction = getServerTransaction(evt);
794 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 809 // if (device != null && device.getOnline() == 1) {
... ... @@ -1006,7 +1017,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
1006 1017 Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
1007 1018 ServerTransaction serverTransaction = getServerTransaction(evt);
1008 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 1033 Response response = getMessageFactory().createResponse(Response.NOT_FOUND, evt.getRequest());
1021 1034 ServerTransaction serverTransaction = getServerTransaction(evt);
1022 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 1041 private Element getRootElement(RequestEvent evt) throws DocumentException {
... ... @@ -1029,7 +1044,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
1029 1044 }
1030 1045  
1031 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 1050 Request request = evt.getRequest();
1034 1051 SAXReader reader = new SAXReader();
1035 1052 reader.setEncoding(charset);
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceAlarmMapper.java
... ... @@ -15,8 +15,8 @@ import java.util.List;
15 15 @Repository
16 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 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 10 //@Repository
11 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 15 int insertNewPosition(MobilePosition mobilePosition);
16 16  
17 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