From 141b2282675269e7cd18b78bb3b95e33bb46ccc7 Mon Sep 17 00:00:00 2001 From: gaofw189 Date: Tue, 17 Jan 2023 17:22:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DWVP=E4=BD=9C=E4=B8=BA?= =?UTF-8?q?=E4=B8=8B=E7=BA=A7=E5=B9=B3=E5=8F=B0=E6=8E=A5=E6=94=B6DeviceInf?= =?UTF-8?q?o=E6=8C=87=E4=BB=A4=E5=9B=BA=E5=AE=9A=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../transmit/cmd/ISIPCommanderForPlatform.java | 6 +++--- .../cmd/impl/SIPCommanderFroPlatform.java | 12 ++++++------ .../cmd/DeviceInfoQueryMessageHandler.java | 17 ++++++++++++++++- .../iot/vmp/storager/IVideoManagerStorage.java | 8 +++++++- .../vmp/storager/dao/PlatformChannelMapper.java | 7 +++++++ .../storager/impl/VideoManagerStorageImpl.java | 14 ++++++++++++++ 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java index 0d6da645..0425356a 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommanderForPlatform.java @@ -51,11 +51,11 @@ public interface ISIPCommanderForPlatform { /** * 向上级回复DeviceInfo查询信息 * @param parentPlatform 平台信息 - * @param sn - * @param fromTag + * @param sn SN + * @param fromTag FROM头的tag信息 * @return */ - void deviceInfoResponse(ParentPlatform parentPlatform, String sn, String fromTag) throws SipException, InvalidArgumentException, ParseException; + void deviceInfoResponse(ParentPlatform parentPlatform,Device device, String sn, String fromTag) throws SipException, InvalidArgumentException, ParseException; /** * 向上级回复DeviceStatus查询信息 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 620f0ff9..eb1b0dc5 100644 --- 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 @@ -255,7 +255,7 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { * @return */ @Override - public void deviceInfoResponse(ParentPlatform parentPlatform, String sn, String fromTag) throws SipException, InvalidArgumentException, ParseException { + public void deviceInfoResponse(ParentPlatform parentPlatform,Device device, String sn, String fromTag) throws SipException, InvalidArgumentException, ParseException { if (parentPlatform == null) { return; } @@ -265,11 +265,11 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { deviceInfoXml.append("\r\n"); deviceInfoXml.append("DeviceInfo\r\n"); deviceInfoXml.append("" +sn + "\r\n"); - deviceInfoXml.append("" + parentPlatform.getDeviceGBId() + "\r\n"); - deviceInfoXml.append("" + parentPlatform.getName() + "\r\n"); - deviceInfoXml.append("wvp\r\n"); - deviceInfoXml.append("wvp-28181-2.0\r\n"); - deviceInfoXml.append("2.0.202107\r\n"); + deviceInfoXml.append("" + device.getDeviceId() + "\r\n"); + deviceInfoXml.append("" + device.getName() + "\r\n"); + deviceInfoXml.append("" + device.getManufacturer() + "\r\n"); + deviceInfoXml.append("" + device.getModel() + "\r\n"); + deviceInfoXml.append("" + device.getFirmware() + "\r\n"); deviceInfoXml.append("OK\r\n"); deviceInfoXml.append("\r\n"); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceInfoQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceInfoQueryMessageHandler.java index df6e056a..0faf2945 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceInfoQueryMessageHandler.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/DeviceInfoQueryMessageHandler.java @@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform; import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessageHandler; import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.query.QueryMessageHandler; +import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import gov.nist.javax.sip.message.SIPRequest; import org.dom4j.Element; import org.slf4j.Logger; @@ -21,6 +22,8 @@ import javax.sip.header.FromHeader; import javax.sip.message.Response; import java.text.ParseException; +import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText; + @Component public class DeviceInfoQueryMessageHandler extends SIPRequestProcessorParent implements InitializingBean, IMessageHandler { @@ -32,6 +35,8 @@ public class DeviceInfoQueryMessageHandler extends SIPRequestProcessorParent imp @Autowired private SIPCommanderFroPlatform cmderFroPlatform; + @Autowired + private IVideoManagerStorage storager; @Override public void afterPropertiesSet() throws Exception { @@ -52,10 +57,20 @@ public class DeviceInfoQueryMessageHandler extends SIPRequestProcessorParent imp responseAck((SIPRequest) evt.getRequest(), Response.OK); } catch (SipException | InvalidArgumentException | ParseException e) { logger.error("[命令发送失败] DeviceInfo查询回复: {}", e.getMessage()); + return; } String sn = rootElement.element("SN").getText(); + /*根据WVP原有的数据结构,设备和通道是分开放置,设备信息都是存放在设备表里,通道表里的设备信息不可作为真实信息处理 + 大部分NVR/IPC设备对他的通道信息实现都是返回默认的值没有什么参考价值。NVR/IPC通道我们统一使用设备表的设备信息来作为返回。 + 我们这里使用查询数据库的方式来实现这个设备信息查询的功能,在其他地方对设备信息更新达到正确的目的。*/ + String channelId = getText(rootElement, "DeviceID"); + Device device = storager.queryDeviceInfoByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId); + if (device ==null){ + logger.error("[平台没有该通道的使用权限]:platformId"+parentPlatform.getServerGBId()+" deviceID:"+channelId); + return; + } try { - cmderFroPlatform.deviceInfoResponse(parentPlatform, sn, fromHeader.getTag()); + cmderFroPlatform.deviceInfoResponse(parentPlatform,device, sn, fromHeader.getTag()); } catch (SipException | InvalidArgumentException | ParseException e) { logger.error("[命令发送失败] 国标级联 DeviceInfo查询回复: {}", e.getMessage()); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java index b4644bfb..b88794d0 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorage.java @@ -186,7 +186,13 @@ public interface IVideoManagerStorage { Device queryVideoDeviceByPlatformIdAndChannelId(String platformId, String channelId); - + /** + * 针对deviceinfo指令的查询接口 + * @param platformId 平台id + * @param channelId 通道id + * @return 设备信息 + */ + Device queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId); /** * 添加Mobile Position设备移动位置 * @param mobilePosition diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java index b98b9485..35a42c57 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java @@ -107,4 +107,11 @@ public interface PlatformChannelMapper { "DELETE FROM platform_gb_channel WHERE platformId=#{platformId} and catalogId=#{catalogId}" + "") int delChannelForGBByCatalogId(String platformId, String catalogId); + + @Select("select dc.channelId deviceId,dc.name,d.manufacturer,d.model,d.firmware\n" + + "from platform_gb_channel pgc\n" + + " left join device_channel dc on dc.id = pgc.deviceChannelId\n" + + " left join device d on dc.deviceId = d.deviceId\n" + + "where dc.channelId = #{channelId} and pgc.platformId=#{platformId}") + List queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java index c773036f..3bc4e4ed 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java @@ -471,6 +471,20 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage { } + @Override + public Device queryDeviceInfoByPlatformIdAndChannelId(String platformId, String channelId) { + List devices = platformChannelMapper.queryDeviceInfoByPlatformIdAndChannelId(platformId, channelId); + if (devices.size() > 1) { + // 出现长度大于0的时候肯定是国标通道的ID重复了 + logger.warn("国标ID存在重复:{}", channelId); + } + if (devices.size() == 0) { + return null; + }else { + return devices.get(0); + } + } + /** * 查询最新移动位置 * @param deviceId