From 0566bf916f4a2ae71cf14d2b3ccb8690dcba36bb Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Thu, 2 Jan 2025 17:26:50 +0800 Subject: [PATCH] =?UTF-8?q?[=E9=9B=86=E7=BE=A4-=E8=87=AA=E5=8A=A8=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E8=BF=87=E5=9B=BD=E6=A0=87=E7=BA=A7=E8=81=94]=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/genersoft/iot/vmp/gb28181/dao/PlatformMapper.java | 2 +- .../iot/vmp/gb28181/service/impl/PlatformServiceImpl.java | 3 ++- .../com/genersoft/iot/vmp/storager/IRedisCatchStorage.java | 2 +- .../genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java | 3 ++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformMapper.java index 3d026ac2..5218537f 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformMapper.java @@ -95,6 +95,6 @@ public interface PlatformMapper { @Select("SELECT server_id FROM wvp_platform WHERE enable=true and server_id != #{serverId} group by server_id") List queryServerIdsWithEnableAndNotInServer(@Param("serverId") String serverId); - @Select("SELECT * FROM wvp_platform WHERE server_id == #{serverId}") + @Select("SELECT * FROM wvp_platform WHERE server_id = #{serverId}") List queryByServerId(@Param("serverId") String serverId); } 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 6cd8abeb..94561f05 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 @@ -120,13 +120,14 @@ public class PlatformServiceImpl implements IPlatformService { log.info("[集群] 检测到 {} 已离线", serverId); // 检查每个是否存活 ServerInfo serverInfo = redisCatchStorage.queryServerInfo(serverId); - if (serverInfo == null && userSetting.getServerId().equals(redisCatchStorage.chooseOneServer())) { + if (serverInfo == null && userSetting.getServerId().equals(redisCatchStorage.chooseOneServer(serverId))) { // 此平台需要选择新平台处理, 确定由当前平台即开始处理 List platformList = platformMapper.queryByServerId(serverId); platformList.forEach(platform -> { log.info("[集群] 由本平台开启上级平台{}({})的注册", platform.getName(), platform.getServerGBId()); // 设置平台使用当前平台的IP platform.setAddress(getIpWithSameNetwork(platform.getAddress())); + platform.setServerId(userSetting.getServerId()); platformMapper.update(platform); // 更新redis redisCatchStorage.delPlatformCatchInfo(platform.getServerGBId()); diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index 66415fc9..1f05a7b4 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -191,7 +191,7 @@ public interface IRedisCatchStorage { ServerInfo queryServerInfo(String serverId); - String chooseOneServer(); + String chooseOneServer(String serverId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index 5e6ab306..4521b0b7 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -545,8 +545,9 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { } @Override - public String chooseOneServer() { + public String chooseOneServer(String serverId) { String key = VideoManagerConstants.WVP_SERVER_LIST; + redisTemplate.opsForZSet().remove(key, serverId); Set range = redisTemplate.opsForZSet().range(key, 0, 0); if (range == null || range.isEmpty()) { return null;