From 42322c75cc4df1a02b2faed44f8226061a1c81df Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 3 Jan 2025 16:21:20 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=9B=86=E7=BE=A4]=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=9B=BD=E6=A0=87=E7=BA=A7=E8=81=94=E7=9B=AE=E5=BD=95=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/gb28181/event/EventPublisher.java | 26 ++++++++++++------- .../subscribe/catalog/CatalogEventLister.java | 10 +++---- .../service/redisMsg/IRedisRpcService.java | 3 ++- .../control/RedisRpcPlatformController.java | 17 +++--------- .../redisMsg/service/RedisRpcServiceImpl.java | 13 +++++----- 5 files changed, 31 insertions(+), 38 deletions(-) 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 62ad621e..4fd171ef 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 @@ -35,10 +35,10 @@ public class EventPublisher { private ApplicationEventPublisher applicationEventPublisher; @Autowired - private UserSetting userSetting; + private UserSetting userSetting; @Autowired - private IRedisRpcService redisRpcService; + private IRedisRpcService redisRpcService; /** * 设备报警事件 @@ -76,15 +76,15 @@ public class EventPublisher { } public void catalogEventPublish(Platform platform, List deviceChannels, String type) { - if (!userSetting.getServerId().equals(platform.getServerId())) { - List ids = new ArrayList<>(); - for (int i = 0; i < deviceChannels.size(); i++) { - ids.add(deviceChannels.get(i).getGbId()); - } - redisRpcService.catalogEventPublish(platform.getServerId(), platform.getId(), ids, type); + if (platform != null && !userSetting.getServerId().equals(platform.getServerId())) { + // 指定了上级平台的推送,则发送到指定的设备,未指定的则全部发送, 接收后各自处理自己的 + CatalogEvent outEvent = new CatalogEvent(this); + outEvent.setChannels(deviceChannels); + outEvent.setType(type); + outEvent.setPlatform(platform); + redisRpcService.catalogEventPublish(platform.getServerId(), outEvent); return; } - CatalogEvent outEvent = new CatalogEvent(this); List channels = new ArrayList<>(); if (deviceChannels.size() > 1) { @@ -103,6 +103,14 @@ public class EventPublisher { outEvent.setType(type); outEvent.setPlatform(platform); applicationEventPublisher.publishEvent(outEvent); + if (platform == null) { + // 如果没指定上级平台,则推送消息到所有在线的wvp处理自己含有的平台的目录更新 + redisRpcService.catalogEventPublish(null, outEvent); + } + } + + public void catalogEventPublish(CatalogEvent event) { + applicationEventPublisher.publishEvent(event); } public void mobilePositionEventPublish(MobilePosition mobilePosition) { diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java index 6b64c05e..08a32902 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEventLister.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; +import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.Platform; import com.genersoft.iot.vmp.gb28181.bean.SubscribeHolder; @@ -7,6 +8,7 @@ import com.genersoft.iot.vmp.gb28181.bean.SubscribeInfo; import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService; import com.genersoft.iot.vmp.gb28181.service.IPlatformService; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; +import com.genersoft.iot.vmp.service.redisMsg.IRedisRpcService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; @@ -15,10 +17,7 @@ import org.springframework.stereotype.Component; import javax.sip.InvalidArgumentException; import javax.sip.SipException; import java.text.ParseException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * catalog事件 @@ -30,9 +29,6 @@ public class CatalogEventLister implements ApplicationListener { @Autowired private IPlatformChannelService platformChannelService; - @Autowired - private IPlatformService platformService; - @Autowired private ISIPCommanderForPlatform sipCommanderFroPlatform; diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java index 8c34a7e5..ba372a18 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/IRedisRpcService.java @@ -4,6 +4,7 @@ import com.genersoft.iot.vmp.common.CommonCallback; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.bean.Platform; import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.vmanager.bean.WVPResult; import java.util.List; @@ -33,5 +34,5 @@ public interface IRedisRpcService { boolean updatePlatform(String serverId, Platform platform); - void catalogEventPublish(String serverId, Integer platformId, List channelIds, String type); + void catalogEventPublish(String serverId, CatalogEvent catalogEvent); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcPlatformController.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcPlatformController.java index 50865f15..860008f3 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcPlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/control/RedisRpcPlatformController.java @@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; 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.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.service.IPlatformChannelService; import com.genersoft.iot.vmp.gb28181.service.IPlatformService; import com.genersoft.iot.vmp.service.redisMsg.dto.RedisRpcController; @@ -70,21 +71,9 @@ public class RedisRpcPlatformController extends RpcController { */ @RedisRpcMapping("catalogEventPublish") public RedisRpcResponse catalogEventPublish(RedisRpcRequest request) { - JSONObject jsonObject = JSONObject.parseObject(request.getParam().toString()); - int platformId = jsonObject.getIntValue("platformId"); - Integer[] channelIds = jsonObject.getJSONArray("channelIds").toArray(Integer.class); - String type = jsonObject.getString("type"); + CatalogEvent event = JSONObject.parseObject(request.getParam().toString(), CatalogEvent.class); + eventPublisher.catalogEventPublish(event); RedisRpcResponse response = request.getResponse(); - - Platform platform = platformService.queryOne(platformId); - if (platform == null ) { - log.warn("[]"); - response.setStatusCode(ErrorCode.ERROR400.getCode()); - response.setBody(ErrorCode.ERROR400.getMsg()); - return response; - } - List commonGBChannels = platformChannelService.queryChannelByPlatformIdAndChannelIds(platformId, Arrays.asList(channelIds)); - eventPublisher.catalogEventPublish(platform, commonGBChannels, type); response.setStatusCode(ErrorCode.SUCCESS.getCode()); return response; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java index 4d6d9f1c..5b22719c 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/redisMsg/service/RedisRpcServiceImpl.java @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcRequest; import com.genersoft.iot.vmp.conf.redis.bean.RedisRpcResponse; import com.genersoft.iot.vmp.gb28181.bean.Platform; import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo; +import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.media.event.hook.Hook; import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; @@ -234,13 +235,11 @@ public class RedisRpcServiceImpl implements IRedisRpcService { } @Override - public void catalogEventPublish(String serverId, Integer platformId, List channelIds, String type) { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("platformId", platformId); - jsonObject.put("channelIds", channelIds); - jsonObject.put("type", type); - RedisRpcRequest request = buildRequest("platform/catalogEventPublish", jsonObject); - request.setToId(serverId); + public void catalogEventPublish(String serverId, CatalogEvent event) { + RedisRpcRequest request = buildRequest("platform/catalogEventPublish", event); + if (serverId != null) { + request.setToId(serverId); + } redisRpcConfig.request(request, 100); } }