From 052bbf16c38cba6cc6c4e2ec6f70b327610fd219 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: Sun, 7 Jul 2024 07:28:54 +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 --- .../gb28181/dao/CommonGBChannelMapper.java | 6 ++ .../gb28181/service/IGbChannelService.java | 2 + .../service/impl/GbChannelServiceImpl.java | 72 +++++++++++++++++-- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java index 872e9de32..e1755f311 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/CommonGBChannelMapper.java @@ -4,6 +4,8 @@ import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import org.apache.ibatis.annotations.*; import org.springframework.stereotype.Repository; +import java.util.List; + @Mapper @Repository public interface CommonGBChannelMapper { @@ -294,4 +296,8 @@ public interface CommonGBChannelMapper { int update(CommonGBChannel commonGBChannel); int updateStatus(@Param("gbId") int gbId, @Param("status") int status); + + int updateStatusForList(List commonGBChannels, @Param("status") int status); + + List queryInListByStatus(List commonGBChannelList, @Param("status") int status); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java index 4007d19c3..57bbc127d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IGbChannelService.java @@ -24,6 +24,8 @@ public interface IGbChannelService { void closeSend(CommonGBChannel commonGBChannel); + void closeSend(List commonGBChannelList); + void batchAdd(List commonGBChannels); void updateStatus(List channelList); 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 3e2023e0d..58e9e338f 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 @@ -44,6 +44,8 @@ public class GbChannelServiceImpl implements IGbChannelService { }catch (Exception e) { log.warn("[通道移除通知] 发送失败,{}", channel.getGbDeviceId(), e); } + // 结束发送 + closeSend(channel); } return 1; } @@ -91,10 +93,34 @@ public class GbChannelServiceImpl implements IGbChannelService { log.warn("[多个通道离线] 通道数量为0,更新失败"); return 0; } - int result = 0; - for (CommonGBChannel channel : commonGBChannelList) { - result += offline(channel); + List onlineChannelList = commonGBChannelMapper.queryInListByStatus(commonGBChannelList, 1); + if (onlineChannelList.isEmpty()) { + log.warn("[多个通道离线] 更新失败, 参数内通道已经离线"); + return 0; } + int limitCount = 1000; + int result = 0; + if (onlineChannelList.size() > limitCount) { + for (int i = 0; i < onlineChannelList.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > onlineChannelList.size()) { + toIndex = onlineChannelList.size(); + } + result += commonGBChannelMapper.updateStatusForList(onlineChannelList.subList(i, toIndex), 0); + } + }else { + result += commonGBChannelMapper.updateStatusForList(onlineChannelList, 0); + } + if (result > 0) { + try { + // 发送catalog + eventPublisher.catalogEventPublish(null, onlineChannelList, CatalogEvent.OFF); + }catch (Exception e) { + log.warn("[多个通道离线] 发送失败,数量:{}", onlineChannelList.size(), e); + } + } + // 结束国标级联的发送 + closeSend(onlineChannelList); return result; } @@ -123,10 +149,34 @@ public class GbChannelServiceImpl implements IGbChannelService { log.warn("[多个通道上线] 通道数量为0,更新失败"); return 0; } - int result = 0; - for (CommonGBChannel channel : commonGBChannelList) { - result += online(channel); + List offlineChannelList = commonGBChannelMapper.queryInListByStatus(commonGBChannelList, 0); + if (offlineChannelList.isEmpty()) { + log.warn("[多个通道上线] 更新失败, 参数内通道已经上线线"); + return 0; } + // 批量更新 + int limitCount = 1000; + int result = 0; + if (offlineChannelList.size() > limitCount) { + for (int i = 0; i < offlineChannelList.size(); i += limitCount) { + int toIndex = i + limitCount; + if (i + limitCount > offlineChannelList.size()) { + toIndex = offlineChannelList.size(); + } + result += commonGBChannelMapper.updateStatusForList(offlineChannelList.subList(i, toIndex), 1); + } + }else { + result += commonGBChannelMapper.updateStatusForList(offlineChannelList, 1); + } + if (result > 0) { + try { + // 发送catalog + eventPublisher.catalogEventPublish(null, offlineChannelList, CatalogEvent.ON); + }catch (Exception e) { + log.warn("[多个通道上线] 发送失败,数量:{}", offlineChannelList.size(), e); + } + } + return result; } @@ -135,6 +185,16 @@ public class GbChannelServiceImpl implements IGbChannelService { } + @Override + @Transactional + public void closeSend(List commonGBChannelList) { + if (!commonGBChannelList.isEmpty()) { + for (CommonGBChannel commonGBChannel : commonGBChannelList) { + closeSend(commonGBChannel); + } + } + } + @Override public void batchAdd(List commonGBChannels) {