From c4aeef62ef54b0706a35348b3d1fc876e1d8be8c Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 4 Dec 2023 21:56:21 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/common.sql | 25 +++----- .../storager/dao/CommonGbChannelMapper.java | 64 +++++++++---------- .../vmp/storager/dao/DeviceChannelMapper.java | 2 +- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/sql/common.sql b/sql/common.sql index deb1a247..0f3eb5cb 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -1,4 +1,4 @@ -CREATE TABLE `wvp_common_gb_channel` +CREATE TABLE `wvp_common_channel` ( `common_gb_id` bigint unsigned NOT NULL AUTO_INCREMENT, `common_gb_device_id` varchar(50) NOT NULL, @@ -67,11 +67,11 @@ CREATE TABLE `wvp_common_region` UNIQUE KEY `common_region_device_id` (`common_region_device_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -CREATE TABLE `wvp_common_platform_channel` +CREATE TABLE `wvp_common_channel_platform` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, - `platform_id` varchar(50) NOT NULL, - `common_gb_channel_id` varchar(50) NOT NULL, + `platform_id` bigint unsigned NOT NULL, + `common_gb_channel_id` bigint unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), UNIQUE KEY `uk_platform_id_common_gb_channel_id` (`platform_id`,`common_gb_channel_id`) @@ -79,17 +79,12 @@ CREATE TABLE `wvp_common_platform_channel` DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci; -CREATE TABLE `wvp_common_platform_region` -( - `id` bigint unsigned NOT NULL AUTO_INCREMENT, - `platform_id` varchar(50) NOT NULL, - `region_id` varchar(50) NOT NULL, - PRIMARY KEY (`id`), - UNIQUE KEY `id` (`id`), - UNIQUE KEY `uk_platform_region_id` (`platform_id`,`region_id`) -) ENGINE = InnoDB - DEFAULT CHARSET = utf8mb4 - COLLATE = utf8mb4_0900_ai_ci; + +drop table wvp_platform_gb_stream; +drop table wvp_platform_gb_channel; +drop table wvp_platform_catalog; +drop table wvp_platform_gb_channel; +drop table wvp_resources_tree; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java index 441bc882..0f25764f 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -16,12 +16,12 @@ import java.util.Map; @Repository public interface CommonGbChannelMapper { - @Select(value = "select * from wvp_common_gb_channel where common_gb_business_group_id = '#{commonGroupId}'") + @Select(value = "select * from wvp_common_channel where common_gb_business_group_id = '#{commonGroupId}'") List getChannels(String commonGroupId); @Update(value = "") int removeChannelsForGroup(List channels); - @Select("select * from wvp_common_gb_channel where common_gb_device_id=#{channelId}") + @Select("select * from wvp_common_channel where common_gb_device_id=#{channelId}") CommonGbChannel queryByDeviceID(String channelId); @Insert(value = "") int add(CommonGbChannel channel); - @Delete("delete from wvp_common_gb_channel where common_gb_device_id = #{channelId}") + @Delete("delete from wvp_common_channel where common_gb_device_id = #{channelId}") int deleteByDeviceID(String channelId); @Update(value = "") int deleteByDeviceIDs(List clearChannels); @Update("") void channelsOnlineFromList(List channelList); @Update("") void channelsOfflineFromList(List channelList); @Update("") int clearParentIds(List errorParentIdList); @Update("") void clearCivilCodes(List errorCivilCodeList); @Select("") List queryInList(List commonGbChannelList); @Update("") void updateChanelRegion(@Param("commonRegionDeviceIdForOld") String commonRegionDeviceIdForOld, @Param("commonRegionDeviceIdForNew") String commonRegionDeviceIdForNew); @Update("") void updateChanelGroup( @Param("groupDeviceIdForOld") String groupDeviceIdForOld, @Param("groupDeviceIdForNew") String groupDeviceIdForNew); @Select("") List getChannelsInRegion(@Param("regionDeviceId") String regionDeviceId, @Param("query") String query); @Select("") List query(@Param("query") String query); @Select("") void removeGroupInfo(@Param("groupList") List groupList); @@ -379,7 +379,7 @@ public interface CommonGbChannelMapper { @Update({""}) void removeFromGroupByGroupId(@Param("commonGbBusinessGroupID") String commonGbBusinessGroupID); @Select("") void removeRegionInfo(@Param("regionList") List regionList); @@ -413,7 +413,7 @@ public interface CommonGbChannelMapper { @Update({""}) @@ -431,7 +431,7 @@ public interface CommonGbChannelMapper { @Update({""}) int batchDelete(@Param("ids") List ids); @MapKey("commonGbDeviceID") - @Select("select * from wvp_common_gb_channel") + @Select("select * from wvp_common_channel") Map queryAllChannelsForMap(); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java index dc1358b3..4ba3cac3 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/DeviceChannelMapper.java @@ -476,7 +476,7 @@ public interface DeviceChannelMapper { @Update(" update wvp_device_channel wdc " + " set " + " common_gb_channel_id=" + - " (select wcgc.common_gb_id from wvp_common_gb_channel wcgc where wdc.channel_id = wcgc.common_gb_device_id) " + + " (select wcgc.common_gb_id from wvp_common_channel wcgc where wdc.channel_id = wcgc.common_gb_device_id) " + " where wdc.device_id = #{deviceId}") int updateCommonChannelId(@Param("deviceId") String deviceId); From 0d3845af5925e8f6c64e7351e9ec5e82788d7264 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 5 Dec 2023 23:23:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=B1=E4=BA=AB=E5=88=B0=E4=B8=8A=E7=BA=A7=E5=B9=B3=E5=8F=B0?= =?UTF-8?q?=E7=9A=84=E9=80=9A=E9=81=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/common.sql | 9 ++ .../iot/vmp/gb28181/bean/ParentPlatform.java | 35 ++++- .../iot/vmp/gb28181/event/EventPublisher.java | 28 +--- .../event/subscribe/catalog/CatalogEvent.java | 11 +- .../vmp/service/IPlatformChannelService.java | 17 +- .../impl/PlatformChannelServiceImpl.java | 145 +++++------------- .../storager/dao/CommonGbChannelMapper.java | 11 ++ .../storager/dao/ParentPlatformMapper.java | 9 +- .../storager/dao/PlatformChannelMapper.java | 46 +++--- .../gb28181/platform/PlatformController.java | 91 +++-------- .../platform/bean/UpdateChannelParam.java | 35 +---- 11 files changed, 178 insertions(+), 259 deletions(-) diff --git a/sql/common.sql b/sql/common.sql index 0f3eb5cb..609419fc 100644 --- a/sql/common.sql +++ b/sql/common.sql @@ -86,6 +86,15 @@ drop table wvp_platform_catalog; drop table wvp_platform_gb_channel; drop table wvp_resources_tree; +alter table wvp_platform + add share_all_channel bool default false; + +alter table wvp_platform + add share_group bool default true; + +alter table wvp_platform + add share_region bool default false; + diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java index 1638c711..63771144 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/ParentPlatform.java @@ -186,9 +186,18 @@ public class ParentPlatform { @Schema(description = "是否作为消息通道") private boolean asMessageChannel; - @Schema(description = "是否作为消息通道") + @Schema(description = "通道自动推送") private boolean autoPushChannel; + @Schema(description = "是否共享所有通道") + private boolean shareAllChannel; + + @Schema(description = "是否共享分组") + private boolean shareGroup; + + @Schema(description = "是否共享区域") + private boolean shareRegion; + public Integer getId() { return id; } @@ -436,4 +445,28 @@ public class ParentPlatform { public void setAutoPushChannel(boolean autoPushChannel) { this.autoPushChannel = autoPushChannel; } + + public boolean isShareAllChannel() { + return shareAllChannel; + } + + public void setShareAllChannel(boolean shareAllChannel) { + this.shareAllChannel = shareAllChannel; + } + + public boolean isShareGroup() { + return shareGroup; + } + + public void setShareGroup(boolean shareGroup) { + this.shareGroup = shareGroup; + } + + public boolean isShareRegion() { + return shareRegion; + } + + public void setShareRegion(boolean shareRegion) { + this.shareRegion = shareRegion; + } } 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 d56e744d..166cbe14 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 @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.event; +import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.device.RequestTimeoutEvent; import com.genersoft.iot.vmp.gb28181.event.record.RecordEndEvent; @@ -52,10 +53,10 @@ public class EventPublisher { } - public void catalogEventPublish(String platformId, DeviceChannel deviceChannel, String type) { - List deviceChannelList = new ArrayList<>(); - deviceChannelList.add(deviceChannel); - catalogEventPublish(platformId, deviceChannelList, type); + public void catalogEventPublish(String platformId, CommonGbChannel channel, String type) { + List channelList = new ArrayList<>(); + channelList.add(channel); + catalogEventPublish(platformId, channelList, type); } @@ -69,25 +70,12 @@ public class EventPublisher { /** * * @param platformId - * @param deviceChannels + * @param channels * @param type */ - public void catalogEventPublish(String platformId, List deviceChannels, String type) { + public void catalogEventPublish(String platformId, List channels, String type) { CatalogEvent outEvent = new CatalogEvent(this); - List channels = new ArrayList<>(); - if (deviceChannels.size() > 1) { - // 数据去重 - Set gbIdSet = new HashSet<>(); - for (DeviceChannel deviceChannel : deviceChannels) { - if (!gbIdSet.contains(deviceChannel.getChannelId())) { - gbIdSet.add(deviceChannel.getChannelId()); - channels.add(deviceChannel); - } - } - }else { - channels = deviceChannels; - } - outEvent.setDeviceChannels(channels); + outEvent.setChannels(channels); outEvent.setType(type); outEvent.setPlatformId(platformId); applicationEventPublisher.publishEvent(outEvent); diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java index 5c064f75..f08d02aa 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/event/subscribe/catalog/CatalogEvent.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.gb28181.event.subscribe.catalog; +import com.genersoft.iot.vmp.common.CommonGbChannel; import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; import com.genersoft.iot.vmp.gb28181.bean.GbStream; import org.springframework.context.ApplicationEvent; @@ -46,17 +47,17 @@ public class CatalogEvent extends ApplicationEvent { */ public static final String UPDATE = "UPDATE"; - private List deviceChannels; + private List channels; private List gbStreams; private String type; private String platformId; - public List getDeviceChannels() { - return deviceChannels; + public List getChannels() { + return channels; } - public void setDeviceChannels(List deviceChannels) { - this.deviceChannels = deviceChannels; + public void setChannels(List channels) { + this.channels = channels; } public String getType() { diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java index 49d74282..84f922ab 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java +++ b/src/main/java/com/genersoft/iot/vmp/service/IPlatformChannelService.java @@ -1,5 +1,7 @@ package com.genersoft.iot.vmp.service; +import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; import java.util.List; @@ -11,19 +13,12 @@ import java.util.List; public interface IPlatformChannelService { /** - * 更新目录下的通道 - * @param platformId 平台编号 - * @param channelReduces 通道信息 - * @param catalogId 目录编号 - * @return + * 添加共享通道 */ - int updateChannelForGB(String platformId, List channelReduces, String catalogId); + int addChannelForGB(ParentPlatform platform, List commonGbChannelIds); /** - * 移除目录下的所有通道 - * @param platformId - * @param catalogId - * @return + * 移除共享通道 */ - int delAllChannelForGB(String platformId, String catalogId); + int removeChannelForGB(ParentPlatform platform, List commonGbChannelIds); } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java index 3a302c0f..bb8f3169 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlatformChannelServiceImpl.java @@ -1,14 +1,14 @@ package com.genersoft.iot.vmp.service.impl; import com.genersoft.iot.vmp.common.BatchLimit; +import com.genersoft.iot.vmp.common.CommonGbChannel; +import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.service.IPlatformChannelService; -import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; -import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper; -import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper; -import com.genersoft.iot.vmp.storager.dao.PlatformChannelMapper; +import com.genersoft.iot.vmp.storager.dao.*; +import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,6 +17,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.stereotype.Service; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.ObjectUtils; import java.util.ArrayList; @@ -35,6 +36,9 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { @Autowired private PlatformChannelMapper platformChannelMapper; + @Autowired + private CommonGbChannelMapper commonGbChannelMapper; + @Autowired TransactionDefinition transactionDefinition; @@ -58,117 +62,50 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { EventPublisher eventPublisher; @Override - public int updateChannelForGB(String platformId, List channelReduces, String catalogId) { - ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId); - if (platform == null) { - logger.warn("更新级联通道信息时未找到平台{}的信息", platformId); - return 0; + @Transactional + public int addChannelForGB(ParentPlatform platform, List commonGbChannelIds) { + assert platform != null; + // 检查通道Id数据是否都是在数据库中存在的数据 + List commonGbChannelIdsForSave = commonGbChannelMapper.getChannelIdsByIds(commonGbChannelIds); + if (commonGbChannelIdsForSave.isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "有效待关联通道Id为空"); } - Map deviceAndChannels = new HashMap<>(); - for (ChannelReduce channelReduce : channelReduces) { - channelReduce.setCatalogId(catalogId); - deviceAndChannels.put(channelReduce.getId(), channelReduce); + // 去除已经关联的部分通道 + List commonGbChannelIdsInDb = platformChannelMapper.findChannelsInDb(platform.getId(), + commonGbChannelIdsForSave); + if (!commonGbChannelIdsInDb.isEmpty()) { + commonGbChannelIdsForSave.removeAll(commonGbChannelIdsInDb); } - List deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet()); - // 查询当前已经存在的 - List channelIds = platformChannelMapper.findChannelRelatedPlatform(platformId, channelReduces); - if (deviceAndChannelList != null) { - deviceAndChannelList.removeAll(channelIds); + if (commonGbChannelIdsForSave.isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "有效待关联通道Id为空"); } - for (Integer channelId : channelIds) { - deviceAndChannels.remove(channelId); - } - List channelReducesToAdd = new ArrayList<>(deviceAndChannels.values()); - // 对剩下的数据进行存储 int allCount = 0; - boolean result = false; - TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition); - if (!channelReducesToAdd.isEmpty()) { - if (channelReducesToAdd.size() > BatchLimit.count) { - for (int i = 0; i < channelReducesToAdd.size(); i += BatchLimit.count) { - int toIndex = i + BatchLimit.count; - if (i + BatchLimit.count > channelReducesToAdd.size()) { - toIndex = channelReducesToAdd.size(); - } - int count = platformChannelMapper.addChannels(platformId, channelReducesToAdd.subList(i, toIndex)); - result = result || count < 0; - allCount += count; - logger.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, channelReducesToAdd.size(), toIndex); + if (commonGbChannelIdsForSave.size() > BatchLimit.count) { + for (int i = 0; i < commonGbChannelIdsForSave.size(); i += BatchLimit.count) { + int toIndex = i + BatchLimit.count; + if (i + BatchLimit.count > commonGbChannelIdsForSave.size()) { + toIndex = commonGbChannelIdsForSave.size(); } - }else { - allCount = platformChannelMapper.addChannels(platformId, channelReducesToAdd); - result = result || allCount < 0; - logger.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platformId, channelReducesToAdd.size()); + int count = platformChannelMapper.addChannels(platform.getId(), commonGbChannelIdsForSave.subList(i, toIndex)); + allCount += count; + logger.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platform.getServerGBId(), commonGbChannelIdsForSave.size(), allCount); } - - if (result) { - //事务回滚 - dataSourceTransactionManager.rollback(transactionStatus); - allCount = 0; - }else { - logger.info("[关联通道]国标通道 平台:{}, 正在存入数据库", platformId); - dataSourceTransactionManager.commit(transactionStatus); - + }else { + allCount = platformChannelMapper.addChannels(platform.getId(), commonGbChannelIdsForSave); + logger.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platform.getServerGBId(), commonGbChannelIdsForSave.size()); + } + SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId()); + if (catalogSubscribe != null) { + List channelList = commonGbChannelMapper.queryInIdList(commonGbChannelIdsForSave); + if (channelList != null) { + eventPublisher.catalogEventPublish(platform.getServerGBId(), channelList, CatalogEvent.ADD); } - SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId); - if (catalogSubscribe != null) { - List deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform); - if (deviceChannelList != null) { - eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD); - } - } - logger.info("[关联通道]国标通道 平台:{}, 存入数据库成功", platformId); } return allCount; } - private List getDeviceChannelListByChannelReduceList(List channelReduces, String catalogId, ParentPlatform platform) { - List deviceChannelList = new ArrayList<>(); - if (channelReduces.size() > 0){ - PlatformCatalog catalog = catalogManager.selectByPlatFormAndCatalogId(platform.getServerGBId(),catalogId); - if (catalog == null && catalogId.equals(platform.getDeviceGBId())) { - for (ChannelReduce channelReduce : channelReduces) { - DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); - deviceChannel.setParental(0); - deviceChannel.setCivilCode(platform.getServerGBDomain()); - deviceChannelList.add(deviceChannel); - } - return deviceChannelList; - } else if (catalog == null || !catalogId.equals(platform.getDeviceGBId())) { - logger.warn("未查询到目录{}的信息", catalogId); - return null; - } - for (ChannelReduce channelReduce : channelReduces) { - DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId()); - deviceChannel.setParental(0); - deviceChannel.setCivilCode(catalog.getCivilCode()); - deviceChannel.setParentId(catalog.getParentId()); - deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId()); - deviceChannelList.add(deviceChannel); - } - } - return deviceChannelList; - } - @Override - public int delAllChannelForGB(String platformId, String catalogId) { - - int result; - if (platformId == null) { - return 0; - } - ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId); - if (platform == null) { - return 0; - } - if (ObjectUtils.isEmpty(catalogId)) { - catalogId = platform.getDeviceGBId(); - } - - if ((result = platformChannelMapper.delChannelForGBByCatalogId(platformId, catalogId)) > 0) { - List deviceChannels = platformChannelMapper.queryAllChannelInCatalog(platformId, catalogId); - eventPublisher.catalogEventPublish(platformId, deviceChannels, CatalogEvent.DEL); - } - return result; + public int removeChannelForGB(ParentPlatform platform, List commonGbChannelIds) { + return 0; } } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java index 0f25764f..d90c22d6 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CommonGbChannelMapper.java @@ -577,4 +577,15 @@ public interface CommonGbChannelMapper { @Select("select * from wvp_common_channel") Map queryAllChannelsForMap(); + @Select("") + List queryInIdList(@Param("channelIds") List channelIds); + + @Select("") + List getChannelIdsByIds(@Param("channelIds") List channelIds); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java index 9dc05034..f8d0651c 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/ParentPlatformMapper.java @@ -16,10 +16,12 @@ import java.util.List; public interface ParentPlatformMapper { @Insert("INSERT INTO wvp_platform (enable, name, server_gb_id, server_gb_domain, server_ip, server_port,device_gb_id,device_ip,"+ - "device_port,username,password,expires,keep_timeout,transport,character_set,ptz,rtcp,as_message_channel,auto_push_channel,"+ + "device_port,username,password,expires,keep_timeout,transport,character_set,ptz,rtcp,as_message_channel,auto_push_channel," + + "share_all_channel,share_group,share_region,"+ "status,start_offline_push,catalog_id,administrative_division,catalog_group,create_time,update_time) " + " VALUES (#{enable}, #{name}, #{serverGBId}, #{serverGBDomain}, #{serverIP}, #{serverPort}, #{deviceGBId}, #{deviceIp}, " + - " #{devicePort}, #{username}, #{password}, #{expires}, #{keepTimeout}, #{transport}, #{characterSet}, #{ptz}, #{rtcp}, #{asMessageChannel}, #{autoPushChannel}, " + + " #{devicePort}, #{username}, #{password}, #{expires}, #{keepTimeout}, #{transport}, #{characterSet}, #{ptz}, " + + " #{rtcp}, #{asMessageChannel}, #{autoPushChannel}, #{shareAllChannel}, #{shareGroup}, #{shareRegion}, " + " #{status}, #{startOfflinePush}, #{catalogId}, #{administrativeDivision}, #{catalogGroup}, #{createTime}, #{updateTime})") int addParentPlatform(ParentPlatform parentPlatform); @@ -43,6 +45,9 @@ public interface ParentPlatformMapper { "rtcp=#{rtcp}, " + "as_message_channel=#{asMessageChannel}, " + "auto_push_channel=#{autoPushChannel}, " + + "share_all_channel=#{shareAllChannel}, " + + "share_group=#{shareGroup}, " + + "share_region=#{shareRegion}, " + "status=#{status}, " + "start_offline_push=#{startOfflinePush}, " + "catalog_group=#{catalogGroup}, " + diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java index 38263506..1a210e74 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/PlatformChannelMapper.java @@ -22,64 +22,64 @@ public interface PlatformChannelMapper { * 查询列表里已经关联的 */ @Select("") List findChannelRelatedPlatform(@Param("platformId") String platformId, @Param("channelReduces") List channelReduces); @Insert("") - int addChannels(@Param("platformId") String platformId, @Param("channelReducesToAdd") List channelReducesToAdd); + int addChannels(@Param("platformId") Integer platformId, @Param("channelIds") List channelIds); @Delete("") int delChannelForGB(@Param("platformId") String platformId, @Param("channelReducesToDel") List channelReducesToDel); @Delete("") int delChannelForDeviceId(String deviceId); @Delete("") int cleanChannelForGB(String platformId); - @Select("SELECT dc.* from wvp_platform_gb_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_id=#{channelId} and pgc.platform_id=#{platformId}") + @Select("SELECT dc.* from wvp_common_channel_platform pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_id=#{channelId} and pgc.platform_id=#{platformId}") List queryChannelInParentPlatform(@Param("platformId") String platformId, @Param("channelId") String channelId); - @Select("SELECT dc.* from wvp_platform_gb_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE pgc.platform_id=#{platformId} and pgc.catalog_id=#{catalogId}") + @Select("SELECT dc.* from wvp_common_channel_platform pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE pgc.platform_id=#{platformId} and pgc.catalog_id=#{catalogId}") List queryAllChannelInCatalog(@Param("platformId") String platformId, @Param("catalogId") String catalogId); @Select(" select dc.channel_id as id, dc.name as name, pgc.platform_id as platform_id, pgc.catalog_id as parent_id, 0 as children_count, 1 as type " + - " from wvp_device_channel dc left join wvp_platform_gb_channel pgc on dc.id = pgc.device_channel_id " + + " from wvp_device_channel dc left join wvp_common_channel_platform pgc on dc.id = pgc.device_channel_id " + " where pgc.platform_id=#{platformId} and pgc.catalog_id=#{catalogId}") List queryChannelInParentPlatformAndCatalog(@Param("platformId") String platformId, @Param("catalogId") String catalogId); @Select("select d.*\n" + - "from wvp_platform_gb_channel pgc\n" + + "from wvp_common_channel_platform pgc\n" + " left join wvp_device_channel dc on dc.id = pgc.device_channel_id\n" + " left join wvp_device d on dc.device_id = d.device_id\n" + "where dc.channel_id = #{channelId} and pgc.platform_id=#{platformId}") List queryVideoDeviceByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId); @Delete("") int delByCatalogId(@Param("platformId") String platformId, @Param("id") String id); @Delete("") int delByCatalogIdAndChannelIdAndPlatformId(PlatformCatalog platformCatalog); @@ -88,7 +88,7 @@ public interface PlatformChannelMapper { "pp.* " + "FROM " + "wvp_platform pp " + - "left join wvp_platform_gb_channel pgc on " + + "left join wvp_common_channel_platform pgc on " + "pp.server_gb_id = pgc.platform_id " + "left join wvp_device_channel dc on " + "dc.id = pgc.device_channel_id " + @@ -100,22 +100,28 @@ public interface PlatformChannelMapper { List queryPlatFormListForGBWithGBId(@Param("channelId") String channelId, @Param("platforms") List platforms); @Delete("") void delByPlatformId(String serverGBId); @Delete("") int delChannelForGBByCatalogId(@Param("platformId") String platformId, @Param("catalogId") String catalogId); @Select("select dc.channel_id dc.device_id,dc.name,d.manufacturer,d.model,d.firmware\n" + - "from wvp_platform_gb_channel pgc\n" + + "from wvp_common_channel_platform pgc\n" + " left join wvp_device_channel dc on dc.id = pgc.device_channel_id\n" + " left join wvp_device d on dc.device_id = d.device_id\n" + "where dc.channel_id = #{channelId} and pgc.platform_id=#{platformId}") List queryDeviceInfoByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId); - @Select("SELECT pgc.platform_id from wvp_platform_gb_channel pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_id='${channelId}'") + @Select("SELECT pgc.platform_id from wvp_common_channel_platform pgc left join wvp_device_channel dc on dc.id = pgc.device_channel_id WHERE dc.channel_id='${channelId}'") List queryParentPlatformByChannelId(String channelId); + + @Select("") + List findChannelsInDb(@Param("platformId") Integer platformId, @Param("channelIds") List channelIds); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java index 870dee0b..3028c529 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/PlatformController.java @@ -165,7 +165,6 @@ public class PlatformController { throw new ControllerException(ErrorCode.ERROR400.getCode(), "error severPort"); } - ParentPlatform parentPlatformOld = storager.queryParentPlatByServerGBId(parentPlatform.getServerGBId()); if (parentPlatformOld != null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台 " + parentPlatform.getServerGBId() + " 已存在"); @@ -283,73 +282,28 @@ public class PlatformController { return parentPlatform != null; } - /** - * 分页查询级联平台的所有所有通道 - * - * @param page 当前页 - * @param count 每页条数 - * @param platformId 上级平台ID - * @param query 查询内容 - * @param online 是否在线 - * @param channelType 通道类型 - * @return - */ - @Operation(summary = "查询上级平台是否存在") - @Parameter(name = "page", description = "当前页", required = true) - @Parameter(name = "count", description = "每页条数", required = true) - @Parameter(name = "platformId", description = "上级平台的国标编号") - @Parameter(name = "catalogId", description = "目录ID") - @Parameter(name = "query", description = "查询内容") - @Parameter(name = "online", description = "是否在线") - @Parameter(name = "channelType", description = "通道类型") - @GetMapping("/channel_list") - @ResponseBody - public PageInfo channelList(int page, int count, - @RequestParam(required = false) String platformId, - @RequestParam(required = false) String catalogId, - @RequestParam(required = false) String query, - @RequestParam(required = false) Boolean online, - @RequestParam(required = false) Boolean channelType) { - - if (ObjectUtils.isEmpty(platformId)) { - platformId = null; - } - if (ObjectUtils.isEmpty(query)) { - query = null; - } - if (ObjectUtils.isEmpty(platformId) || ObjectUtils.isEmpty(catalogId)) { - catalogId = null; - } - PageInfo channelReduces = storager.queryAllChannelList(page, count, query, online, channelType, platformId, catalogId); - - return channelReduces; - } - /** * 向上级平台添加国标通道 - * - * @param param 通道关联参数 - * @return */ @Operation(summary = "向上级平台添加国标通道") - @PostMapping("/update_channel_for_gb") + @PostMapping("/channel/add") @ResponseBody - public void updateChannelForGB(@RequestBody UpdateChannelParam param) { + public void addChannelForGB(@RequestBody UpdateChannelParam param) { if (logger.isDebugEnabled()) { logger.debug("给上级平台添加国标通道API调用"); } - int result = 0; - if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) { - if (param.isAll()) { - logger.info("[国标级联]添加所有通道到上级平台, {}", param.getPlatformId()); - List allChannelForDevice = deviceChannelService.queryAllChannelList(param.getPlatformId()); - result = platformChannelService.updateChannelForGB(param.getPlatformId(), allChannelForDevice, param.getCatalogId()); - } - }else { - result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId()); + ParentPlatform platform = platformService.queryPlatformByServerGBId(param.getPlatformId()); + if (platform == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在"); } - if (result <= 0) { + if (platform.isShareAllChannel()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "已开启共享所有通道,不需要添加了"); + } + if (param.getCommonGbChannelIds() == null || param.getCommonGbChannelIds().isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100); + } + if (platformChannelService.addChannelForGB(platform,param.getCommonGbChannelIds()) <= 0) { throw new ControllerException(ErrorCode.ERROR100); } } @@ -361,23 +315,24 @@ public class PlatformController { * @return */ @Operation(summary = "从上级平台移除国标通道") - @DeleteMapping("/del_channel_for_gb") + @DeleteMapping("/channel/delete") @ResponseBody public void delChannelForGB(@RequestBody UpdateChannelParam param) { if (logger.isDebugEnabled()) { logger.debug("给上级平台删除国标通道API调用"); } - int result = 0; - if (param.getChannelReduces() == null || param.getChannelReduces().size() == 0) { - if (param.isAll()) { - logger.info("[国标级联]移除所有通道,上级平台, {}", param.getPlatformId()); - result = platformChannelService.delAllChannelForGB(param.getPlatformId(), param.getCatalogId()); - } - }else { - result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces()); + ParentPlatform platform = platformService.queryPlatformByServerGBId(param.getPlatformId()); + if (platform == null) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在"); } - if (result <= 0) { + if (platform.isShareAllChannel()) { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "已开启共享所有通道,不支持部分移除"); + } + if (param.getCommonGbChannelIds() == null || param.getCommonGbChannelIds().isEmpty()) { + throw new ControllerException(ErrorCode.ERROR100); + } + if (platformChannelService.removeChannelForGB(platform,param.getCommonGbChannelIds()) <= 0) { throw new ControllerException(ErrorCode.ERROR100); } } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/bean/UpdateChannelParam.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/bean/UpdateChannelParam.java index 2d598e44..4b384693 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/bean/UpdateChannelParam.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/platform/bean/UpdateChannelParam.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.vmanager.gb28181.platform.bean; +import com.genersoft.iot.vmp.common.CommonGbChannel; import io.swagger.v3.oas.annotations.media.Schema; import java.util.List; @@ -14,14 +15,8 @@ public class UpdateChannelParam { @Schema(description = "上级平台的国标编号") private String platformId; - @Schema(description = "目录的国标编号") - private String catalogId; - - @Schema(description = "处理所有通道") - private boolean all; - - @Schema(description = "") - private List channelReduces; + @Schema(description = "待关联的通道ID") + private List commonGbChannelIds; public String getPlatformId() { return platformId; @@ -31,27 +26,11 @@ public class UpdateChannelParam { this.platformId = platformId; } - public List getChannelReduces() { - return channelReduces; + public List getCommonGbChannelIds() { + return commonGbChannelIds; } - public void setChannelReduces(List channelReduces) { - this.channelReduces = channelReduces; - } - - public String getCatalogId() { - return catalogId; - } - - public void setCatalogId(String catalogId) { - this.catalogId = catalogId; - } - - public boolean isAll() { - return all; - } - - public void setAll(boolean all) { - this.all = all; + public void setCommonGbChannelIds(List commonGbChannelIds) { + this.commonGbChannelIds = commonGbChannelIds; } }