diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java index 3311a249..d23eec4b 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/PlatformChannelMapper.java @@ -540,4 +540,12 @@ public interface PlatformChannelMapper { " ") Set queryShareGroup(@Param("platformId") Integer platformId); + @Select(" ") + Set queryShareRegion(Integer id); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java index f6a584df..e03e0907 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/IPlatformChannelService.java @@ -1,9 +1,6 @@ package com.genersoft.iot.vmp.gb28181.service; -import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; -import com.genersoft.iot.vmp.gb28181.bean.Group; -import com.genersoft.iot.vmp.gb28181.bean.Platform; -import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel; +import com.genersoft.iot.vmp.gb28181.bean.*; import com.github.pagehelper.PageInfo; import java.util.List; @@ -47,4 +44,6 @@ public interface IPlatformChannelService { CommonGBChannel queryChannelByPlatformIdAndChannelId(Integer platformId, Integer channelId); void checkRegionAdd(List channelList); + + void checkRegionRemove(List channelList, List regionList); } 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 a7ff3c7a..0abf38ac 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 @@ -442,6 +442,14 @@ public class GbChannelServiceImpl implements IGbChannelService { throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); } int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + Region region = regionMapper.queryByDeviceId(civilCode); + if (region == null) { + platformChannelService.checkRegionRemove(channelList, null); + }else { + List regionList = new ArrayList<>(); + regionList.add(region); + platformChannelService.checkRegionRemove(channelList, regionList); + } // TODO 发送通知 // if (result > 0) { // try { @@ -460,6 +468,8 @@ public class GbChannelServiceImpl implements IGbChannelService { throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); } int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + + platformChannelService.checkRegionRemove(channelList, null); // TODO 发送通知 // if (result > 0) { // try { @@ -499,6 +509,7 @@ public class GbChannelServiceImpl implements IGbChannelService { throw new ControllerException(ErrorCode.ERROR100.getCode(), "所有通道Id不存在"); } int result = commonGBChannelMapper.removeCivilCodeByChannels(channelList); + platformChannelService.checkRegionRemove(channelList, null); } @Override diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java index b90f67af..71ca0988 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/service/impl/PlatformChannelServiceImpl.java @@ -52,8 +52,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { private ISIPCommanderForPlatform sipCommanderFroPlatform; - - @Override public PageInfo queryChannelList(int page, int count, String query, Integer channelType, Boolean online, Integer platformId, Boolean hasShare) { PageHelper.startPage(page, count); @@ -94,8 +92,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { return regionMapper.queryNotShareRegionForPlatformByRegionList(allRegion, platformId); } - - /** * 移除空的共享,并返回移除的分组 */ @@ -474,6 +470,44 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { } } + @Override + @Transactional + public void checkRegionRemove(List channelList, List regionList) { + List channelIds = new ArrayList<>(); + channelList.stream().forEach(commonGBChannel -> { + channelIds.add(commonGBChannel.getGbId()); + }); + // 获取关联这些通道的平台 + List platformList = platformChannelMapper.queryPlatFormListByChannelList(channelIds); + if (platformList.isEmpty()) { + return; + } + for (Platform platform : platformList) { + Set regionSet; + if (regionList == null || regionList.isEmpty()) { + regionSet = platformChannelMapper.queryShareRegion(platform.getId()); + }else { + regionSet = new HashSet<>(regionList); + } + // 清理空的分组并发送消息 + Set deleteRegion = deleteEmptyRegion(regionSet, platform.getId()); + + List channelListForEvent = new ArrayList<>(); + if (!deleteRegion.isEmpty()) { + for (Region region : deleteRegion) { + channelListForEvent.add(0, CommonGBChannel.build(region)); + } + } + // 发送消息 + try { + // 发送catalog + eventPublisher.catalogEventPublish(platform.getId(), channelListForEvent, CatalogEvent.DEL); + } catch (Exception e) { + log.warn("[移除关联通道] 发送失败,数量:{}", channelList.size(), e); + } + } + } + @Override @Transactional public void checkGroupAdd(List channelList) {