添加utf-8解析设备信息

This commit is contained in:
648540858
2021-09-13 16:08:40 +08:00
parent 69734af3ba
commit 5e8a7ce21e
11 changed files with 244 additions and 16 deletions

View File

@@ -1,5 +1,7 @@
package com.genersoft.iot.vmp.gb28181.auth;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -14,13 +16,17 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
@Component
public class RegisterLogicHandler {
private Logger logger = LoggerFactory.getLogger(RegisterLogicHandler.class);
@Autowired
private SIPCommander cmder;
public void onRegister(Device device) {
// TODO 后续处理,只有第一次注册时调用查询设备信息如需更新调用更新API接口
cmder.deviceInfoQuery(device);
cmder.catalogQuery(device, null);
// 只有第一次注册时调用查询设备信息如需更新调用更新API接口
if (device.isFirsRegister()) {
logger.info("[{}] 首次注册,查询设备信息以及通道信息", device.getDeviceId());
cmder.deviceInfoQuery(device);
cmder.catalogQuery(device, null);
}
}
}

View File

@@ -99,6 +99,18 @@ public class Device {
*/
private String mediaServerId;
/**
* 首次注册
*/
private boolean firsRegister;
/**
* 字符集, 支持 utf-8 与 gb2312
*/
private String charset ;
public String getDeviceId() {
return deviceId;
}
@@ -242,4 +254,20 @@ public class Device {
public void setMediaServerId(String mediaServerId) {
this.mediaServerId = mediaServerId;
}
public boolean isFirsRegister() {
return firsRegister;
}
public void setFirsRegister(boolean firsRegister) {
this.firsRegister = firsRegister;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
}

View File

@@ -172,6 +172,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
String deviceId = deviceIdElement.getTextTrim().toString();
Device device = storager.queryVideoDevice(deviceId);
if (device != null) {
rootElement = getRootElement(evt, device.getCharset());
if (!StringUtils.isEmpty(device.getName())) {
mobilePosition.setDeviceName(device.getName());
}
@@ -449,8 +450,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Element rootElement = getRootElement(evt);
String requestName = rootElement.getName();
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getTextTrim().toString();
String deviceId = deviceIdElement.getTextTrim();
Device device = storager.queryVideoDevice(deviceId);
if (device != null ) {
rootElement = getRootElement(evt, device.getCharset());
}
if (requestName.equals("Query")) {
logger.info("接收到DeviceInfo查询消息");
FromHeader fromHeader = (FromHeader) evt.getRequest().getHeader(FromHeader.NAME);
@@ -470,7 +474,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
if (device == null) {
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"));
@@ -569,12 +575,14 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
} else {
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
deviceListElement = getRootElement(evt, device.getCharset()).element("DeviceList");
Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
if (deviceListIterator != null) {
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
// 遍历DeviceList
while (deviceListIterator.hasNext()) {
Element itemDevice = deviceListIterator.next();
@@ -693,6 +701,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
if (device == null) {
return;
}
if (device.getCharset() != null) {
rootElement = getRootElement(evt, device.getCharset());
}
if (rootElement.getName().equals("Notify")) { // 处理报警通知
DeviceAlarm deviceAlarm = new DeviceAlarm();
@@ -816,6 +827,10 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
Element rootElement = getRootElement(evt);
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText().toString();
Device device = storager.queryVideoDevice(deviceId);
if (device != null ) {
rootElement = getRootElement(evt, device.getCharset());
}
recordInfo.setDeviceId(deviceId);
recordInfo.setName(XmlUtil.getText(rootElement, "Name"));
if (XmlUtil.getText(rootElement, "SumNum")== null || XmlUtil.getText(rootElement, "SumNum") =="") {
@@ -1009,9 +1024,15 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
}
private Element getRootElement(RequestEvent evt) throws DocumentException {
return getRootElement(evt, "gb2312");
}
private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
if (charset == null) charset = "gb2312";
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
reader.setEncoding("gbk");
reader.setEncoding(charset);
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
return xml.getRootElement();
}

View File

@@ -156,6 +156,7 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
if (device == null) {
return;
}
rootElement = getRootElement(evt, device.getCharset());
DeviceAlarm deviceAlarm = new DeviceAlarm();
deviceAlarm.setDeviceId(deviceId);
deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
@@ -218,6 +219,9 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
Element deviceIdElement = rootElement.element("DeviceID");
String deviceId = deviceIdElement.getText();
Device device = storager.queryVideoDevice(deviceId);
if (device != null ) {
rootElement = getRootElement(evt, device.getCharset());
}
Element deviceListElement = rootElement.element("DeviceList");
if (deviceListElement == null) {
return;
@@ -347,11 +351,14 @@ public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
serverTransaction.sendResponse(response);
if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
}
private Element getRootElement(RequestEvent evt) throws DocumentException {
return getRootElement(evt, "gb2312");
}
private Element getRootElement(RequestEvent evt, String charset) throws DocumentException {
if (charset == null) charset = "gb2312";
Request request = evt.getRequest();
SAXReader reader = new SAXReader();
reader.setEncoding("gbk");
reader.setEncoding(charset);
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
return xml.getRootElement();
}

View File

@@ -134,7 +134,9 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
if (device == null) {
device = new Device();
device.setStreamMode("UDP");
device.setCharset("gb2312");
device.setDeviceId(deviceId);
device.setFirsRegister(true);
}
device.setIp(received);
device.setPort(rPort);

View File

@@ -32,6 +32,7 @@ public interface DeviceMapper {
"keepaliveTime," +
"createTime," +
"updateTime," +
"charset," +
"online" +
") VALUES (" +
"#{deviceId}," +
@@ -49,6 +50,7 @@ public interface DeviceMapper {
"#{keepaliveTime}," +
"#{createTime}," +
"#{updateTime}," +
"#{charset}," +
"#{online}" +
")")
int add(Device device);
@@ -69,6 +71,7 @@ public interface DeviceMapper {
"<if test=\"registerTime != null\">, registerTime='${registerTime}'</if>" +
"<if test=\"keepaliveTime != null\">, keepaliveTime='${keepaliveTime}'</if>" +
"<if test=\"expires != null\">, expires=${expires}</if>" +
"<if test=\"charset != null\">, charset='${charset}'</if>" +
"WHERE deviceId='${deviceId}'"+
" </script>"})
int update(Device device);

View File

@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.gb28181.device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.slf4j.Logger;
@@ -22,6 +23,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import javax.sip.message.Response;
import java.io.UnsupportedEncodingException;
@Api(tags = "国标设备查询", value = "国标设备查询")
@SuppressWarnings("rawtypes")
@@ -273,6 +275,32 @@ public class DeviceQuery {
return new ResponseEntity<>(null,HttpStatus.OK);
}
/**
* 更新设备信息
* @param device 设备信息
* @return
*/
@ApiOperation("更新设备信息")
@ApiImplicitParams({
@ApiImplicitParam(name = "device", value = "设备信息", required = true, dataTypeClass = Device.class)
})
@PostMapping("/device/update/")
public ResponseEntity<WVPResult<String>> updateDevice(Device device){
if (device != null && device.getDeviceId() != null) {
Device deviceInStore = storager.queryVideoDevice(device.getDeviceId());
if (!StringUtils.isEmpty(device.getName())) deviceInStore.setName(device.getName());
if (!StringUtils.isEmpty(device.getCharset())) deviceInStore.setCharset(device.getCharset());
if (!StringUtils.isEmpty(device.getMediaServerId())) deviceInStore.setMediaServerId(device.getMediaServerId());
storager.updateDevice(deviceInStore);
cmder.deviceInfoQuery(deviceInStore);
}
WVPResult<String> result = new WVPResult<>();
result.setCode(0);
result.setMsg("success");
return new ResponseEntity<>(result,HttpStatus.OK);
}
/**
* 设备状态查询请求API接口
*

Binary file not shown.