优化国标级联的目录创建以及推送规则,优化接收目录规则,更加规范

This commit is contained in:
648540858
2023-06-19 18:42:36 +08:00
parent 8f5bbfa5c2
commit 8942ab0112
26 changed files with 8818 additions and 16508 deletions

View File

@@ -1,10 +0,0 @@
package com.genersoft.iot.vmp.gb28181.bean;
/**
* 目录结构类型
* @author lin
*/
public class TreeType {
public static final String BUSINESS_GROUP = "BusinessGroup";
public static final String CIVIL_CODE = "CivilCode";
}

View File

@@ -209,59 +209,149 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform {
// 行政区划分组只需要这两项就可以
catalogXml.append("<DeviceID>" + channel.getChannelId() + "</DeviceID>\r\n");
catalogXml.append("<Name>" + channel.getName() + "</Name>\r\n");
if (channel.getParentId() != null) {
// 业务分组加上这一项即可,提高兼容性,
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
// catalogXml.append("<ParentID>" + parentPlatform.getDeviceGBId() + "/" + channel.getParentId() + "</ParentID>\r\n");
}
if (channel.getChannelId().length() == 20 && Integer.parseInt(channel.getChannelId().substring(10, 13)) == 216) {
// 虚拟组织增加BusinessGroupID字段
catalogXml.append("<BusinessGroupID>" + channel.getParentId() + "</BusinessGroupID>\r\n");
}
if (!channel.getChannelId().equals(parentPlatform.getDeviceGBId())) {
catalogXml.append("<Parental>" + channel.getParental() + "</Parental>\r\n");
if (channel.getParental() == 0) {
catalogXml.append("<Status>" + (channel.getStatus() == 0 ? "OFF" : "ON") + "</Status>\r\n");
if (channel.getChannelId().length() <= 8) {
catalogXml.append("</Item>\r\n");
continue;
}else {
if (channel.getChannelId().length() != 20) {
continue;
}
}
if (channel.getParental() == 0) {
// 通道项
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
String civilCode = channel.getCivilCode() == null?parentPlatform.getAdministrativeDivision() : channel.getCivilCode();
if (channel.getChannelType() != 2) { // 业务分组/虚拟组织/行政区划 不设置以下属性
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
catalogXml.append("<Owner>" + parentPlatform.getDeviceGBId()+ "</Owner>\r\n");
catalogXml.append("<CivilCode>" + civilCode + "</CivilCode>\r\n");
if (channel.getAddress() == null) {
catalogXml.append("<Address></Address>\r\n");
}else {
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
}
catalogXml.append("<Block>" + channel.getBlock() + "</Block>\r\n");
catalogXml.append("<SafetyWay>" + channel.getSafetyWay() + "</SafetyWay>\r\n");
catalogXml.append("<CertNum>" + channel.getCertNum() + "</CertNum>\r\n");
catalogXml.append("<Certifiable>" + channel.getCertifiable() + "</Certifiable>\r\n");
catalogXml.append("<ErrCode>" + channel.getErrCode() + "</ErrCode>\r\n");
catalogXml.append("<EndTime>" + channel.getEndTime() + "</EndTime>\r\n");
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
catalogXml.append("<Password>" + channel.getPort() + "</Password>\r\n");
catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
catalogXml.append("<Status>" + (channel.getStatus() == 1?"ON":"OFF") + "</Status>\r\n");
catalogXml.append("<Longitude>" +
(channel.getLongitudeWgs84() != 0? channel.getLongitudeWgs84():channel.getLongitude())
+ "</Longitude>\r\n");
catalogXml.append("<Latitude>" +
(channel.getLatitudeWgs84() != 0? channel.getLatitudeWgs84():channel.getLatitude())
+ "</Latitude>\r\n");
switch (Integer.parseInt(channel.getChannelId().substring(10, 13))){
case 200:
// catalogXml.append("<Manufacturer>三永华通</Manufacturer>\r\n");
// GitUtil gitUtil = SpringBeanFactory.getBean("gitUtil");
// String model = (gitUtil == null || gitUtil.getBuildVersion() == null)?"1.0": gitUtil.getBuildVersion();
// catalogXml.append("<Model>" + model + "</Manufacturer>\r\n");
// catalogXml.append("<Owner>三永华通</Owner>\r\n");
if (channel.getCivilCode() != null) {
catalogXml.append("<CivilCode>"+channel.getCivilCode()+"</CivilCode>\r\n");
}else {
catalogXml.append("<CivilCode></CivilCode>\r\n");
}
catalogXml.append("<RegisterWay>1</RegisterWay>\r\n");
catalogXml.append("<Secrecy>0</Secrecy>\r\n");
break;
case 215:
if (!ObjectUtils.isEmpty(channel.getParentId())) {
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
}
break;
case 216:
if (!ObjectUtils.isEmpty(channel.getParentId())) {
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
}else {
catalogXml.append("<ParentID></ParentID>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getBusinessGroupId())) {
catalogXml.append("<BusinessGroupID>" + channel.getBusinessGroupId() + "</BusinessGroupID>\r\n");
}else {
catalogXml.append("<BusinessGroupID></BusinessGroupID>\r\n");
}
break;
default:
// 通道项
if (channel.getManufacture() != null) {
catalogXml.append("<Manufacturer>" + channel.getManufacture() + "</Manufacturer>\r\n");
}else {
catalogXml.append("<Manufacturer></Manufacturer>\r\n");
}
if (channel.getSecrecy() != null) {
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
}else {
catalogXml.append("<Secrecy></Secrecy>\r\n");
}
catalogXml.append("<RegisterWay>" + channel.getRegisterWay() + "</RegisterWay>\r\n");
if (channel.getModel() != null) {
catalogXml.append("<Model>" + channel.getModel() + "</Model>\r\n");
}else {
catalogXml.append("<Model></Model>\r\n");
}
if (channel.getOwner() != null) {
catalogXml.append("<Owner>" + channel.getOwner()+ "</Owner>\r\n");
}else {
catalogXml.append("<Owner></Owner>\r\n");
}
if (channel.getCivilCode() != null) {
catalogXml.append("<CivilCode>" + channel.getCivilCode() + "</CivilCode>\r\n");
}else {
catalogXml.append("<CivilCode></CivilCode>\r\n");
}
if (channel.getAddress() == null) {
catalogXml.append("<Address></Address>\r\n");
}else {
catalogXml.append("<Address>" + channel.getAddress() + "</Address>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getParentId())) {
catalogXml.append("<ParentID>" + channel.getParentId() + "</ParentID>\r\n");
}else {
catalogXml.append("<ParentID></ParentID>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getBlock())) {
catalogXml.append("<Block>" + channel.getBlock() + "</Block>\r\n");
}else {
catalogXml.append("<Block></Block>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getSafetyWay())) {
catalogXml.append("<SafetyWay>" + channel.getSafetyWay() + "</SafetyWay>\r\n");
}else {
catalogXml.append("<SafetyWay></SafetyWay>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getCertNum())) {
catalogXml.append("<CertNum>" + channel.getCertNum() + "</CertNum>\r\n");
}else {
catalogXml.append("<CertNum></CertNum>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getCertifiable())) {
catalogXml.append("<Certifiable>" + channel.getCertifiable() + "</Certifiable>\r\n");
}else {
catalogXml.append("<Certifiable></Certifiable>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getErrCode())) {
catalogXml.append("<ErrCode>" + channel.getErrCode() + "</ErrCode>\r\n");
}else {
catalogXml.append("<ErrCode></ErrCode>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getEndTime())) {
catalogXml.append("<EndTime>" + channel.getEndTime() + "</EndTime>\r\n");
}else {
catalogXml.append("<EndTime></EndTime>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getSecrecy())) {
catalogXml.append("<Secrecy>" + channel.getSecrecy() + "</Secrecy>\r\n");
}else {
catalogXml.append("<Secrecy></Secrecy>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getIpAddress())) {
catalogXml.append("<IPAddress>" + channel.getIpAddress() + "</IPAddress>\r\n");
}else {
catalogXml.append("<IPAddress></IPAddress>\r\n");
}
catalogXml.append("<Port>" + channel.getPort() + "</Port>\r\n");
if (!ObjectUtils.isEmpty(channel.getPassword())) {
catalogXml.append("<Password>" + channel.getPassword() + "</Password>\r\n");
}else {
catalogXml.append("<Password></Password>\r\n");
}
if (!ObjectUtils.isEmpty(channel.getPTZType())) {
catalogXml.append("<PTZType>" + channel.getPTZType() + "</PTZType>\r\n");
}else {
catalogXml.append("<PTZType></PTZType>\r\n");
}
catalogXml.append("<Status>" + (channel.getStatus() == 1?"ON":"OFF") + "</Status>\r\n");
catalogXml.append("<Longitude>" +
(channel.getLongitudeWgs84() != 0? channel.getLongitudeWgs84():channel.getLongitude())
+ "</Longitude>\r\n");
catalogXml.append("<Latitude>" +
(channel.getLatitudeWgs84() != 0? channel.getLatitudeWgs84():channel.getLatitude())
+ "</Latitude>\r\n");
break;
}
catalogXml.append("</Item>\r\n");
}
catalogXml.append("</Item>\r\n");
}
}

View File

@@ -191,6 +191,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements
logger.error("[命令发送失败] invite GONE: {}", e.getMessage());
}
return;
}else {
// TODO 可能漏回复消息
}
}
} else {

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.Device;
@@ -20,7 +21,10 @@ import org.springframework.stereotype.Component;
import javax.sip.RequestEvent;
import javax.sip.header.FromHeader;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -56,6 +60,9 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
@Autowired
private DynamicTask dynamicTask;
@Autowired
private CivilCodeFileConf civilCodeFileConf;
private final static String talkKey = "notify-request-for-catalog-task";
public void process(RequestEvent evt) {
@@ -96,7 +103,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
}else {
event = eventElement.getText().toUpperCase();
}
DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event);
DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event, civilCodeFileConf);
channel.setDeviceId(device.getDeviceId());
logger.info("[收到目录订阅]{}/{}", device.getDeviceId(), channel.getChannelId());

View File

@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -79,6 +80,9 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
@Autowired
private NotifyRequestForCatalogProcessor notifyRequestForCatalogProcessor;
@Autowired
private CivilCodeFileConf civilCodeFileConf;
private ConcurrentLinkedQueue<HandlerCatchData> taskQueue = new ConcurrentLinkedQueue<>();
@Qualifier("taskExecutor")
@@ -403,7 +407,7 @@ public class NotifyRequestProcessor extends SIPRequestProcessorParent implements
}else {
event = eventElement.getText().toUpperCase();
}
DeviceChannel channel = XmlUtil.channelContentHander(itemDevice, device, event);
DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event, civilCodeFileConf);
channel.setDeviceId(device.getDeviceId());
logger.info("[收到目录订阅]{}/{}", device.getDeviceId(), channel.getChannelId());
switch (event) {

View File

@@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.cmd;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
@@ -53,6 +54,9 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
@Autowired
private ThreadPoolTaskExecutor taskExecutor;
@Autowired
private CivilCodeFileConf civilCodeFileConf;
@Override
public void afterPropertiesSet() throws Exception {
responseMessageHandler.addHandler(cmdType, this);
@@ -100,6 +104,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
if (deviceListIterator != null) {
List<DeviceChannel> channelList = new ArrayList<>();
List<String> parentChannelIds = new ArrayList<>();
// 遍历DeviceList
while (deviceListIterator.hasNext()) {
Element itemDevice = deviceListIterator.next();
@@ -107,7 +112,7 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
if (channelDeviceElement == null) {
continue;
}
DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice, device, null);
DeviceChannel deviceChannel = XmlUtil.channelContentHandler(itemDevice, device, null, civilCodeFileConf);
deviceChannel = SipUtils.updateGps(deviceChannel, device.getGeoCoordSys());
deviceChannel.setDeviceId(take.getDevice().getDeviceId());

View File

@@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.gb28181.utils;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.CivilCodePo;
import com.genersoft.iot.vmp.conf.CivilCodeFileConf;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
@@ -192,7 +194,7 @@ public class XmlUtil {
CivilCode, BusinessGroup,VirtualOrganization,Other
}
public static DeviceChannel channelContentHander(Element itemDevice, Device device, String event){
public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event, CivilCodeFileConf civilCodeFileConf){
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setDeviceId(device.getDeviceId());
Element channdelIdElement = itemDevice.element("DeviceID");
@@ -210,208 +212,353 @@ public class XmlUtil {
// 除了ADD和update情况下需要识别全部内容
return deviceChannel;
}
ChannelType channelType = ChannelType.Other;
if (channelId.length() <= 8) {
channelType = ChannelType.CivilCode;
Element nameElement = itemDevice.element("Name");
if (nameElement != null) {
deviceChannel.setName(nameElement.getText());
}
if(channelId.length() <= 8) {
deviceChannel.setHasAudio(false);
}else {
if (channelId.length() == 20) {
int code = Integer.parseInt(channelId.substring(10, 13));
switch (code){
case 215:
channelType = ChannelType.BusinessGroup;
deviceChannel.setHasAudio(false);
break;
case 216:
channelType = ChannelType.VirtualOrganization;
deviceChannel.setHasAudio(false);
break;
case 136:
case 137:
case 138:
deviceChannel.setHasAudio(true);
break;
default:
deviceChannel.setHasAudio(false);
break;
}
}
}
Element channdelNameElement = itemDevice.element("Name");
String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim() : "";
deviceChannel.setName(channelName);
String civilCode = XmlUtil.getText(itemDevice, "CivilCode");
deviceChannel.setCivilCode(civilCode);
if (channelType == ChannelType.CivilCode && civilCode == null) {
deviceChannel.setParental(1);
// 行政区划如果没有传递具体值,则推测一个
if (channelId.length() > 2) {
deviceChannel.setCivilCode(channelId.substring(0, channelId.length() - 2));
}
}
if (channelType.equals(ChannelType.CivilCode)) {
// 行政区划其他字段没必要识别了,默认在线即可
deviceChannel.setStatus(1);
deviceChannel.setParental(1);
deviceChannel.setCreateTime(DateUtil.getNow());
deviceChannel.setUpdateTime(DateUtil.getNow());
return deviceChannel;
}
/**
* 行政区划展示设备树与业务分组展示设备树是两种不同的模式
* 行政区划展示设备树 各个目录之间主要靠deviceId做关联,摄像头通过CivilCode指定其属于那个行政区划;都是不超过十位的编号; 结构如下:
* 河北省
* --> 石家庄市
* --> 摄像头
*String parentId = XmlUtil.getText(itemDevice, "ParentID");
if (parentId != null) {
if (parentId.contains("/")) {
String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
String businessGroup = parentId.substring(0, parentId.indexOf("/"));
deviceChannel.setParentId(lastParentId);
}else {
deviceChannel.setParentId(parentId);
}
}
deviceCh --> 正定县
* --> 摄像头
* --> 摄像头
*
* 业务分组展示设备树是顶级是业务分组,其下的虚拟组织靠BusinessGroupID指定其所属的业务分组;摄像头通过ParentId来指定其所属于的虚拟组织:
* 业务分组
* --> 虚拟组织
* --> 摄像头
* --> 虚拟组织
* --> 摄像头
* --> 摄像头
*/
String parentId = XmlUtil.getText(itemDevice, "ParentID");
String businessGroupID = XmlUtil.getText(itemDevice, "BusinessGroupID");
if (parentId != null) {
if (parentId.contains("/")) {
String lastParentId = parentId.substring(parentId.lastIndexOf("/") + 1);
if (businessGroupID == null) {
businessGroupID = parentId.substring(0, parentId.indexOf("/"));
}
deviceChannel.setParentId(lastParentId);
CivilCodePo parentCode = civilCodeFileConf.getParentCode(channelId);
if (parentCode != null) {
deviceChannel.setParentId(parentCode.getCode());
deviceChannel.setCivilCode(parentCode.getCode());
}else {
deviceChannel.setParentId(parentId);
logger.warn("[xml解析] 无法确定行政区划{}的上级行政区划", channelId);
}
// 兼容设备通道信息中自己为自己父节点的情况
if (deviceChannel.getParentId().equals(deviceChannel.getChannelId())) {
deviceChannel.setParentId(null);
}
}
deviceChannel.setBusinessGroupId(businessGroupID);
if (channelType.equals(ChannelType.BusinessGroup) || channelType.equals(ChannelType.VirtualOrganization)) {
// 业务分组和虚拟组织 其他字段没必要识别了,默认在线即可
deviceChannel.setStatus(1);
deviceChannel.setParental(1);
deviceChannel.setCreateTime(DateUtil.getNow());
deviceChannel.setUpdateTime(DateUtil.getNow());
return deviceChannel;
}
Element statusElement = itemDevice.element("Status");
if (statusElement != null) {
String status = statusElement.getTextTrim().trim();
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
deviceChannel.setStatus(1);
}
if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
deviceChannel.setStatus(0);
}
}else {
deviceChannel.setStatus(1);
}
// 识别自带的目录标识
String parental = XmlUtil.getText(itemDevice, "Parental");
// 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1
if (!ObjectUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
deviceChannel.setParental(0);
}else {
deviceChannel.setParental(1);
}
deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
String safetyWay = XmlUtil.getText(itemDevice, "SafetyWay");
if (ObjectUtils.isEmpty(safetyWay)) {
deviceChannel.setSafetyWay(0);
} else {
deviceChannel.setSafetyWay(Integer.parseInt(safetyWay));
}
String registerWay = XmlUtil.getText(itemDevice, "RegisterWay");
if (ObjectUtils.isEmpty(registerWay)) {
deviceChannel.setRegisterWay(1);
} else {
deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
}
if (XmlUtil.getText(itemDevice, "Certifiable") == null
|| XmlUtil.getText(itemDevice, "Certifiable") == "") {
deviceChannel.setCertifiable(0);
} else {
deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
}
if (XmlUtil.getText(itemDevice, "ErrCode") == null
|| XmlUtil.getText(itemDevice, "ErrCode") == "") {
deviceChannel.setErrCode(0);
} else {
deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
}
deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") {
deviceChannel.setPort(0);
} else {
deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
}
String longitude = XmlUtil.getText(itemDevice, "Longitude");
if (NumericUtil.isDouble(longitude)) {
deviceChannel.setLongitude(Double.parseDouble(longitude));
} else {
deviceChannel.setLongitude(0.00);
}
String latitude = XmlUtil.getText(itemDevice, "Latitude");
if (NumericUtil.isDouble(latitude)) {
deviceChannel.setLatitude(Double.parseDouble(latitude));
} else {
deviceChannel.setLatitude(0.00);
}
deviceChannel.setGpsTime(DateUtil.getNow());
if (XmlUtil.getText(itemDevice, "PTZType") == null || "".equals(XmlUtil.getText(itemDevice, "PTZType"))) {
//兼容INFO中的信息
Element info = itemDevice.element("Info");
if(XmlUtil.getText(info, "PTZType") == null || "".equals(XmlUtil.getText(info, "PTZType"))){
deviceChannel.setPTZType(0);
}else{
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(info, "PTZType")));
if(channelId.length() != 20) {
logger.warn("[xml解析] 失败编号不符合国标28181定义 {}", channelId);
return null;
}
int code = Integer.parseInt(channelId.substring(10, 13));
if (code == 136 || code == 137 || code == 138) {
deviceChannel.setHasAudio(true);
}else {
deviceChannel.setHasAudio(false);
}
// 设备厂商
String manufacturer = getText(itemDevice, "Manufacturer");
// 设备型号
String model = getText(itemDevice, "Model");
// 设备归属
String owner = getText(itemDevice, "Owner");
// 行政区域
String civilCode = getText(itemDevice, "CivilCode");
// 虚拟组织所属的业务分组ID,业务分组根据特定的业务需求制定,一个业务分组包含一组特定的虚拟组织
String businessGroupID = getText(itemDevice, "BusinessGroupID");
// 父设备/区域/系统ID
String parentID = getText(itemDevice, "ParentID");
if (parentID != null && parentID.equalsIgnoreCase("null")) {
parentID = null;
}
// 注册方式(必选)缺省为1;1:符合IETFRFC3261标准的认证注册模式;2:基于口令的双向认证注册模式;3:基于数字证书的双向认证注册模式
String registerWay = getText(itemDevice, "RegisterWay");
// 保密属性(必选)缺省为0;0:不涉密,1:涉密
String secrecy = getText(itemDevice, "Secrecy");
// 安装地址
String address = getText(itemDevice, "Address");
switch (code){
case 200:
// 系统目录
if (!ObjectUtils.isEmpty(manufacturer)) {
deviceChannel.setManufacture(manufacturer);
}
if (!ObjectUtils.isEmpty(model)) {
deviceChannel.setModel(model);
}
if (!ObjectUtils.isEmpty(owner)) {
deviceChannel.setOwner(owner);
}
if (!ObjectUtils.isEmpty(civilCode)) {
deviceChannel.setCivilCode(civilCode);
deviceChannel.setParentId(civilCode);
}else {
if (!ObjectUtils.isEmpty(parentID)) {
deviceChannel.setParentId(parentID);
}
}
if (!ObjectUtils.isEmpty(address)) {
deviceChannel.setAddress(address);
}
deviceChannel.setStatus(1);
if (!ObjectUtils.isEmpty(registerWay)) {
try {
deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
}catch (NumberFormatException exception) {
logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay);
}
}
if (!ObjectUtils.isEmpty(secrecy)) {
deviceChannel.setSecrecy(secrecy);
}
return deviceChannel;
case 215:
// 业务分组
deviceChannel.setStatus(1);
if (!ObjectUtils.isEmpty(parentID)) {
if (!parentID.trim().equalsIgnoreCase(device.getDeviceId())) {
deviceChannel.setParentId(parentID);
}
}else {
logger.warn("[xml解析] 业务分组数据中缺少关键信息->ParentId");
if (!ObjectUtils.isEmpty(civilCode)) {
deviceChannel.setCivilCode(civilCode);
}
}
break;
case 216:
// 虚拟组织
deviceChannel.setStatus(1);
if (!ObjectUtils.isEmpty(businessGroupID)) {
deviceChannel.setBusinessGroupId(businessGroupID);
}
if (!ObjectUtils.isEmpty(parentID)) {
if (parentID.contains("/")) {
String[] parentIdArray = parentID.split("/");
parentID = parentIdArray[parentIdArray.length - 1];
}
deviceChannel.setParentId(parentID);
}else {
if (!ObjectUtils.isEmpty(businessGroupID)) {
deviceChannel.setParentId(businessGroupID);
}
}
break;
default:
// 设备目录
if (!ObjectUtils.isEmpty(manufacturer)) {
deviceChannel.setManufacture(manufacturer);
}
if (!ObjectUtils.isEmpty(model)) {
deviceChannel.setModel(model);
}
if (!ObjectUtils.isEmpty(owner)) {
deviceChannel.setOwner(owner);
}
if (!ObjectUtils.isEmpty(civilCode)) {
deviceChannel.setCivilCode(civilCode);
}
if (!ObjectUtils.isEmpty(businessGroupID)) {
deviceChannel.setBusinessGroupId(businessGroupID);
}
// 警区
String block = getText(itemDevice, "Block");
if (!ObjectUtils.isEmpty(block)) {
deviceChannel.setBlock(block);
}
if (!ObjectUtils.isEmpty(address)) {
deviceChannel.setAddress(address);
}
if (!ObjectUtils.isEmpty(secrecy)) {
deviceChannel.setSecrecy(secrecy);
}
// 当为设备时,是否有子设备(必选)1有,0没有
String parental = getText(itemDevice, "Parental");
if (!ObjectUtils.isEmpty(parental)) {
try {
// 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1
if (!ObjectUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
deviceChannel.setParental(0);
}else {
deviceChannel.setParental(1);
}
}catch (NumberFormatException e) {
logger.warn("[xml解析] 从通道数据获取 parental失败 {}", parental);
}
}
// 父设备/区域/系统ID
String realParentId = parentID;
if (!ObjectUtils.isEmpty(parentID)) {
if (parentID.contains("/")) {
String[] parentIdArray = parentID.split("/");
realParentId = parentIdArray[parentIdArray.length - 1];
}
deviceChannel.setParentId(realParentId);
}else {
if (!ObjectUtils.isEmpty(businessGroupID)) {
deviceChannel.setParentId(businessGroupID);
}else {
if (!ObjectUtils.isEmpty(civilCode)) {
deviceChannel.setParentId(civilCode);
}
}
}
// 注册方式
if (!ObjectUtils.isEmpty(registerWay)) {
try {
int registerWayInt = Integer.parseInt(registerWay);
deviceChannel.setRegisterWay(registerWayInt);
}catch (NumberFormatException exception) {
logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay);
deviceChannel.setRegisterWay(1);
}
}else {
deviceChannel.setRegisterWay(1);
}
// 信令安全模式(可选)缺省为0; 0:不采用;2:S/MIME 签名方式;3:S/MIME加密签名同时采用方式;4:数字摘要方式
String safetyWay = getText(itemDevice, "SafetyWay");
if (!ObjectUtils.isEmpty(safetyWay)) {
try {
deviceChannel.setSafetyWay(Integer.parseInt(safetyWay));
}catch (NumberFormatException e) {
logger.warn("[xml解析] 从通道数据获取 safetyWay失败 {}", safetyWay);
}
}
// 证书序列号(有证书的设备必选)
String certNum = getText(itemDevice, "CertNum");
if (!ObjectUtils.isEmpty(certNum)) {
deviceChannel.setCertNum(certNum);
}
// 证书有效标识(有证书的设备必选)缺省为0;证书有效标识:0:无效 1:有效
String certifiable = getText(itemDevice, "Certifiable");
if (!ObjectUtils.isEmpty(certifiable)) {
try {
deviceChannel.setCertifiable(Integer.parseInt(certifiable));
}catch (NumberFormatException e) {
logger.warn("[xml解析] 从通道数据获取 Certifiable失败 {}", certifiable);
}
}
// 无效原因码(有证书且证书无效的设备必选)
String errCode = getText(itemDevice, "ErrCode");
if (!ObjectUtils.isEmpty(errCode)) {
try {
deviceChannel.setErrCode(Integer.parseInt(errCode));
}catch (NumberFormatException e) {
logger.warn("[xml解析] 从通道数据获取 ErrCode失败 {}", errCode);
}
}
// 证书终止有效期(有证书的设备必选)
String endTime = getText(itemDevice, "EndTime");
if (!ObjectUtils.isEmpty(endTime)) {
deviceChannel.setEndTime(endTime);
}
// 设备/区域/系统IP地址
String ipAddress = getText(itemDevice, "IPAddress");
if (!ObjectUtils.isEmpty(ipAddress)) {
deviceChannel.setIpAddress(ipAddress);
}
// 设备/区域/系统端口
String port = getText(itemDevice, "Port");
if (!ObjectUtils.isEmpty(port)) {
try {
deviceChannel.setPort(Integer.parseInt(port));
}catch (NumberFormatException e) {
logger.warn("[xml解析] 从通道数据获取 Port失败 {}", port);
}
}
// 设备口令
String password = getText(itemDevice, "Password");
if (!ObjectUtils.isEmpty(password)) {
deviceChannel.setPassword(password);
}
// 设备状态
String status = getText(itemDevice, "Status");
if (status != null) {
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE") || status.equals("OK")) {
deviceChannel.setStatus(1);
}
if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
deviceChannel.setStatus(0);
}
}else {
deviceChannel.setStatus(1);
}
// 经度
String longitude = getText(itemDevice, "Longitude");
if (NumericUtil.isDouble(longitude)) {
deviceChannel.setLongitude(Double.parseDouble(longitude));
} else {
deviceChannel.setLongitude(0.00);
}
// 纬度
String latitude = getText(itemDevice, "Latitude");
if (NumericUtil.isDouble(latitude)) {
deviceChannel.setLatitude(Double.parseDouble(latitude));
} else {
deviceChannel.setLatitude(0.00);
}
deviceChannel.setGpsTime(DateUtil.getNow());
// -摄像机类型扩展,标识摄像机类型:1-球机;2-半球;3-固定枪机;4-遥控枪机。当目录项为摄像机时可选
String ptzType = getText(itemDevice, "PTZType");
if (ObjectUtils.isEmpty(ptzType)) {
//兼容INFO中的信息
Element info = itemDevice.element("Info");
String ptzTypeFromInfo = XmlUtil.getText(info, "PTZType");
if(!ObjectUtils.isEmpty(ptzTypeFromInfo)){
try {
deviceChannel.setPTZType(Integer.parseInt(ptzTypeFromInfo));
}catch (NumberFormatException e){
logger.warn("[xml解析] 从通道数据info中获取PTZType失败 {}", ptzTypeFromInfo);
}
}
} else {
try {
deviceChannel.setPTZType(Integer.parseInt(ptzType));
}catch (NumberFormatException e){
logger.warn("[xml解析] 从通道数据中获取PTZType失败 {}", ptzType);
}
}
// TODO 摄像机位置类型扩展。
// 1-省际检查站、
// 2-党政机关、
// 3-车站码头、
// 4-中心广场、
// 5-体育场馆、
// 6-商业中心、
// 7-宗教场所、
// 8-校园周边、
// 9-治安复杂区域、
// 10-交通干线。
// String positionType = getText(itemDevice, "PositionType");
// TODO 摄像机安装位置室外、室内属性。1-室外、2-室内。
// String roomType = getText(itemDevice, "RoomType");
// TODO 摄像机用途属性
// String useType = getText(itemDevice, "UseType");
// TODO 摄像机补光属性。1-无补光、2-红外补光、3-白光补光
// String supplyLightType = getText(itemDevice, "SupplyLightType");
// TODO 摄像机监视方位属性。1-东、2-西、3-南、4-北、5-东南、6-东北、7-西南、8-西北。
// String directionType = getText(itemDevice, "DirectionType");
// TODO 摄像机支持的分辨率,可有多个分辨率值,各个取值间以“/”分隔。分辨率取值参见附录 F中SDPf字段规定
// String resolution = getText(itemDevice, "Resolution");
// TODO 下载倍速范围(可选),各可选参数以“/”分隔,如设备支持1,2,4倍速下载则应写为“1/2/4
// String downloadSpeed = getText(itemDevice, "DownloadSpeed");
// TODO 空域编码能力,取值0:不支持;1:1级增强(1个增强层);2:2级增强(2个增强层);3:3级增强(3个增强层)
// String svcSpaceSupportMode = getText(itemDevice, "SVCSpaceSupportMode");
// TODO 时域编码能力,取值0:不支持;1:1级增强;2:2级增强;3:3级增强
// String svcTimeSupportMode = getText(itemDevice, "SVCTimeSupportMode");
deviceChannel.setSecrecy(secrecy);
break;
}
} else {
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
}
return deviceChannel;