diff --git a/sql/mysql.sql b/sql/mysql.sql index 5524e321..90393e67 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -23,7 +23,8 @@ create table device updateTime varchar(50) not null, port int not null, expires int not null, - hostAddress varchar(50) not null + hostAddress varchar(50) not null, + charset varchar(50) not null ); create table device_channel diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/auth/RegisterLogicHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/auth/RegisterLogicHandler.java index 6fe63cc5..01b0a129 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/auth/RegisterLogicHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/auth/RegisterLogicHandler.java @@ -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); + } } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java index cf939cfe..bfbf5477 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/Device.java @@ -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; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java index db5f05b2..6f38e560 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java @@ -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 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(); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java index b1c4922d..4c177697 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/NotifyRequestProcessor.java @@ -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(); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java index 4034d578..68299f28 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/RegisterRequestProcessor.java @@ -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); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java index c70eda3c..68ad28df 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceMapper.java @@ -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 { ", registerTime='${registerTime}'" + ", keepaliveTime='${keepaliveTime}'" + ", expires=${expires}" + + ", charset='${charset}'" + "WHERE deviceId='${deviceId}'"+ " "}) int update(Device device); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java index 02894cc3..cb08ba38 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceQuery.java @@ -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> 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 result = new WVPResult<>(); + result.setCode(0); + result.setMsg("success"); + return new ResponseEntity<>(result,HttpStatus.OK); + } + /** * 设备状态查询请求API接口 * diff --git a/src/main/resources/wvp.sqlite b/src/main/resources/wvp.sqlite index 228a96a3..b95368d3 100644 Binary files a/src/main/resources/wvp.sqlite and b/src/main/resources/wvp.sqlite differ diff --git a/web_src/src/components/DeviceList.vue b/web_src/src/components/DeviceList.vue index 8a212110..7644a963 100644 --- a/web_src/src/components/DeviceList.vue +++ b/web_src/src/components/DeviceList.vue @@ -60,7 +60,7 @@ 通道 定位 - 控制 + 编辑 删除 @@ -76,7 +76,7 @@ layout="total, sizes, prev, pager, next" :total="total"> - + @@ -84,10 +84,12 @@