临时提交

pull/1642/head
648540858 2024-06-25 16:45:31 +08:00
parent 306c42b4b7
commit 68fce9177f
14 changed files with 654 additions and 675 deletions

View File

@ -0,0 +1,38 @@
package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element;
import java.lang.reflect.InvocationTargetException;
@Data
@Slf4j
@EqualsAndHashCode(callSuper = true)
public class CatalogChannelEvent extends DeviceChannel{
private String event;
private DeviceChannel channel;
public static CatalogChannelEvent decode(Element element) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
Element eventElement = element.element("Event");
CatalogChannelEvent catalogChannelEvent = new CatalogChannelEvent();
if (eventElement != null) {
catalogChannelEvent.setEvent(eventElement.getText());
}else {
catalogChannelEvent.setEvent(CatalogEvent.ADD);
}
DeviceChannel deviceChannel;
if (CatalogEvent.ADD.equalsIgnoreCase(catalogChannelEvent.getEvent()) ||
CatalogEvent.UPDATE.equalsIgnoreCase(catalogChannelEvent.getEvent()) ){
deviceChannel = DeviceChannel.decode(element);
}else {
deviceChannel = DeviceChannel.decodeWithOnlyDeviceId(element);
}
catalogChannelEvent.setChannel(deviceChannel);
return catalogChannelEvent;
}
}

View File

@ -1,9 +0,0 @@
package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.gb28181.utils.MessageElement;
public class CatalogEvent extends DeviceChannel{
@MessageElement("Event")
private String event;
}

View File

@ -1,257 +1,170 @@
package com.genersoft.iot.vmp.gb28181.bean; package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.gb28181.utils.MessageElement; import com.genersoft.iot.vmp.gb28181.utils.MessageElement;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.Element;
import java.lang.reflect.InvocationTargetException;
@Data @Data
@Slf4j
@Schema(description = "通道信息") @Schema(description = "通道信息")
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class DeviceChannel extends CommonGBChannel { public class DeviceChannel extends CommonGBChannel {
@Schema(description = "数据库自增ID")
private int id;
@MessageElement("DeviceID") @MessageElement("DeviceID")
@Schema(description = "编码") @Schema(description = "编码")
private String deviceId; private String deviceId;
@MessageElement("DeviceID") @MessageElement("Name")
@Schema(description = "名称") @Schema(description = "名称")
private String name; private String name;
@MessageElement("DeviceID") @MessageElement("Manufacturer")
@Schema(description = "设备厂商") @Schema(description = "设备厂商")
private String manufacturer; private String manufacturer;
@MessageElement("DeviceID") @MessageElement("Model")
@Schema(description = "设备型号") @Schema(description = "设备型号")
private String model; private String model;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("Owner")
@Schema(description = "设备归属") @Schema(description = "设备归属")
private String owner; private String owner;
@MessageElement("DeviceID") @MessageElement("CivilCode")
@Schema(description = "行政区域") @Schema(description = "行政区域")
private String civilCode; private String civilCode;
@MessageElement("DeviceID") @MessageElement("Block")
@Schema(description = "警区") @Schema(description = "警区")
private String block; private String block;
@MessageElement("DeviceID") @MessageElement("Address")
@Schema(description = "安装地址") @Schema(description = "安装地址")
private String address; private String address;
@MessageElement("DeviceID") @MessageElement("Parental")
@Schema(description = "是否有子设备") @Schema(description = "是否有子设备(必选)1有,0没有")
private Boolean parental; private Integer parental;
@MessageElement("DeviceID") @MessageElement("ParentID")
@Schema(description = "父节点ID") @Schema(description = "父节点ID")
private String parentId; private String parentId;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("SafetyWay")
@Schema(description = "信令安全模式") @Schema(description = "信令安全模式")
private Integer safetyWay; private Integer safetyWay;
@MessageElement("DeviceID") @MessageElement("RegisterWay")
@Schema(description = "注册方式") @Schema(description = "注册方式")
private Integer registerWay; private Integer registerWay;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("CertNum")
@Schema(description = "证书序列号") @Schema(description = "证书序列号")
private Integer certNum; private String certNum;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("Certifiable")
@Schema(description = "证书有效标识") @Schema(description = "证书有效标识, 缺省为0;证书有效标识:0:无效 1:有效")
private Integer certifiable; private Integer certifiable;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("ErrCode")
@Schema(description = "无效原因码(有证书且证书无效的设备必选)") @Schema(description = "无效原因码(有证书且证书无效的设备必选)")
private Integer errCode; private Integer errCode;
// 2016 // 2016
@MessageElement("DeviceID") @MessageElement("EndTime")
@Schema(description = "证书终止有效期(有证书且证书无效的设备必选)") @Schema(description = "证书终止有效期(有证书且证书无效的设备必选)")
private Integer endTime; private String endTime;
// 2022 @MessageElement("Secrecy")
@MessageElement("DeviceID")
@Schema(description = "摄像机安全能力等级代码")
private String securityLevelCode;
@MessageElement("DeviceID")
@Schema(description = "保密属性(必选)缺省为0;0-不涉密,1-涉密") @Schema(description = "保密属性(必选)缺省为0;0-不涉密,1-涉密")
private Integer secrecy; private Integer secrecy;
@MessageElement("DeviceID") @MessageElement("IPAddress")
@Schema(description = "设备/系统IPv4/IPv6地址") @Schema(description = "设备/系统IPv4/IPv6地址")
private String ipAddress; private String ipAddress;
@MessageElement("DeviceID") @MessageElement("Port")
@Schema(description = "设备/系统端口") @Schema(description = "设备/系统端口")
private Integer port; private Integer port;
@MessageElement("DeviceID") @MessageElement("Password")
@Schema(description = "设备口令") @Schema(description = "设备口令")
private String password; private String password;
@MessageElement("DeviceID") @MessageElement("Status")
@Schema(description = "设备状态") @Schema(description = "设备状态")
private Boolean status; private String status;
@MessageElement("DeviceID") @MessageElement("Longitude")
@Schema(description = "经度 WGS-84坐标系") @Schema(description = "经度 WGS-84坐标系")
private Double longitude; private Double longitude;
@MessageElement("DeviceID") @MessageElement("Latitude")
@Schema(description = ",纬度 WGS-84坐标系") @Schema(description = ",纬度 WGS-84坐标系")
private Double latitude; private Double latitude;
@MessageElement("DeviceID") @MessageElement("Info.PTZType")
@Schema(description = "虚拟组织所属的业务分组ID")
private String businessGroupId;
@MessageElement("DeviceID")
@Schema(description = "摄像机结构类型,标识摄像机类型: 1-球机; 2-半球; 3-固定枪机; 4-遥控枪机;5-遥控半球;6-多目设备的全景/拼接通道;7-多目设备的分割通道") @Schema(description = "摄像机结构类型,标识摄像机类型: 1-球机; 2-半球; 3-固定枪机; 4-遥控枪机;5-遥控半球;6-多目设备的全景/拼接通道;7-多目设备的分割通道")
private Integer ptzType; private Integer ptzType;
@MessageElement("DeviceID") @MessageElement("Info.PositionType")
@Schema(description = "摄像机光电成像类型。1-可见光成像;2-热成像;3-雷达成像;4-X光成像;5-深度光场成像;9-其他。可多值,") @Schema(description = "摄像机位置类型扩展。1-省际检查站、2-党政机关、3-车站码头、4-中心广场、5-体育场馆、" +
private String photoelectricImagingTyp; "6-商业中心、7-宗教场所、8-校园周边、9-治安复杂区域、10-交通干线")
private Integer positionType;
@MessageElement("DeviceID") @MessageElement("Info.RoomType")
@Schema(description = "摄像机采集部位类型")
private String capturePositionType;
@MessageElement("DeviceID")
@Schema(description = "摄像机安装位置室外、室内属性。1-室外、2-室内。") @Schema(description = "摄像机安装位置室外、室内属性。1-室外、2-室内。")
private Integer roomType; private Integer roomType;
// 2016 @MessageElement("Info.UseType")
@MessageElement("DeviceID") @Schema(description = "用途属性, 1-治安、2-交通、3-重点。")
@Schema(description = "用途属性")
private Integer useType; private Integer useType;
@MessageElement("DeviceID") @MessageElement("Info.SupplyLightType")
@Schema(description = "摄像机补光属性。1-无补光;2-红外补光;3-白光补光;4-激光补光;9-其他") @Schema(description = "摄像机补光属性。1-无补光;2-红外补光;3-白光补光;4-激光补光;9-其他")
private Integer supplyLightType; private Integer supplyLightType;
@MessageElement("DeviceID") @MessageElement("Info.DirectionType")
@Schema(description = "摄像机监视方位(光轴方向)属性。1-东(西向东)、2-西(东向西)、3-南(北向南)、4-北(南向北)、" + @Schema(description = "摄像机监视方位(光轴方向)属性。1-东(西向东)、2-西(东向西)、3-南(北向南)、4-北(南向北)、" +
"5-东南(西北到东南)、6-东北(西南到东北)、7-西南(东北到西南)、8-西北(东南到西北)") "5-东南(西北到东南)、6-东北(西南到东北)、7-西南(东北到西南)、8-西北(东南到西北)")
private Integer directionType; private Integer directionType;
@MessageElement("DeviceID") @MessageElement("Info.Resolution")
@Schema(description = "摄像机支持的分辨率,可多值") @Schema(description = "摄像机支持的分辨率,可多值")
private String resolution; private String resolution;
// 2022 @MessageElement("Info.BusinessGroupID")
@MessageElement("DeviceID") @Schema(description = "虚拟组织所属的业务分组ID")
@Schema(description = "摄像机支持的码流编号列表,用于实时点播时指定码流编号(可选)") private String businessGroupId;
private String streamNumberList;
@MessageElement("DeviceID") @MessageElement("Info.DownloadSpeed")
@Schema(description = "下载倍速(可选),可多值") @Schema(description = "下载倍速(可选),可多值")
private String downloadSpeed; private String downloadSpeed;
@MessageElement("DeviceID") @MessageElement("Info.SVCSpaceSupportMode")
@Schema(description = "空域编码能力,取值0-不支持;1-1级增强(1个增强层);2-2级增强(2个增强层);3-3级增强(3个增强层)") @Schema(description = "空域编码能力,取值0-不支持;1-1级增强(1个增强层);2-2级增强(2个增强层);3-3级增强(3个增强层)")
private Integer svcSpaceSupportMod; private Integer svcSpaceSupportMod;
@MessageElement("DeviceID") @MessageElement("Info.SVCTimeSupportMode")
@Schema(description = "时域编码能力,取值0-不支持;1-1级增强;2-2级增强;3-3级增强(可选)") @Schema(description = "时域编码能力,取值0-不支持;1-1级增强;2-2级增强;3-3级增强(可选)")
private Integer svcTimeSupportMode; private Integer svcTimeSupportMode;
// 2022
@MessageElement("DeviceID")
@Schema(description = " SSVC增强层与基本层比例能力 ")
private String ssvcRatioSupportList;
// 2022
@MessageElement("DeviceID")
@Schema(description = "移动采集设备类型(仅移动采集设备适用,必选);1-移动机器人载摄像机;2-执法记录仪;3-移动单兵设备;" +
"4-车载视频记录设备;5-无人机载摄像机;9-其他")
private Integer mobileDeviceType;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机水平视场角(可选),取值范围大于0度小于等于360度")
private Double horizontalFieldAngle;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机竖直视场角(可选),取值范围大于0度小于等于360度 ")
private Double verticalFieldAngle;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机可视距离(可选),单位:米")
private Double maxViewDistance;
// 2022
@MessageElement("DeviceID")
@Schema(description = "基层组织编码(必选,非基层建设时为“000000”)")
private String grassrootsCode;
// 2022
@MessageElement("DeviceID")
@Schema(description = "监控点位类型(当为摄像机时必选),1-一类视频监控点;2-二类视频监控点;3-三类视频监控点;9-其他点位。")
private Integer poType;
// 2022
@MessageElement("DeviceID")
@Schema(description = "点位俗称")
private String poCommonName;
// 2022
@MessageElement("DeviceID")
@Schema(description = "设备MAC地址(可选),用“XX-XX-XX-XX-XX-XX”格式表达")
private String mac;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机卡口功能类型,01-人脸卡口;02-人员卡口;03-机动车卡口;04-非机动车卡口;05-物品卡口;99-其他")
private String functionType;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机视频编码格式")
private String encodeType;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机安装使用时间")
private String installTime;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机所属管理单位名称")
private String managementUnit;
// 2022
@MessageElement("DeviceID")
@Schema(description = "摄像机所属管理单位联系人的联系方式(电话号码,可多值,用英文半角“/”分割)")
private String contactInfo;
// 2022
@MessageElement("DeviceID")
@Schema(description = "录像保存天数(可选)")
private Integer recordSaveDays;
// 2022
@MessageElement("DeviceID")
@Schema(description = "国民经济行业分类代码(可选)")
private String industrialClassification;
@Schema(description = "云台类型描述字符串") @Schema(description = "云台类型描述字符串")
private String ptzTypeText; private String ptzTypeText;
@ -306,4 +219,15 @@ public class DeviceChannel extends CommonGBChannel {
break; break;
} }
} }
public static DeviceChannel decode(Element element) throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
return XmlUtil.elementDecode(element, DeviceChannel.class);
}
public static DeviceChannel decodeWithOnlyDeviceId(Element element) {
Element deviceElement = element.element("DeviceID");
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setDeviceId(deviceElement.getText());
return deviceChannel;
}
} }

View File

@ -5,8 +5,7 @@ import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import org.slf4j.Logger; import lombok.extern.slf4j.Slf4j;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -23,11 +22,10 @@ import java.util.Map;
/** /**
* catalog * catalog
*/ */
@Slf4j
@Component @Component
public class CatalogEventLister implements ApplicationListener<CatalogEvent> { public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
private final static Logger logger = LoggerFactory.getLogger(CatalogEventLister.class);
@Autowired @Autowired
private IVideoManagerStorage storager; private IVideoManagerStorage storager;
@ -66,9 +64,9 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
if (event.getDeviceChannels() != null) { if (event.getDeviceChannels() != null) {
if (platforms.size() > 0) { if (platforms.size() > 0) {
for (DeviceChannel deviceChannel : event.getDeviceChannels()) { for (DeviceChannel deviceChannel : event.getDeviceChannels()) {
List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForGBWithGBId(deviceChannel.getChannelId(), platforms); List<ParentPlatform> parentPlatformsForGB = storager.queryPlatFormListForGBWithGBId(deviceChannel.getDeviceId(), platforms);
parentPlatformMap.put(deviceChannel.getChannelId(), parentPlatformsForGB); parentPlatformMap.put(deviceChannel.getDeviceId(), parentPlatformsForGB);
channelMap.put(deviceChannel.getChannelId(), deviceChannel); channelMap.put(deviceChannel.getDeviceId(), deviceChannel);
} }
} }
}else if (event.getGbStreams() != null) { }else if (event.getGbStreams() != null) {
@ -106,12 +104,12 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
} }
} }
if (deviceChannelList.size() > 0) { if (deviceChannelList.size() > 0) {
logger.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size()); log.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size());
try { try {
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), parentPlatform, deviceChannelList, subscribe, null); sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), parentPlatform, deviceChannelList, subscribe, null);
} catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException | } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
IllegalAccessException e) { IllegalAccessException e) {
logger.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage()); log.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
} }
} }
}else if (parentPlatformMap.keySet().size() > 0) { }else if (parentPlatformMap.keySet().size() > 0) {
@ -123,16 +121,16 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
if (subscribeInfo == null) { if (subscribeInfo == null) {
continue; continue;
} }
logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId); log.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId);
List<DeviceChannel> deviceChannelList = new ArrayList<>(); List<DeviceChannel> deviceChannelList = new ArrayList<>();
DeviceChannel deviceChannel = new DeviceChannel(); DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbId); deviceChannel.setDeviceId(gbId);
deviceChannelList.add(deviceChannel); deviceChannelList.add(deviceChannel);
try { try {
sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo, null); sipCommanderFroPlatform.sendNotifyForCatalogOther(event.getType(), platform, deviceChannelList, subscribeInfo, null);
} catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException | } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
IllegalAccessException e) { IllegalAccessException e) {
logger.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage()); log.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
} }
} }
} }
@ -157,12 +155,12 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
} }
} }
if (!deviceChannelList.isEmpty()) { if (!deviceChannelList.isEmpty()) {
logger.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size()); log.info("[Catalog事件: {}]平台:{},影响通道{}个", event.getType(), event.getPlatformId(), deviceChannelList.size());
try { try {
sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe, null); sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), parentPlatform, deviceChannelList, subscribe, null);
} catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException | } catch (InvalidArgumentException | ParseException | NoSuchFieldException | SipException |
IllegalAccessException e) { IllegalAccessException e) {
logger.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage()); log.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
} }
} }
}else if (!parentPlatformMap.keySet().isEmpty()) { }else if (!parentPlatformMap.keySet().isEmpty()) {
@ -174,7 +172,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
if (subscribeInfo == null) { if (subscribeInfo == null) {
continue; continue;
} }
logger.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId); log.info("[Catalog事件: {}]平台:{},影响通道{}", event.getType(), platform.getServerGBId(), gbId);
List<DeviceChannel> deviceChannelList = new ArrayList<>(); List<DeviceChannel> deviceChannelList = new ArrayList<>();
DeviceChannel deviceChannel = channelMap.get(gbId); DeviceChannel deviceChannel = channelMap.get(gbId);
deviceChannelList.add(deviceChannel); deviceChannelList.add(deviceChannel);
@ -187,7 +185,7 @@ public class CatalogEventLister implements ApplicationListener<CatalogEvent> {
sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), platform, deviceChannelList, subscribeInfo, null); sipCommanderFroPlatform.sendNotifyForCatalogAddOrUpdate(event.getType(), platform, deviceChannelList, subscribeInfo, null);
} catch (InvalidArgumentException | ParseException | NoSuchFieldException | } catch (InvalidArgumentException | ParseException | NoSuchFieldException |
SipException | IllegalAccessException e) { SipException | IllegalAccessException e) {
logger.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage()); log.error("[命令发送失败] 国标级联 Catalog通知: {}", e.getMessage());
} }
} }
} }

View File

@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.SipConfig;
import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.CatalogChannelEvent;
import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.HandlerCatchData; import com.genersoft.iot.vmp.gb28181.bean.HandlerCatchData;
@ -10,14 +11,12 @@ import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.service.IDeviceChannelService; import com.genersoft.iot.vmp.service.IDeviceChannelService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
import org.dom4j.Element; import org.dom4j.Element;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -25,6 +24,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.sip.RequestEvent; import javax.sip.RequestEvent;
import javax.sip.header.FromHeader; import javax.sip.header.FromHeader;
import java.lang.reflect.InvocationTargetException;
import java.nio.charset.Charset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -36,12 +37,10 @@ import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* SIP NOTIFY * SIP NOTIFY
*/ */
@Slf4j
@Component @Component
public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent { public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent {
private final static Logger logger = LoggerFactory.getLogger(NotifyRequestForCatalogProcessor.class);
private final List<DeviceChannel> updateChannelOnlineList = new CopyOnWriteArrayList<>(); private final List<DeviceChannel> updateChannelOnlineList = new CopyOnWriteArrayList<>();
private final List<DeviceChannel> updateChannelOfflineList = new CopyOnWriteArrayList<>(); private final List<DeviceChannel> updateChannelOfflineList = new CopyOnWriteArrayList<>();
private final Map<String, DeviceChannel> updateChannelMap = new ConcurrentHashMap<>(); private final Map<String, DeviceChannel> updateChannelMap = new ConcurrentHashMap<>();
@ -72,7 +71,7 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
@Transactional @Transactional
public void process(RequestEvent evt) { public void process(RequestEvent evt) {
if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) { if (taskQueue.size() >= userSetting.getMaxNotifyCountQueue()) {
logger.error("[notify-目录订阅] 待处理消息队列已满 {}返回486 BUSY_HERE消息不做处理", userSetting.getMaxNotifyCountQueue()); log.error("[notify-目录订阅] 待处理消息队列已满 {}返回486 BUSY_HERE消息不做处理", userSetting.getMaxNotifyCountQueue());
return; return;
} }
taskQueue.offer(new HandlerCatchData(evt, null, null)); taskQueue.offer(new HandlerCatchData(evt, null, null));
@ -95,12 +94,12 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
Device device = redisCatchStorage.getDevice(deviceId); Device device = redisCatchStorage.getDevice(deviceId);
if (device == null || !device.isOnLine()) { if (device == null || !device.isOnLine()) {
logger.warn("[收到目录订阅]{}, 但是设备已经离线", (device != null ? device.getDeviceId() : "")); log.warn("[收到目录订阅]{}, 但是设备已经离线", (device != null ? device.getDeviceId() : ""));
return; return;
} }
Element rootElement = getRootElement(evt, device.getCharset()); Element rootElement = getRootElement(evt, device.getCharset());
if (rootElement == null) { if (rootElement == null) {
logger.warn("[ 收到目录订阅 ] content cannot be null, {}", evt.getRequest()); log.warn("[ 收到目录订阅 ] content cannot be null, {}", evt.getRequest());
return; return;
} }
Element deviceListElement = rootElement.element("DeviceList"); Element deviceListElement = rootElement.element("DeviceList");
@ -113,132 +112,134 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
// 遍历DeviceList // 遍历DeviceList
while (deviceListIterator.hasNext()) { while (deviceListIterator.hasNext()) {
Element itemDevice = deviceListIterator.next(); Element itemDevice = deviceListIterator.next();
Element eventElement = itemDevice.element("Event"); CatalogChannelEvent catalogChannelEvent = null;
String event; try {
if (eventElement == null) { catalogChannelEvent = CatalogChannelEvent.decode(itemDevice);
logger.warn("[收到目录订阅]{}, 但是Event为空, 设为默认值 ADD", (device != null ? device.getDeviceId() : "")); if (catalogChannelEvent.getChannel() == null) {
event = CatalogEvent.ADD; log.info("[解析CatalogChannelEvent]成功:但是解析通道信息失败, 原文如下: \n{}", new String(evt.getRequest().getRawContent()));
} else {
event = eventElement.getText().toUpperCase();
}
DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, event);
if (channel == null) {
logger.info("[收到目录订阅]:但是解析失败 {}", new String(evt.getRequest().getRawContent()));
continue; continue;
} }
if (channel.getParentId() != null && channel.getParentId().equals(sipConfig.getId())) { } catch (InvocationTargetException | NoSuchMethodException | InstantiationException |
channel.setParentId(null); IllegalAccessException e) {
log.error("[解析CatalogChannelEvent]失败,", e);
log.error("[解析CatalogChannelEvent]失败原文: \n{}", new String(evt.getRequest().getRawContent(), Charset.forName(device.getCharset())));
continue;
} }
channel.setDeviceId(device.getDeviceId()); if (catalogChannelEvent == null) {
logger.info("[收到目录订阅]{}/{}", device.getDeviceId(), channel.getDeviceId()); continue;
switch (event) { }
log.info("[收到目录订阅]{}/{}-{}", device.getDeviceId(),
catalogChannelEvent.getChannel().getDeviceId(), catalogChannelEvent.getEvent());
switch (catalogChannelEvent.getEvent()) {
case CatalogEvent.ON: case CatalogEvent.ON:
// 上线 // 上线
logger.info("[收到通道上线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道上线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
updateChannelOnlineList.add(channel); updateChannelOnlineList.add(catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), true); redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);
} }
break; break;
case CatalogEvent.OFF: case CatalogEvent.OFF:
// 离线 // 离线
logger.info("[收到通道离线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道离线通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) { if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
logger.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道离线通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
} else { } else {
updateChannelOfflineList.add(channel); updateChannelOfflineList.add(catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false); redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
} }
} }
break; break;
case CatalogEvent.VLOST: case CatalogEvent.VLOST:
// 视频丢失 // 视频丢失
logger.info("[收到通道视频丢失通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道视频丢失通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) { if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
logger.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道视频丢失通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
} else { } else {
updateChannelOfflineList.add(channel); updateChannelOfflineList.add(catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false); redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
} }
} }
break; break;
case CatalogEvent.DEFECT: case CatalogEvent.DEFECT:
// 故障 // 故障
logger.info("[收到通道视频故障通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道视频故障通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
if (userSetting.getRefuseChannelStatusChannelFormNotify()) { if (userSetting.getRefuseChannelStatusChannelFormNotify()) {
logger.info("[收到通道视频故障通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到通道视频故障通知] 但是平台已配置拒绝此消息,来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
} else { } else {
updateChannelOfflineList.add(channel); updateChannelOfflineList.add(catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), channel.getChannelId(), false); redisCatchStorage.sendDeviceOrChannelStatus(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
} }
} }
break; break;
case CatalogEvent.ADD: case CatalogEvent.ADD:
// 增加 // 增加
logger.info("[收到增加通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到增加通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
// 判断此通道是否存在 // 判断此通道是否存在
DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId, channel.getChannelId()); DeviceChannel deviceChannel = deviceChannelService.getOne(deviceId, catalogChannelEvent.getChannel().getDeviceId());
if (deviceChannel != null) { if (deviceChannel != null) {
logger.info("[增加通道] 已存在,不发送通知只更新,设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[增加通道] 已存在,不发送通知只更新,设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
DeviceChannel channel = catalogChannelEvent.getChannel();
channel.setId(deviceChannel.getId()); channel.setId(deviceChannel.getId());
channel.setHasAudio(null); channel.setHasAudio(deviceChannel.getHasAudio());
updateChannelMap.put(channel.getChannelId(), channel); channel.setUpdateTime(DateUtil.getNow());
updateChannelMap.put(catalogChannelEvent.getChannel().getDeviceId(), channel);
} else { } else {
addChannelMap.put(channel.getChannelId(), channel); addChannelMap.put(catalogChannelEvent.getChannel().getDeviceId(), catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true); redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);
} }
} }
break; break;
case CatalogEvent.DEL: case CatalogEvent.DEL:
// 删除 // 删除
logger.info("[收到删除通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到删除通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
deleteChannelList.add(channel); deleteChannelList.add(catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), false); redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), false);
} }
break; break;
case CatalogEvent.UPDATE: case CatalogEvent.UPDATE:
// 更新 // 更新
logger.info("[收到更新通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), channel.getChannelId()); log.info("[收到更新通道通知] 来自设备: {}, 通道 {}", device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId());
// 判断此通道是否存在 // 判断此通道是否存在
DeviceChannel deviceChannelForUpdate = deviceChannelService.getOne(deviceId, channel.getChannelId()); DeviceChannel deviceChannelForUpdate = deviceChannelService.getOne(deviceId, catalogChannelEvent.getChannel().getDeviceId());
if (deviceChannelForUpdate != null) { if (deviceChannelForUpdate != null) {
DeviceChannel channel = catalogChannelEvent.getChannel();
channel.setId(deviceChannelForUpdate.getId()); channel.setId(deviceChannelForUpdate.getId());
channel.setHasAudio(deviceChannelForUpdate.getHasAudio());
channel.setUpdateTime(DateUtil.getNow()); channel.setUpdateTime(DateUtil.getNow());
channel.setHasAudio(null); updateChannelMap.put(catalogChannelEvent.getChannel().getDeviceId(), channel);
updateChannelMap.put(channel.getChannelId(), channel);
} else { } else {
addChannelMap.put(channel.getChannelId(), channel); addChannelMap.put(catalogChannelEvent.getChannel().getDeviceId(), catalogChannelEvent.getChannel());
if (userSetting.getDeviceStatusNotify()) { if (userSetting.getDeviceStatusNotify()) {
// 发送redis消息 // 发送redis消息
redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), channel.getChannelId(), true); redisCatchStorage.sendChannelAddOrDelete(device.getDeviceId(), catalogChannelEvent.getChannel().getDeviceId(), true);
} }
} }
break; break;
default: default:
logger.warn("[ NotifyCatalog ] event not found {}", event); log.warn("[ NotifyCatalog ] event not found {}", catalogChannelEvent.getEvent());
} }
// 转发变化信息 // 转发变化信息
eventPublisher.catalogEventPublish(null, channel, event); eventPublisher.catalogEventPublish(null, catalogChannelEvent.getChannel(), catalogChannelEvent.getEvent());
} }
} }
} catch (DocumentException e) { } catch (DocumentException e) {
logger.error("未处理的异常 ", e); log.error("未处理的异常 ", e);
} }
} }
taskQueue.clear(); taskQueue.clear();
@ -255,33 +256,33 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
try { try {
executeSaveForAdd(); executeSaveForAdd();
} catch (Exception e) { } catch (Exception e) {
logger.error("[存储收到的增加通道] 异常: ", e ); log.error("[存储收到的增加通道] 异常: ", e );
} }
try { try {
executeSaveForOnline(); executeSaveForOnline();
} catch (Exception e) { } catch (Exception e) {
logger.error("[存储收到的通道上线] 异常: ", e ); log.error("[存储收到的通道上线] 异常: ", e );
} }
try { try {
executeSaveForOffline(); executeSaveForOffline();
} catch (Exception e) { } catch (Exception e) {
logger.error("[存储收到的通道离线] 异常: ", e ); log.error("[存储收到的通道离线] 异常: ", e );
} }
try { try {
executeSaveForUpdate(); executeSaveForUpdate();
} catch (Exception e) { } catch (Exception e) {
logger.error("[存储收到的更新通道] 异常: ", e ); log.error("[存储收到的更新通道] 异常: ", e );
} }
try { try {
executeSaveForDelete(); executeSaveForDelete();
} catch (Exception e) { } catch (Exception e) {
logger.error("[存储收到的删除通道] 异常: ", e ); log.error("[存储收到的删除通道] 异常: ", e );
} }
} }
private void executeSaveForUpdate(){ private void executeSaveForUpdate(){
if (!updateChannelMap.values().isEmpty()) { if (!updateChannelMap.values().isEmpty()) {
logger.info("[存储收到的更新通道], 数量: {}", updateChannelMap.size()); log.info("[存储收到的更新通道], 数量: {}", updateChannelMap.size());
ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(updateChannelMap.values()); ArrayList<DeviceChannel> deviceChannels = new ArrayList<>(updateChannelMap.values());
deviceChannelService.batchUpdateChannel(deviceChannels); deviceChannelService.batchUpdateChannel(deviceChannels);
updateChannelMap.clear(); updateChannelMap.clear();
@ -319,6 +320,6 @@ public class NotifyRequestForCatalogProcessor extends SIPRequestProcessorParent
@Scheduled(fixedRate = 10000) //每1秒执行一次 @Scheduled(fixedRate = 10000) //每1秒执行一次
public void execute(){ public void execute(){
logger.info("[待处理Notify-目录订阅消息数量]: {}", taskQueue.size()); log.info("[待处理Notify-目录订阅消息数量]: {}", taskQueue.size());
} }
} }

View File

@ -7,7 +7,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorP
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import gov.nist.javax.sip.message.SIPRequest; import gov.nist.javax.sip.message.SIPRequest;
import org.dom4j.DocumentException; import org.dom4j.DocumentException;
@ -114,8 +113,9 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
if (channelDeviceElement == null) { if (channelDeviceElement == null) {
continue; continue;
} }
DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, null); DeviceChannel channel = DeviceChannel.decode(itemDevice);
if (channel == null) { // DeviceChannel channel = XmlUtil.channelContentHandler(itemDevice, device, null);
if (channel == null || channel.getDeviceId() == null) {
logger.info("[收到目录订阅]:但是解析失败 {}", new String(evt.getRequest().getRawContent())); logger.info("[收到目录订阅]:但是解析失败 {}", new String(evt.getRequest().getRawContent()));
continue; continue;
} }

View File

@ -2,13 +2,6 @@ package com.genersoft.iot.vmp.gb28181.utils;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.CivilCodePo;
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;
import com.genersoft.iot.vmp.utils.CivilCodeUtil;
import com.genersoft.iot.vmp.utils.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils; import org.apache.commons.lang3.math.NumberUtils;
import org.dom4j.Attribute; import org.dom4j.Attribute;
import org.dom4j.Document; import org.dom4j.Document;
@ -240,388 +233,387 @@ public class XmlUtil {
CivilCode, BusinessGroup,VirtualOrganization,Other CivilCode, BusinessGroup,VirtualOrganization,Other
} }
public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event){ // public static DeviceChannel channelContentHandler(Element itemDevice, Device device, String event){
loadElement(itemDevice, DeviceChannel.class) // DeviceChannel deviceChannel = new DeviceChannel();
DeviceChannel deviceChannel = new DeviceChannel(); // deviceChannel.setDeviceId(device.getDeviceId());
deviceChannel.setDeviceId(device.getDeviceId()); // Element channdelIdElement = itemDevice.element("DeviceID");
Element channdelIdElement = itemDevice.element("DeviceID"); // if (channdelIdElement == null) {
if (channdelIdElement == null) { // logger.warn("解析Catalog消息时发现缺少 DeviceID");
logger.warn("解析Catalog消息时发现缺少 DeviceID"); // return null;
return null; // }
} // String channelId = channdelIdElement.getTextTrim();
String channelId = channdelIdElement.getTextTrim(); // if (ObjectUtils.isEmpty(channelId)) {
if (ObjectUtils.isEmpty(channelId)) { // logger.warn("解析Catalog消息时发现缺少 DeviceID");
logger.warn("解析Catalog消息时发现缺少 DeviceID"); // return null;
return null; // }
} // deviceChannel.setDeviceId(channelId);
deviceChannel.setChannelId(channelId); // if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) {
if (event != null && !event.equals(CatalogEvent.ADD) && !event.equals(CatalogEvent.UPDATE)) { // // 除了ADD和update情况下需要识别全部内容
// 除了ADD和update情况下需要识别全部内容 // return deviceChannel;
return deviceChannel; // }
} // Element nameElement = itemDevice.element("Name");
Element nameElement = itemDevice.element("Name"); // // 当通道名称为空时,设置通道名称为通道编码,避免级联时因通道名称为空导致上级接收通道失败
// 当通道名称为空时,设置通道名称为通道编码,避免级联时因通道名称为空导致上级接收通道失败 // if (nameElement != null && StringUtils.isNotBlank(nameElement.getText())) {
if (nameElement != null && StringUtils.isNotBlank(nameElement.getText())) { // deviceChannel.setName(nameElement.getText());
deviceChannel.setName(nameElement.getText()); // } else {
} else { // deviceChannel.setName(channelId);
deviceChannel.setName(channelId); // }
} // if(channelId.length() <= 8) {
if(channelId.length() <= 8) { // deviceChannel.setHasAudio(false);
deviceChannel.setHasAudio(false); // CivilCodePo parentCode = CivilCodeUtil.INSTANCE.getParentCode(channelId);
CivilCodePo parentCode = CivilCodeUtil.INSTANCE.getParentCode(channelId); // if (parentCode != null) {
if (parentCode != null) { // deviceChannel.setParentId(parentCode.getCode());
deviceChannel.setParentId(parentCode.getCode()); // deviceChannel.setCivilCode(parentCode.getCode());
deviceChannel.setCivilCode(parentCode.getCode()); // }else {
}else { // logger.warn("[xml解析] 无法确定行政区划{}的上级行政区划", channelId);
logger.warn("[xml解析] 无法确定行政区划{}的上级行政区划", channelId); // }
} // deviceChannel.setStatus("ON");
deviceChannel.setStatus(true); // return deviceChannel;
return deviceChannel; // }else {
}else { // if(channelId.length() != 20) {
if(channelId.length() != 20) { // logger.warn("[xml解析] 失败编号不符合国标28181定义 {}", channelId);
logger.warn("[xml解析] 失败编号不符合国标28181定义 {}", channelId); // return null;
return null; // }
} //
// int code = Integer.parseInt(channelId.substring(10, 13));
int code = Integer.parseInt(channelId.substring(10, 13)); // if (code == 136 || code == 137 || code == 138) {
if (code == 136 || code == 137 || code == 138) { // deviceChannel.setHasAudio(true);
deviceChannel.setHasAudio(true); // }else {
}else { // deviceChannel.setHasAudio(false);
deviceChannel.setHasAudio(false); // }
} // // 设备厂商
// 设备厂商 // String manufacturer = getText(itemDevice, "Manufacturer");
String manufacturer = getText(itemDevice, "Manufacturer"); // // 设备型号
// 设备型号 // String model = getText(itemDevice, "Model");
String model = getText(itemDevice, "Model"); // // 设备归属
// 设备归属 // String owner = getText(itemDevice, "Owner");
String owner = getText(itemDevice, "Owner"); // // 行政区域
// 行政区域 // String civilCode = getText(itemDevice, "CivilCode");
String civilCode = getText(itemDevice, "CivilCode"); // // 虚拟组织所属的业务分组ID,业务分组根据特定的业务需求制定,一个业务分组包含一组特定的虚拟组织
// 虚拟组织所属的业务分组ID,业务分组根据特定的业务需求制定,一个业务分组包含一组特定的虚拟组织 // String businessGroupID = getText(itemDevice, "BusinessGroupID");
String businessGroupID = getText(itemDevice, "BusinessGroupID"); // // 父设备/区域/系统ID
// 父设备/区域/系统ID // String parentID = getText(itemDevice, "ParentID");
String parentID = getText(itemDevice, "ParentID"); // if (parentID != null && parentID.equalsIgnoreCase("null")) {
if (parentID != null && parentID.equalsIgnoreCase("null")) { // parentID = null;
parentID = null; // }
} // // 注册方式(必选)缺省为1;1:符合IETFRFC3261标准的认证注册模式;2:基于口令的双向认证注册模式;3:基于数字证书的双向认证注册模式
// 注册方式(必选)缺省为1;1:符合IETFRFC3261标准的认证注册模式;2:基于口令的双向认证注册模式;3:基于数字证书的双向认证注册模式 // String registerWay = getText(itemDevice, "RegisterWay");
String registerWay = getText(itemDevice, "RegisterWay"); // // 保密属性(必选)缺省为0;0:不涉密,1:涉密
// 保密属性(必选)缺省为0;0:不涉密,1:涉密 // String secrecy = getText(itemDevice, "Secrecy");
String secrecy = getText(itemDevice, "Secrecy"); // // 安装地址
// 安装地址 // String address = getText(itemDevice, "Address");
String address = getText(itemDevice, "Address"); //
// switch (code){
switch (code){ // case 200:
case 200: // // 系统目录
// 系统目录 // if (!ObjectUtils.isEmpty(manufacturer)) {
if (!ObjectUtils.isEmpty(manufacturer)) { // deviceChannel.setManufacture(manufacturer);
deviceChannel.setManufacture(manufacturer); // }
} // if (!ObjectUtils.isEmpty(model)) {
if (!ObjectUtils.isEmpty(model)) { // deviceChannel.setModel(model);
deviceChannel.setModel(model); // }
} // if (!ObjectUtils.isEmpty(owner)) {
if (!ObjectUtils.isEmpty(owner)) { // deviceChannel.setOwner(owner);
deviceChannel.setOwner(owner); // }
} // if (!ObjectUtils.isEmpty(civilCode)) {
if (!ObjectUtils.isEmpty(civilCode)) { // deviceChannel.setCivilCode(civilCode);
deviceChannel.setCivilCode(civilCode); // deviceChannel.setParentId(civilCode);
deviceChannel.setParentId(civilCode); // }else {
}else { // if (!ObjectUtils.isEmpty(parentID)) {
if (!ObjectUtils.isEmpty(parentID)) { // deviceChannel.setParentId(parentID);
deviceChannel.setParentId(parentID); // }
} // }
} // if (!ObjectUtils.isEmpty(address)) {
if (!ObjectUtils.isEmpty(address)) { // deviceChannel.setAddress(address);
deviceChannel.setAddress(address); // }
} // deviceChannel.setStatus(true);
deviceChannel.setStatus(true); // if (!ObjectUtils.isEmpty(registerWay)) {
if (!ObjectUtils.isEmpty(registerWay)) { // try {
try { // deviceChannel.setRegisterWay(Integer.parseInt(registerWay));
deviceChannel.setRegisterWay(Integer.parseInt(registerWay)); // }catch (NumberFormatException exception) {
}catch (NumberFormatException exception) { // logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay);
logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay); // }
} // }
} // if (!ObjectUtils.isEmpty(secrecy)) {
if (!ObjectUtils.isEmpty(secrecy)) { // deviceChannel.setSecrecy(secrecy);
deviceChannel.setSecrecy(secrecy); // }
} // return deviceChannel;
return deviceChannel; // case 215:
case 215: // // 业务分组
// 业务分组 // deviceChannel.setStatus(true);
deviceChannel.setStatus(true); // if (!ObjectUtils.isEmpty(parentID)) {
if (!ObjectUtils.isEmpty(parentID)) { // if (!parentID.trim().equalsIgnoreCase(device.getDeviceId())) {
if (!parentID.trim().equalsIgnoreCase(device.getDeviceId())) { // deviceChannel.setParentId(parentID);
deviceChannel.setParentId(parentID); // }
} // }else {
}else { // logger.warn("[xml解析] 业务分组数据中缺少关键信息->ParentId");
logger.warn("[xml解析] 业务分组数据中缺少关键信息->ParentId"); // if (!ObjectUtils.isEmpty(civilCode)) {
if (!ObjectUtils.isEmpty(civilCode)) { // deviceChannel.setCivilCode(civilCode);
deviceChannel.setCivilCode(civilCode); // }
} // }
} // break;
break; // case 216:
case 216: // // 虚拟组织
// 虚拟组织 // deviceChannel.setStatus(true);
deviceChannel.setStatus(true); // if (!ObjectUtils.isEmpty(businessGroupID)) {
if (!ObjectUtils.isEmpty(businessGroupID)) { // deviceChannel.setBusinessGroupId(businessGroupID);
deviceChannel.setBusinessGroupId(businessGroupID); // }
} //
// if (!ObjectUtils.isEmpty(parentID)) {
if (!ObjectUtils.isEmpty(parentID)) { // if (parentID.contains("/")) {
if (parentID.contains("/")) { // String[] parentIdArray = parentID.split("/");
String[] parentIdArray = parentID.split("/"); // parentID = parentIdArray[parentIdArray.length - 1];
parentID = parentIdArray[parentIdArray.length - 1]; // }
} // deviceChannel.setParentId(parentID);
deviceChannel.setParentId(parentID); // }else {
}else { // if (!ObjectUtils.isEmpty(businessGroupID)) {
if (!ObjectUtils.isEmpty(businessGroupID)) { // deviceChannel.setParentId(businessGroupID);
deviceChannel.setParentId(businessGroupID); // }
} // }
} // break;
break; // default:
default: // // 设备目录
// 设备目录 // if (!ObjectUtils.isEmpty(manufacturer)) {
if (!ObjectUtils.isEmpty(manufacturer)) { // deviceChannel.setManufacture(manufacturer);
deviceChannel.setManufacture(manufacturer); // }
} // if (!ObjectUtils.isEmpty(model)) {
if (!ObjectUtils.isEmpty(model)) { // deviceChannel.setModel(model);
deviceChannel.setModel(model); // }
} // if (!ObjectUtils.isEmpty(owner)) {
if (!ObjectUtils.isEmpty(owner)) { // deviceChannel.setOwner(owner);
deviceChannel.setOwner(owner); // }
} // if (!ObjectUtils.isEmpty(civilCode)
if (!ObjectUtils.isEmpty(civilCode) // && civilCode.length() <= 8
&& civilCode.length() <= 8 // && NumberUtils.isParsable(civilCode)
&& NumberUtils.isParsable(civilCode) // && civilCode.length()%2 == 0
&& civilCode.length()%2 == 0 // ) {
) { // deviceChannel.setCivilCode(civilCode);
deviceChannel.setCivilCode(civilCode); // }
} // if (!ObjectUtils.isEmpty(businessGroupID)) {
if (!ObjectUtils.isEmpty(businessGroupID)) { // deviceChannel.setBusinessGroupId(businessGroupID);
deviceChannel.setBusinessGroupId(businessGroupID); // }
} //
// // 警区
// 警区 // String block = getText(itemDevice, "Block");
String block = getText(itemDevice, "Block"); // if (!ObjectUtils.isEmpty(block)) {
if (!ObjectUtils.isEmpty(block)) { // deviceChannel.setBlock(block);
deviceChannel.setBlock(block); // }
} // if (!ObjectUtils.isEmpty(address)) {
if (!ObjectUtils.isEmpty(address)) { // deviceChannel.setAddress(address);
deviceChannel.setAddress(address); // }
} //
// if (!ObjectUtils.isEmpty(secrecy)) {
if (!ObjectUtils.isEmpty(secrecy)) { // deviceChannel.setSecrecy(secrecy);
deviceChannel.setSecrecy(secrecy); // }
} //
// // 当为设备时,是否有子设备(必选)1有,0没有
// 当为设备时,是否有子设备(必选)1有,0没有 // String parental = getText(itemDevice, "Parental");
String parental = getText(itemDevice, "Parental"); // if (!ObjectUtils.isEmpty(parental)) {
if (!ObjectUtils.isEmpty(parental)) { // try {
try { // // 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1
// 由于海康会错误的发送65535作为这里的取值,所以这里除非是0否则认为是1 // if (!ObjectUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) {
if (!ObjectUtils.isEmpty(parental) && parental.length() == 1 && Integer.parseInt(parental) == 0) { // deviceChannel.setParental(0);
deviceChannel.setParental(0); // }else {
}else { // deviceChannel.setParental(1);
deviceChannel.setParental(1); // }
} // }catch (NumberFormatException e) {
}catch (NumberFormatException e) { // logger.warn("[xml解析] 从通道数据获取 parental失败 {}", parental);
logger.warn("[xml解析] 从通道数据获取 parental失败 {}", parental); // }
} // }
} // // 父设备/区域/系统ID
// 父设备/区域/系统ID //
// if (!ObjectUtils.isEmpty(parentID) ) {
if (!ObjectUtils.isEmpty(parentID) ) { // if (parentID.contains("/")) {
if (parentID.contains("/")) { // String[] parentIdArray = parentID.split("/");
String[] parentIdArray = parentID.split("/"); // deviceChannel.setParentId(parentIdArray[parentIdArray.length - 1]);
deviceChannel.setParentId(parentIdArray[parentIdArray.length - 1]); // }else {
}else { // if (parentID.length()%2 == 0) {
if (parentID.length()%2 == 0) { // deviceChannel.setParentId(parentID);
deviceChannel.setParentId(parentID); // }else {
}else { // logger.warn("[xml解析] 不规范的parentID{}, 已舍弃", parentID);
logger.warn("[xml解析] 不规范的parentID{}, 已舍弃", parentID); // }
} // }
} // }else {
}else { // if (!ObjectUtils.isEmpty(businessGroupID)) {
if (!ObjectUtils.isEmpty(businessGroupID)) { // deviceChannel.setParentId(businessGroupID);
deviceChannel.setParentId(businessGroupID); // }else {
}else { // if (!ObjectUtils.isEmpty(deviceChannel.getCivilCode())) {
if (!ObjectUtils.isEmpty(deviceChannel.getCivilCode())) { // deviceChannel.setParentId(deviceChannel.getCivilCode());
deviceChannel.setParentId(deviceChannel.getCivilCode()); // }
} // }
} // }
} // // 注册方式
// 注册方式 // if (!ObjectUtils.isEmpty(registerWay)) {
if (!ObjectUtils.isEmpty(registerWay)) { // try {
try { // int registerWayInt = Integer.parseInt(registerWay);
int registerWayInt = Integer.parseInt(registerWay); // deviceChannel.setRegisterWay(registerWayInt);
deviceChannel.setRegisterWay(registerWayInt); // }catch (NumberFormatException exception) {
}catch (NumberFormatException exception) { // logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay);
logger.warn("[xml解析] 从通道数据获取registerWay失败 {}", registerWay); // deviceChannel.setRegisterWay(1);
deviceChannel.setRegisterWay(1); // }
} // }else {
}else { // deviceChannel.setRegisterWay(1);
deviceChannel.setRegisterWay(1); // }
} //
// // 信令安全模式(可选)缺省为0; 0:不采用;2:S/MIME 签名方式;3:S/MIME加密签名同时采用方式;4:数字摘要方式
// 信令安全模式(可选)缺省为0; 0:不采用;2:S/MIME 签名方式;3:S/MIME加密签名同时采用方式;4:数字摘要方式 // String safetyWay = getText(itemDevice, "SafetyWay");
String safetyWay = getText(itemDevice, "SafetyWay"); // if (!ObjectUtils.isEmpty(safetyWay)) {
if (!ObjectUtils.isEmpty(safetyWay)) { // try {
try { // deviceChannel.setSafetyWay(Integer.parseInt(safetyWay));
deviceChannel.setSafetyWay(Integer.parseInt(safetyWay)); // }catch (NumberFormatException e) {
}catch (NumberFormatException e) { // logger.warn("[xml解析] 从通道数据获取 safetyWay失败 {}", safetyWay);
logger.warn("[xml解析] 从通道数据获取 safetyWay失败 {}", safetyWay); // }
} // }
} //
// // 证书序列号(有证书的设备必选)
// 证书序列号(有证书的设备必选) // String certNum = getText(itemDevice, "CertNum");
String certNum = getText(itemDevice, "CertNum"); // if (!ObjectUtils.isEmpty(certNum)) {
if (!ObjectUtils.isEmpty(certNum)) { // deviceChannel.setCertNum(certNum);
deviceChannel.setCertNum(certNum); // }
} //
// // 证书有效标识(有证书的设备必选)缺省为0;证书有效标识:0:无效 1:有效
// 证书有效标识(有证书的设备必选)缺省为0;证书有效标识:0:无效 1:有效 // String certifiable = getText(itemDevice, "Certifiable");
String certifiable = getText(itemDevice, "Certifiable"); // if (!ObjectUtils.isEmpty(certifiable)) {
if (!ObjectUtils.isEmpty(certifiable)) { // try {
try { // deviceChannel.setCertifiable(Integer.parseInt(certifiable));
deviceChannel.setCertifiable(Integer.parseInt(certifiable)); // }catch (NumberFormatException e) {
}catch (NumberFormatException e) { // logger.warn("[xml解析] 从通道数据获取 Certifiable失败 {}", certifiable);
logger.warn("[xml解析] 从通道数据获取 Certifiable失败 {}", certifiable); // }
} // }
} //
// // 无效原因码(有证书且证书无效的设备必选)
// 无效原因码(有证书且证书无效的设备必选) // String errCode = getText(itemDevice, "ErrCode");
String errCode = getText(itemDevice, "ErrCode"); // if (!ObjectUtils.isEmpty(errCode)) {
if (!ObjectUtils.isEmpty(errCode)) { // try {
try { // deviceChannel.setErrCode(Integer.parseInt(errCode));
deviceChannel.setErrCode(Integer.parseInt(errCode)); // }catch (NumberFormatException e) {
}catch (NumberFormatException e) { // logger.warn("[xml解析] 从通道数据获取 ErrCode失败 {}", errCode);
logger.warn("[xml解析] 从通道数据获取 ErrCode失败 {}", errCode); // }
} // }
} //
// // 证书终止有效期(有证书的设备必选)
// 证书终止有效期(有证书的设备必选) // String endTime = getText(itemDevice, "EndTime");
String endTime = getText(itemDevice, "EndTime"); // if (!ObjectUtils.isEmpty(endTime)) {
if (!ObjectUtils.isEmpty(endTime)) { // deviceChannel.setEndTime(endTime);
deviceChannel.setEndTime(endTime); // }
} //
//
// // 设备/区域/系统IP地址
// 设备/区域/系统IP地址 // String ipAddress = getText(itemDevice, "IPAddress");
String ipAddress = getText(itemDevice, "IPAddress"); // if (!ObjectUtils.isEmpty(ipAddress)) {
if (!ObjectUtils.isEmpty(ipAddress)) { // deviceChannel.setIpAddress(ipAddress);
deviceChannel.setIpAddress(ipAddress); // }
} //
// // 设备/区域/系统端口
// 设备/区域/系统端口 // String port = getText(itemDevice, "Port");
String port = getText(itemDevice, "Port"); // if (!ObjectUtils.isEmpty(port)) {
if (!ObjectUtils.isEmpty(port)) { // try {
try { // deviceChannel.setPort(Integer.parseInt(port));
deviceChannel.setPort(Integer.parseInt(port)); // }catch (NumberFormatException e) {
}catch (NumberFormatException e) { // logger.warn("[xml解析] 从通道数据获取 Port失败 {}", port);
logger.warn("[xml解析] 从通道数据获取 Port失败 {}", port); // }
} // }
} //
// // 设备口令
// 设备口令 // String password = getText(itemDevice, "Password");
String password = getText(itemDevice, "Password"); // if (!ObjectUtils.isEmpty(password)) {
if (!ObjectUtils.isEmpty(password)) { // deviceChannel.setPassword(password);
deviceChannel.setPassword(password); // }
} //
//
// // 设备状态
// 设备状态 // String status = getText(itemDevice, "Status");
String status = getText(itemDevice, "Status"); // if (status != null) {
if (status != null) { // // ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理 // if (status.equalsIgnoreCase("ON") || status.equalsIgnoreCase("On") || status.equalsIgnoreCase("ONLINE") || status.equalsIgnoreCase("OK")) {
if (status.equalsIgnoreCase("ON") || status.equalsIgnoreCase("On") || status.equalsIgnoreCase("ONLINE") || status.equalsIgnoreCase("OK")) { // deviceChannel.setStatus(true);
deviceChannel.setStatus(true); // }
} // if (status.equalsIgnoreCase("OFF") || status.equalsIgnoreCase("Off") || status.equalsIgnoreCase("OFFLINE")) {
if (status.equalsIgnoreCase("OFF") || status.equalsIgnoreCase("Off") || status.equalsIgnoreCase("OFFLINE")) { // deviceChannel.setStatus(false);
deviceChannel.setStatus(false); // }
} // }else {
}else { // deviceChannel.setStatus(true);
deviceChannel.setStatus(true); // }
} //// logger.info("状态字符串: {}", status);
// logger.info("状态字符串: {}", status); //// logger.info("状态结果: {}", deviceChannel.isStatus());
// logger.info("状态结果: {}", deviceChannel.isStatus()); // // 经度
// 经度 // String longitude = getText(itemDevice, "Longitude");
String longitude = getText(itemDevice, "Longitude"); // if (NumericUtil.isDouble(longitude)) {
if (NumericUtil.isDouble(longitude)) { // deviceChannel.setLongitude(Double.parseDouble(longitude));
deviceChannel.setLongitude(Double.parseDouble(longitude)); // } else {
} else { // deviceChannel.setLongitude(0.00);
deviceChannel.setLongitude(0.00); // }
} //
// // 纬度
// 纬度 // String latitude = getText(itemDevice, "Latitude");
String latitude = getText(itemDevice, "Latitude"); // if (NumericUtil.isDouble(latitude)) {
if (NumericUtil.isDouble(latitude)) { // deviceChannel.setLatitude(Double.parseDouble(latitude));
deviceChannel.setLatitude(Double.parseDouble(latitude)); // } else {
} else { // deviceChannel.setLatitude(0.00);
deviceChannel.setLatitude(0.00); // }
} //
// deviceChannel.setGpsTime(DateUtil.getNow());
deviceChannel.setGpsTime(DateUtil.getNow()); //
// // -摄像机类型扩展,标识摄像机类型:1-球机;2-半球;3-固定枪机;4-遥控枪机。当目录项为摄像机时可选
// -摄像机类型扩展,标识摄像机类型:1-球机;2-半球;3-固定枪机;4-遥控枪机。当目录项为摄像机时可选 // String ptzType = getText(itemDevice, "PTZType");
String ptzType = getText(itemDevice, "PTZType"); // if (ObjectUtils.isEmpty(ptzType)) {
if (ObjectUtils.isEmpty(ptzType)) { // //兼容INFO中的信息
//兼容INFO中的信息 // Element info = itemDevice.element("Info");
Element info = itemDevice.element("Info"); // String ptzTypeFromInfo = XmlUtil.getText(info, "PTZType");
String ptzTypeFromInfo = XmlUtil.getText(info, "PTZType"); // if(!ObjectUtils.isEmpty(ptzTypeFromInfo)){
if(!ObjectUtils.isEmpty(ptzTypeFromInfo)){ // try {
try { // deviceChannel.setPtzType(Integer.parseInt(ptzTypeFromInfo));
deviceChannel.setPtzType(Integer.parseInt(ptzTypeFromInfo)); // }catch (NumberFormatException e){
}catch (NumberFormatException e){ // logger.warn("[xml解析] 从通道数据info中获取PTZType失败 {}", ptzTypeFromInfo);
logger.warn("[xml解析] 从通道数据info中获取PTZType失败 {}", ptzTypeFromInfo); // }
} // }
} // } else {
} else { // try {
try { // deviceChannel.setPtzType(Integer.parseInt(ptzType));
deviceChannel.setPtzType(Integer.parseInt(ptzType)); // }catch (NumberFormatException e){
}catch (NumberFormatException e){ // logger.warn("[xml解析] 从通道数据中获取PTZType失败 {}", ptzType);
logger.warn("[xml解析] 从通道数据中获取PTZType失败 {}", ptzType); // }
} // }
} //
// // TODO 摄像机位置类型扩展。
// TODO 摄像机位置类型扩展。 // // 1-省际检查站、
// 1-省际检查站、 // // 2-党政机关、
// 2-党政机关、 // // 3-车站码头、
// 3-车站码头、 // // 4-中心广场、
// 4-中心广场、 // // 5-体育场馆、
// 5-体育场馆、 // // 6-商业中心、
// 6-商业中心、 // // 7-宗教场所、
// 7-宗教场所、 // // 8-校园周边、
// 8-校园周边、 // // 9-治安复杂区域、
// 9-治安复杂区域、 // // 10-交通干线。
// 10-交通干线。 // // String positionType = getText(itemDevice, "PositionType");
// String positionType = getText(itemDevice, "PositionType"); //
// // TODO 摄像机安装位置室外、室内属性。1-室外、2-室内。
// TODO 摄像机安装位置室外、室内属性。1-室外、2-室内。 // // String roomType = getText(itemDevice, "RoomType");
// String roomType = getText(itemDevice, "RoomType"); // // TODO 摄像机用途属性
// TODO 摄像机用途属性 // // String useType = getText(itemDevice, "UseType");
// String useType = getText(itemDevice, "UseType"); // // TODO 摄像机补光属性。1-无补光、2-红外补光、3-白光补光
// TODO 摄像机补光属性。1-无补光、2-红外补光、3-白光补光 // // String supplyLightType = getText(itemDevice, "SupplyLightType");
// String supplyLightType = getText(itemDevice, "SupplyLightType"); // // TODO 摄像机监视方位属性。1-东、2-西、3-南、4-北、5-东南、6-东北、7-西南、8-西北。
// TODO 摄像机监视方位属性。1-东、2-西、3-南、4-北、5-东南、6-东北、7-西南、8-西北。 // // String directionType = getText(itemDevice, "DirectionType");
// String directionType = getText(itemDevice, "DirectionType"); // // TODO 摄像机支持的分辨率,可有多个分辨率值,各个取值间以“/”分隔。分辨率取值参见附录 F中SDPf字段规定
// TODO 摄像机支持的分辨率,可有多个分辨率值,各个取值间以“/”分隔。分辨率取值参见附录 F中SDPf字段规定 // // String resolution = getText(itemDevice, "Resolution");
// String resolution = getText(itemDevice, "Resolution"); //
// // TODO 下载倍速范围(可选),各可选参数以“/”分隔,如设备支持1,2,4倍速下载则应写为“1/2/4
// TODO 下载倍速范围(可选),各可选参数以“/”分隔,如设备支持1,2,4倍速下载则应写为“1/2/4 // // String downloadSpeed = getText(itemDevice, "DownloadSpeed");
// String downloadSpeed = getText(itemDevice, "DownloadSpeed"); // // TODO 空域编码能力,取值0:不支持;1:1级增强(1个增强层);2:2级增强(2个增强层);3:3级增强(3个增强层)
// TODO 空域编码能力,取值0:不支持;1:1级增强(1个增强层);2:2级增强(2个增强层);3:3级增强(3个增强层) // // String svcSpaceSupportMode = getText(itemDevice, "SVCSpaceSupportMode");
// String svcSpaceSupportMode = getText(itemDevice, "SVCSpaceSupportMode"); // // TODO 时域编码能力,取值0:不支持;1:1级增强;2:2级增强;3:3级增强
// TODO 时域编码能力,取值0:不支持;1:1级增强;2:2级增强;3:3级增强 // // String svcTimeSupportMode = getText(itemDevice, "SVCTimeSupportMode");
// String svcTimeSupportMode = getText(itemDevice, "SVCTimeSupportMode"); //
//
// deviceChannel.setSecrecy(secrecy);
deviceChannel.setSecrecy(secrecy); // break;
break; // }
} // }
} //
// return deviceChannel;
return deviceChannel; // }
}
/** /**
* *
@ -672,6 +664,46 @@ public class XmlUtil {
return t; return t;
} }
public static <T> T elementDecode(Element element, Class<T> clazz) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Field[] fields = clazz.getDeclaredFields();
T t = clazz.getDeclaredConstructor().newInstance();
for (Field field : fields) {
ReflectionUtils.makeAccessible(field);
MessageElement annotation = field.getAnnotation(MessageElement.class);
if (annotation == null) {
continue;
}
String value = annotation.value();
boolean subVal = value.contains(".");
Element element1 = element.element(value);
if (element1 == null) {
continue;
}
if (!subVal) {
// 无下级数据
Object fieldVal = element1.isTextOnly() ? element1.getText() : loadElement(element1, field.getType());
Object o = simpleTypeDeal(field.getType(), fieldVal);
ReflectionUtils.setField(field, t, o);
} else {
String[] pathArray = value.split(".");
Element subElement = element1;
for (String path : pathArray) {
subElement = subElement.element(path);
if (subElement == null) {
break;
}
}
if (subElement == null) {
continue;
}
Object fieldVal = subElement.isTextOnly() ? subElement.getText() : loadElement(subElement, field.getType());
Object o = simpleTypeDeal(field.getType(), fieldVal);
ReflectionUtils.setField(field, t, o);
}
}
return t;
}
/** /**
* *
* *

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.service; package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
@ -45,8 +46,8 @@ public interface IGbStreamService {
DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, ParentPlatform platform); DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, ParentPlatform platform);
void sendCatalogMsg(GbStream gbStream, String type); void sendCatalogMsg(CommonGBChannel gbStream, String type);
void sendCatalogMsgs(List<GbStream> gbStreams, String type); void sendCatalogMsgs(List<CommonGBChannel> gbStreams, String type);
/** /**
* gbIdname * gbIdname

View File

@ -116,4 +116,7 @@ public interface IStreamPushService {
void updatePush(OnStreamChangedHookParam param); void updatePush(OnStreamChangedHookParam param);
Map<String, StreamPush> getAllGBId();
} }

View File

@ -157,16 +157,16 @@ public class GbStreamServiceImpl implements IGbStreamService {
} }
@Override @Override
public void sendCatalogMsg(GbStream gbStream, String type) { public void sendCatalogMsg(CommonGBChannel channel, String type) {
if (gbStream == null || type == null) { if (channel == null || type == null) {
logger.warn("[发送目录订阅]类型流信息或类型为NULL"); logger.warn("[发送目录订阅]类型流信息或类型为NULL");
return; return;
} }
List<GbStream> gbStreams = new ArrayList<>(); List<CommonGBChannel> gbStreams = new ArrayList<>();
if (gbStream.getGbId() != null) { if (channel.getGbDeviceId() != null) {
gbStreams.add(gbStream); gbStreams.add(channel);
}else { }else {
GbStream gbStreamIndb = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream()); GbStream gbStreamIndb = gbStreamMapper.selectOne(channel.getApp(), channel.getStream());
if (gbStreamIndb != null && gbStreamIndb.getGbId() != null){ if (gbStreamIndb != null && gbStreamIndb.getGbId() != null){
gbStreams.add(gbStreamIndb); gbStreams.add(gbStreamIndb);
} }

View File

@ -48,9 +48,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
private final static Logger logger = LoggerFactory.getLogger(StreamPushServiceImpl.class); private final static Logger logger = LoggerFactory.getLogger(StreamPushServiceImpl.class);
@Autowired
private GbStreamMapper gbStreamMapper;
@Autowired @Autowired
private StreamPushMapper streamPushMapper; private StreamPushMapper streamPushMapper;
@ -66,9 +63,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
@Autowired @Autowired
private PlatformGbStreamMapper platformGbStreamMapper; private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private IGbStreamService gbStreamService;
@Autowired @Autowired
private EventPublisher eventPublisher; private EventPublisher eventPublisher;
@ -126,16 +120,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
streamPushMapper.update(transform); streamPushMapper.update(transform);
gbStreamMapper.updateMediaServer(event.getApp(), event.getStream(), event.getMediaServer().getId()); gbStreamMapper.updateMediaServer(event.getApp(), event.getStream(), event.getMediaServer().getId());
} }
// TODO 相关的事件自行管理不需要写入ZLMMediaListManager
// ChannelOnlineEvent channelOnlineEventLister = getChannelOnlineEventLister(transform.getApp(), transform.getStream());
// if ( channelOnlineEventLister != null) {
// try {
// channelOnlineEventLister.run(transform.getApp(), transform.getStream(), transform.getServerId());;
// } catch (ParseException e) {
// logger.error("addPush: ", e);
// }
// removedChannelOnlineEventLister(transform.getApp(), transform.getStream());
// }
// 冗余数据,自己系统中自用 // 冗余数据,自己系统中自用
redisCatchStorage.addPushListItem(event.getApp(), event.getStream(), event); redisCatchStorage.addPushListItem(event.getApp(), event.getStream(), event);
@ -216,7 +201,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
streamPushItem.setMediaServerId(item.getMediaServerId()); streamPushItem.setMediaServerId(item.getMediaServerId());
streamPushItem.setStream(item.getStream()); streamPushItem.setStream(item.getStream());
streamPushItem.setCreateTime(DateUtil.getNow()); streamPushItem.setCreateTime(DateUtil.getNow());
streamPushItem.setVhost(item.getVhost());
streamPushItem.setServerId(item.getSeverId()); streamPushItem.setServerId(item.getSeverId());
return streamPushItem; return streamPushItem;
} }
@ -625,6 +609,11 @@ public class StreamPushServiceImpl implements IStreamPushService {
return streamPushMapper.getAllAppAndStreamMap(); return streamPushMapper.getAllAppAndStreamMap();
} }
@Override
public Map<String, StreamPush> getAllGBId() {
return streamPushMapper.getAllGBId();
}
@Override @Override
public void updatePush(OnStreamChangedHookParam param) { public void updatePush(OnStreamChangedHookParam param) {
StreamPush transform = transform(param); StreamPush transform = transform(param);

View File

@ -2,10 +2,9 @@ package com.genersoft.iot.vmp.service.redisMsg;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.gb28181.bean.GbStream; import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPush; import com.genersoft.iot.vmp.media.zlm.dto.StreamPush;
import com.genersoft.iot.vmp.service.IGbStreamService; import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamPushService; import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -60,43 +59,40 @@ public class RedisPushStreamStatusListMsgListener implements MessageListener {
List<StreamPush> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPush.class); List<StreamPush> streamPushItems = JSON.parseArray(new String(msg.getBody()), StreamPush.class);
//查询全部的app+stream 用于判断是添加还是修改 //查询全部的app+stream 用于判断是添加还是修改
Map<String, StreamPush> allAppAndStream = streamPushService.getAllAppAndStreamMap(); Map<String, StreamPush> allAppAndStream = streamPushService.getAllAppAndStreamMap();
Map<String, GbStream> allGBId = gbStreamService.getAllGBId(); Map<String, StreamPush> allGBId = streamPushService.getAllGBId();
/** /**
* APP+Streamstream_pushgb_stream * APP+Streamstream_pushgb_stream
*/ */
List<StreamPush> streamPushItemForSave = new ArrayList<>(); List<StreamPush> streamPushItemForSave = new ArrayList<>();
List<StreamPush> streamPushItemForUpdate = new ArrayList<>(); List<StreamPush> streamPushItemForUpdate = new ArrayList<>();
for (StreamPush streamPushItem : streamPushItems) { for (StreamPush streamPush : streamPushItems) {
String app = streamPushItem.getApp(); String app = streamPush.getApp();
String stream = streamPushItem.getStream(); String stream = streamPush.getStream();
boolean contains = allAppAndStream.containsKey(app + stream); boolean contains = allAppAndStream.containsKey(app + stream);
//不存在就添加 //不存在就添加
if (!contains) { if (!contains) {
if (allGBId.containsKey(streamPushItem.getGbId())) { if (allGBId.containsKey(streamPush.getGbDeviceId())) {
GbStream gbStream = allGBId.get(streamPushItem.getGbId()); StreamPush streamPushInDb = allGBId.get(streamPush.getGbDeviceId());
logger.warn("[REDIS消息-推流设备列表更新-INSERT] 国标编号重复: {}, 已分配给{}/{}", logger.warn("[REDIS消息-推流设备列表更新-INSERT] 国标编号重复: {}, 已分配给{}/{}",
streamPushItem.getGbId(), gbStream.getApp(), gbStream.getStream()); streamPushInDb.getGbDeviceId(), streamPushInDb.getApp(), streamPushInDb.getStream());
continue; continue;
} }
streamPushItem.setStreamType("push"); streamPush.setCreateTime(DateUtil.getNow());
streamPushItem.setCreateTime(DateUtil.getNow()); streamPush.setMediaServerId(mediaServerService.getDefaultMediaServer().getId());
streamPushItem.setMediaServerId(mediaServerService.getDefaultMediaServer().getId()); streamPushItemForSave.add(streamPush);
streamPushItem.setOriginType(2); allGBId.put(streamPush.getGbDeviceId(), streamPush);
streamPushItem.setOriginTypeStr("rtsp_push");
streamPushItem.setTotalReaderCount(0);
streamPushItemForSave.add(streamPushItem);
allGBId.put(streamPushItem.getGbId(), streamPushItem);
} else { } else {
if (allGBId.containsKey(streamPushItem.getGbId()) if (allGBId.containsKey(streamPush.getGbDeviceId())
&& (!allGBId.get(streamPushItem.getGbId()).getApp().equals(streamPushItem.getApp()) || !allGBId.get(streamPushItem.getGbId()).getStream().equals(streamPushItem.getStream()))) { && (!allGBId.get(streamPush.getGbDeviceId()).getApp().equals(streamPush.getApp())
GbStream gbStream = allGBId.get(streamPushItem.getGbId()); || !allGBId.get(streamPush.getGbDeviceId()).getStream().equals(streamPush.getStream()))) {
StreamPush streamPushInDb = allGBId.get(streamPush.getGbDeviceId());
logger.warn("[REDIS消息-推流设备列表更新-UPDATE] 国标编号重复: {}, 已分配给{}/{}", logger.warn("[REDIS消息-推流设备列表更新-UPDATE] 国标编号重复: {}, 已分配给{}/{}",
streamPushItem.getGbId(), gbStream.getApp(), gbStream.getStream()); streamPush.getGbDeviceId(), streamPushInDb.getApp(), streamPushInDb.getStream());
continue; continue;
} }
//存在就只修改 name和gbId //存在就只修改 name和gbId
streamPushItemForUpdate.add(streamPushItem); streamPushItemForUpdate.add(streamPush);
} }
} }
if (!streamPushItemForSave.isEmpty()) { if (!streamPushItemForSave.isEmpty()) {

View File

@ -204,4 +204,10 @@ public interface StreamPushMapper {
Map<String, StreamPush> getAllAppAndStreamMap(); Map<String, StreamPush> getAllAppAndStreamMap();
@MapKey("gb_id")
@Select("SELECT wgs.gb_id, wsp.app, wsp.stream, wgs.gb_id, wgs.name " +
" from wvp_stream_push wsp " +
" left join wvp_gb_stream wgs on wgs.app = wsp.app and wgs.stream = wsp.stream")
Map<String, StreamPush> getAllGBId();
} }

View File

@ -2,4 +2,4 @@ spring:
application: application:
name: wvp name: wvp
profiles: profiles:
active: local active: local271