From 1efb5fca0f9f37d677b8005ec45c18ba901b450e Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 28 Aug 2024 18:00:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/bean/SubscribeHolder.java | 6 +++ .../iot/vmp/gb28181/event/EventPublisher.java | 7 ++++ .../catalog/CatalogSubscribePutEvent.java | 21 ++++++++++ .../CatalogSubscribePutEventLister.java | 41 +++++++++++++++++++ .../service/impl/PlatformServiceImpl.java | 1 + 5 files changed, 76 insertions(+) create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEvent.java create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEventLister.java diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java index a15de224..28fa1e43 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/SubscribeHolder.java @@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.gb28181.bean; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.conf.DynamicTask; import com.genersoft.iot.vmp.conf.UserSetting; +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.task.ISubscribeTask; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -23,6 +24,9 @@ public class SubscribeHolder { @Autowired private UserSetting userSetting; + @Autowired + private EventPublisher eventPublisher; + private final String taskOverduePrefix = "subscribe_overdue_"; private static ConcurrentHashMap catalogMap = new ConcurrentHashMap<>(); @@ -37,6 +41,8 @@ public class SubscribeHolder { // 添加任务处理订阅过期 dynamicTask.startDelay(taskOverdueKey, () -> removeCatalogSubscribe(subscribeInfo.getId()), subscribeInfo.getExpires() * 1000); + // 发送目录订阅添加通知 + eventPublisher.catalogSubscribePutEventPublish(platformId, subscribeInfo); } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java index 2a28aabb..36541589 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.gb28181.event.alarm.AlarmEvent; import com.genersoft.iot.vmp.gb28181.event.device.RequestTimeoutEvent; import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogSubscribePutEvent; import com.genersoft.iot.vmp.gb28181.event.subscribe.mobilePosition.MobilePositionEvent; import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerOfflineEvent; import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerOnlineEvent; @@ -106,4 +107,10 @@ public class EventPublisher { applicationEventPublisher.publishEvent(outEvent); } + public void catalogSubscribePutEventPublish(String platformId, SubscribeInfo subscribeInfo) { + CatalogSubscribePutEvent event = new CatalogSubscribePutEvent(this); + event.setPlatformId(platformId); + event.setSubscribeInfo(subscribeInfo); + applicationEventPublisher.publishEvent(event); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEvent.java new file mode 100644 index 00000000..905e46bd --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEvent.java @@ -0,0 +1,21 @@ +package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; + +import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.ApplicationEvent; + +public class CatalogSubscribePutEvent extends ApplicationEvent { + + public CatalogSubscribePutEvent(Object source) { + super(source); + } + + @Getter + @Setter + private SubscribeInfo subscribeInfo; + + @Getter + @Setter + private String platformId; +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEventLister.java new file mode 100644 index 00000000..d3b92621 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogSubscribePutEventLister.java @@ -0,0 +1,41 @@ +package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; + +import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; +import com.genersoft.iot.vmp.gb28181.bean.Platform; +import com.genersoft.iot.vmp.gb28181.event.EventPublisher; +import com.genersoft.iot.vmp.gb28181.service.IPlatformService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationListener; +import org.springframework.stereotype.Component; + +@Slf4j +@Component +public class CatalogSubscribePutEventLister implements ApplicationListener { + + @Autowired + private IPlatformService platformService; + + @Autowired + private EventPublisher eventPublisher; + + + @Override + public void onApplicationEvent(CatalogSubscribePutEvent event) { + + Platform platform = platformService.queryPlatformByServerGBId(event.getPlatformId()); + if (platform == null){ + return; + } + + CommonGBChannel channel = CommonGBChannel.build(platform); + + // 发送消息 + try { + // 发送catalog + eventPublisher.catalogEventPublish(platform.getId(), channel, CatalogEvent.ADD); + } catch (Exception e) { + log.warn("[推送平台信息] 发送失败,平台{}({})", platform.getName(), platform.getServerGBId(), e); + } + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java index 7f47232f..1f39e4d7 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformServiceImpl.java @@ -319,6 +319,7 @@ public class PlatformServiceImpl implements IPlatformService { if (subscribeHolder.getCatalogSubscribe(platform.getServerGBId()) == null) { log.info("[国标级联]:{}, 添加自动通道推送模拟订阅信息", platform.getServerGBId()); addSimulatedSubscribeInfo(platform); + } }else { SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());