diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CommonGBChannel.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CommonGBChannel.java index 5d82ae52..c261427e 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CommonGBChannel.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/CommonGBChannel.java @@ -218,13 +218,16 @@ public class CommonGBChannel { private String updateTime; - public String encode(){ - return encode(null); + + + public String encode(String serverDeviceId) { + return encode(null, serverDeviceId); } - public String encode(String event){ + + public String encode(String event,String serverDeviceId) { String content; if (event == null) { - return getFullContent(null); + return getFullContent(null, serverDeviceId); } switch (event) { case CatalogEvent.DEL: @@ -244,7 +247,7 @@ public class CommonGBChannel { break; case CatalogEvent.ADD: case CatalogEvent.UPDATE: - content = getFullContent(event); + content = getFullContent(event, serverDeviceId); break; default: content = null; @@ -253,69 +256,156 @@ public class CommonGBChannel { return content; } - private String getFullContent(String event) { + private String getFullContent(String event, String serverDeviceId) { StringBuilder content = new StringBuilder(); // 行政区划目录项 content.append("\n") .append("" + this.getGbDeviceId() + "\n") .append("" + this.getGbName() + "\n"); + if (this.getGbDeviceId().length() > 8) { - String type = this.getGbDeviceId().substring(10,13); + String type = this.getGbDeviceId().substring(10, 13); if (type.equals("200")) { // 业务分组目录项 - content.append("" + this.getGbManufacturer() + "\n") - .append("" + this.getGbModel() + "\n") - .append("" + this.getGbOwner() + "\n") - .append("" + this.getGbCivilCode() + "\n") - .append("
" + this.getGbAddress() + "
\n") - .append("" + this.getGbRegisterWay() + "\n") - .append("" + this.getGbSecrecy() + "\n"); - }else if (type.equals("215")) { + if (this.getGbManufacturer() != null) { + content.append("" + this.getGbManufacturer() + "\n"); + } + if (this.getGbModel() != null) { + content.append("" + this.getGbModel() + "\n"); + } + if (this.getGbOwner() != null) { + content.append("" + this.getGbOwner() + "\n"); + } + if (this.getGbCivilCode() != null) { + content.append("" + this.getGbCivilCode() + "\n"); + } + if (this.getGbAddress() != null) { + content.append("
" + this.getGbAddress() + "
\n"); + } + if (this.getGbRegisterWay() != null) { + content.append("" + this.getGbRegisterWay() + "\n"); + } + if (this.getGbSecrecy() != null) { + content.append("" + this.getGbSecrecy() + "\n"); + } + } else if (type.equals("215")) { // 业务分组 - content.append("" + this.getGbParentId() + "\n"); - }else if (type.equals("216")) { + if (this.getGbCivilCode() != null) { + content.append("" + this.getGbCivilCode() + "\n"); + } + content.append("" + serverDeviceId + "\n"); + } else if (type.equals("216")) { // 虚拟组织目录项 + if (this.getGbCivilCode() != null) { + content.append("" + this.getGbCivilCode() + "\n"); + } content.append("" + this.getGbParentId() + "\n") .append("" + this.getGbBusinessGroupId() + "\n"); - }else { - // 设备目录项 - content.append("" + this.getGbManufacturer() + "\n") - .append("" + this.getGbModel() + "\n") - .append("" + this.getGbOwner() + "\n") - .append("" + this.getGbCivilCode() + "\n") - .append("" + this.getGbBlock() + "\n") - .append("
" + this.getGbAddress() + "
\n") - .append("" + this.getGbParental() + "\n") - .append("" + this.getGbParentId() + "\n") - .append("" + this.getGbSafetyWay() + "\n") - .append("" + this.getGbRegisterWay() + "\n") - .append("" + this.getGbCertNum() + "\n") - .append("" + this.getGbCertifiable() + "\n") - .append("" + this.getGbErrCode() + "\n") - .append("" + this.getGbEndTime() + "\n") - .append("" + this.getGbSecrecy() + "\n") - .append("" + this.getGbIpAddress() + "\n") - .append("" + this.getGbPort() + "\n") - .append("" + this.getGbPassword() + "\n") - .append("" + this.getGbStatus() + "\n") - .append("" + this.getGbLongitude() + "\n") - .append("" + this.getGbLatitude() + "\n") - .append("\n") - .append(" " + this.getGbPtzType() + "\n") - .append(" " + this.getGbPositionType() + "\n") - .append(" " + this.getGbRoomType() + "\n") - .append(" " + this.getGbUseType() + "\n") - .append(" " + this.getGbSupplyLightType() + "\n") - .append(" " + this.getGbDirectionType() + "\n") - .append(" " + this.getGbResolution() + "\n") - .append(" " + this.getGbBusinessGroupId() + "\n") - .append(" " + this.getGbDownloadSpeed() + "\n") - .append(" " + this.getGbSvcSpaceSupportMod() + "\n") - .append(" " + this.getGbSvcTimeSupportMode() + "\n") - .append("") - ; + } else { + if (this.getGbManufacturer() != null) { + content.append("" + this.getGbManufacturer() + "\n"); + } + if (this.getGbModel() != null) { + content.append("" + this.getGbModel() + "\n"); + } + if (this.getGbOwner() != null) { + content.append("" + this.getGbOwner() + "\n"); + } + if (this.getGbCivilCode() != null) { + content.append("" + this.getGbCivilCode() + "\n"); + } + if (this.getGbAddress() != null) { + content.append("
" + this.getGbAddress() + "
\n"); + } + if (this.getGbRegisterWay() != null) { + content.append("" + this.getGbRegisterWay() + "\n"); + } + if (this.getGbSecrecy() != null) { + content.append("" + this.getGbSecrecy() + "\n"); + } + if (this.getGbParentId() != null) { + content.append("" + this.getGbParentId() + "\n"); + } + if (this.getGbParental() != null) { + content.append("" + this.getGbParental() + "\n"); + } + if (this.getGbSafetyWay() != null) { + content.append("" + this.getGbSafetyWay() + "\n"); + } + if (this.getGbRegisterWay() != null) { + content.append("" + this.getGbRegisterWay() + "\n"); + } + if (this.getGbCertNum() != null) { + content.append("" + this.getGbCertNum() + "\n"); + } + if (this.getGbCertifiable() != null) { + content.append("" + this.getGbCertifiable() + "\n"); + } + if (this.getGbErrCode() != null) { + content.append("" + this.getGbErrCode() + "\n"); + } + if (this.getGbEndTime() != null) { + content.append("" + this.getGbEndTime() + "\n"); + } + if (this.getGbSecrecy() != null) { + content.append("" + this.getGbSecrecy() + "\n"); + } + if (this.getGbIpAddress() != null) { + content.append("" + this.getGbIpAddress() + "\n"); + } + if (this.getGbPort() != null) { + content.append("" + this.getGbPort() + "\n"); + } + if (this.getGbPassword() != null) { + content.append("" + this.getGbPassword() + "\n"); + } + if (this.getGbStatus() != null) { + content.append("" + this.getGbStatus() + "\n"); + } + if (this.getGbLongitude() != null) { + content.append("" + this.getGbLongitude() + "\n"); + } + if (this.getGbLatitude() != null) { + content.append("" + this.getGbLatitude() + "\n"); + } + content.append("\n"); + + if (this.getGbPtzType() != null) { + content.append(" " + this.getGbPtzType() + "\n"); + } + if (this.getGbPositionType() != null) { + content.append(" " + this.getGbPositionType() + "\n"); + } + if (this.getGbRoomType() != null) { + content.append(" " + this.getGbRoomType() + "\n"); + } + if (this.getGbUseType() != null) { + content.append(" " + this.getGbUseType() + "\n"); + } + if (this.getGbSupplyLightType() != null) { + content.append(" " + this.getGbSupplyLightType() + "\n"); + } + if (this.getGbDirectionType() != null) { + content.append(" " + this.getGbDirectionType() + "\n"); + } + if (this.getGbResolution() != null) { + content.append(" " + this.getGbResolution() + "\n"); + } + if (this.getGbBusinessGroupId() != null) { + content.append(" " + this.getGbBusinessGroupId() + "\n"); + } + if (this.getGbDownloadSpeed() != null) { + content.append(" " + this.getGbDownloadSpeed() + "\n"); + } + if (this.getGbSvcSpaceSupportMod() != null) { + content.append(" " + this.getGbSvcSpaceSupportMod() + "\n"); + } + if (this.getGbSvcTimeSupportMode() != null) { + content.append(" " + this.getGbSvcTimeSupportMode() + "\n"); + } + content.append("\n"); } } if (event != null) { @@ -332,7 +422,7 @@ public class CommonGBChannel { // 业务分组 channel.setGbName(group.getName()); channel.setGbDeviceId(group.getDeviceId()); - }else { + } else { // 虚拟组织 channel.setGbName(group.getName()); channel.setGbDeviceId(group.getDeviceId()); @@ -352,8 +442,15 @@ public class CommonGBChannel { commonGBChannel.setGbAddress(platform.getAddress()); commonGBChannel.setGbRegisterWay(platform.getRegisterWay()); commonGBChannel.setGbSecrecy(platform.getSecrecy()); - commonGBChannel.setGbStatus(platform.isStatus()?"ON":"OFF"); + commonGBChannel.setGbStatus(platform.isStatus() ? "ON" : "OFF"); return commonGBChannel; } + public static CommonGBChannel build(Region region) { + CommonGBChannel commonGBChannel = new CommonGBChannel(); + commonGBChannel.setGbDeviceId(region.getDeviceId()); + commonGBChannel.setGbName(region.getName()); + return null; + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java index c0b10691..2b261c44 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java @@ -164,8 +164,11 @@ public interface GroupMapper { @Select(" ") - List queryInChannelList(List channelList); + List queryInChannelList(List channelList); + + + @Select(" ") + List queryParentInChannelList(List regionChannelList); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java index 0a509763..a3b5d470 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/GbChannelServiceImpl.java @@ -328,15 +328,20 @@ public class GbChannelServiceImpl implements IGbChannelService { // 是否包含行政区划信息 if (platform.getCatalogWithRegion()) { - List regionChannelList = regionMapper.queryInChannelList(commonGBChannelList); + List regionChannelList = regionMapper.queryInChannelList(commonGBChannelList); if (!regionChannelList.isEmpty()) { - channelList.addAll(regionChannelList); + // 获取这些节点的所有父节点 + List allRegion = getAllRegion(regionChannelList); + for (Region region : allRegion) { + channelList.add(CommonGBChannel.build(region)); + } } } // 是否包含分组信息 if (platform.getCatalogWithGroup()) { List groupChannelList = groupMapper.queryInChannelList(commonGBChannelList); if (!groupChannelList.isEmpty()) { + // 获取这些节点的所有父节点 channelList.addAll(groupChannelList); } } @@ -344,6 +349,19 @@ public class GbChannelServiceImpl implements IGbChannelService { return channelList; } + private List getAllRegion(List regionChannelList ) { + if (regionChannelList.isEmpty()) { + return new ArrayList<>(); + } + List channelList = regionMapper.queryParentInChannelList(regionChannelList); + if (channelList.isEmpty()) { + return channelList; + } + List allParentRegion = getAllRegion(channelList); + channelList.addAll(allParentRegion); + return channelList; + } + @Override public CommonGBChannel getOne(int id) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java index 4cddba52..1c622b99 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java @@ -204,19 +204,19 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { } sendCatalogResponse(channels, parentPlatform, sn, fromTag, 0, true); } - private String getCatalogXml(List channels, String sn, Platform parentPlatform, int size) { - String characterSet = parentPlatform.getCharacterSet(); + private String getCatalogXml(List channels, String sn, Platform platform, int size) { + String characterSet = platform.getCharacterSet(); StringBuffer catalogXml = new StringBuffer(600); catalogXml.append("\r\n") .append("\r\n") .append("Catalog\r\n") .append("" +sn + "\r\n") - .append("" + parentPlatform.getDeviceGBId() + "\r\n") + .append("" + platform.getDeviceGBId() + "\r\n") .append("" + size + "\r\n") .append("\r\n"); if (!channels.isEmpty()) { for (CommonGBChannel channel : channels) { - catalogXml.append(channel.encode()); + catalogXml.append(channel.encode(platform.getDeviceGBId())); } } @@ -464,19 +464,19 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { sipSender.transmitRequest(parentPlatform.getDeviceIp(), notifyRequest, errorEvent, okEvent); } - private String getCatalogXmlContentForCatalogAddOrUpdate(Platform parentPlatform, List channels, int sumNum, String type, SubscribeInfo subscribeInfo) { + private String getCatalogXmlContentForCatalogAddOrUpdate(Platform platform, List channels, int sumNum, String type, SubscribeInfo subscribeInfo) { StringBuffer catalogXml = new StringBuffer(600); - String characterSet = parentPlatform.getCharacterSet(); + String characterSet = platform.getCharacterSet(); catalogXml.append("\r\n") .append("\r\n") .append("Catalog\r\n") .append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n") - .append("" + parentPlatform.getDeviceGBId() + "\r\n") + .append("" + platform.getDeviceGBId() + "\r\n") .append(""+ sumNum +"\r\n") .append("\r\n"); if (!channels.isEmpty()) { for (CommonGBChannel channel : channels) { - catalogXml.append(channel.encode(type)); + catalogXml.append(channel.encode(type, platform.getDeviceGBId())); } } catalogXml.append("\r\n") @@ -523,20 +523,20 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { }); } - private String getCatalogXmlContentForCatalogOther(Platform parentPlatform, List channels, String type) { + private String getCatalogXmlContentForCatalogOther(Platform platform, List channels, String type) { - String characterSet = parentPlatform.getCharacterSet(); + String characterSet = platform.getCharacterSet(); StringBuffer catalogXml = new StringBuffer(600); catalogXml.append("\r\n") .append("\r\n") .append("Catalog\r\n") .append("" + (int) ((Math.random() * 9 + 1) * 100000) + "\r\n") - .append("" + parentPlatform.getDeviceGBId() + "\r\n") + .append("" + platform.getDeviceGBId() + "\r\n") .append("1\r\n") .append("\r\n"); if (!channels.isEmpty()) { for (CommonGBChannel channel : channels) { - catalogXml.append(channel.encode(type)); + catalogXml.append(channel.encode(type, platform.getDeviceGBId())); } } catalogXml.append("\r\n")