From c45bf5d6af7edfaf05a70007c5ffb97d21dca863 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 26 Aug 2024 17:16:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E6=A0=87=E7=BA=A7=E8=81=94=E9=80=9A?= =?UTF-8?q?=E9=81=93=E5=85=B1=E4=BA=AB=E9=87=8D=E6=9E=84=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/dao/CommonGBChannelMapper.java | 49 +++++ .../iot/vmp/gb28181/dao/GroupMapper.java | 8 +- .../gb28181/dao/PlatformChannelMapper.java | 42 ++++- .../iot/vmp/gb28181/dao/RegionMapper.java | 39 ++++ .../impl/PlatformChannelServiceImpl.java | 175 +++++++++++++++--- 5 files changed, 274 insertions(+), 39 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 d09eeba1..8f1ecaa9 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 @@ -507,6 +507,55 @@ public interface CommonGBChannelMapper { List queryShareChannelByParentId(@Param("parentId") String parentId, @Param("platformId") Integer platformId); + @Select("select\n" + + " wdc.id as gb_id,\n" + + " wdc.device_db_id as gb_device_db_id,\n" + + " wdc.stream_push_id,\n" + + " wdc.stream_proxy_id,\n" + + " wdc.create_time,\n" + + " wdc.update_time,\n" + + " coalesce(wpgc.device_id, wdc.gb_device_id, wdc.device_id) as gb_device_id,\n" + + " coalesce(wpgc.name, wdc.gb_name, wdc.name) as gb_name,\n" + + " coalesce(wpgc.manufacturer, wdc.gb_manufacturer, wdc.manufacturer) as gb_manufacturer,\n" + + " coalesce(wpgc.model, wdc.gb_model, wdc.model) as gb_model,\n" + + " coalesce(wpgc.owner, wdc.gb_owner, wdc.owner) as gb_owner,\n" + + " coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code) as gb_civil_code,\n" + + " coalesce(wpgc.block, wdc.gb_block, wdc.block) as gb_block,\n" + + " coalesce(wpgc.address, wdc.gb_address, wdc.address) as gb_address,\n" + + " coalesce(wpgc.parental, wdc.gb_parental, wdc.parental) as gb_parental,\n" + + " coalesce(wpgc.parent_id, wdc.gb_parent_id, wdc.parent_id) as gb_parent_id,\n" + + " coalesce(wpgc.safety_way, wdc.gb_safety_way, wdc.safety_way) as gb_safety_way,\n" + + " coalesce(wpgc.register_way, wdc.gb_register_way, wdc.register_way) as gb_register_way,\n" + + " coalesce(wpgc.cert_num, wdc.gb_cert_num, wdc.cert_num) as gb_cert_num,\n" + + " coalesce(wpgc.certifiable, wdc.gb_certifiable, wdc.certifiable) as gb_certifiable,\n" + + " coalesce(wpgc.err_code, wdc.gb_err_code, wdc.err_code) as gb_err_code,\n" + + " coalesce(wpgc.end_time, wdc.gb_end_time, wdc.end_time) as gb_end_time,\n" + + " coalesce(wpgc.secrecy, wdc.gb_secrecy, wdc.secrecy) as gb_secrecy,\n" + + " coalesce(wpgc.ip_address, wdc.gb_ip_address, wdc.ip_address) as gb_ip_address,\n" + + " coalesce(wpgc.port, wdc.gb_port, wdc.port) as gb_port,\n" + + " coalesce(wpgc.password, wdc.gb_password, wdc.password) as gb_password,\n" + + " coalesce(wpgc.status, wdc.gb_status, wdc.status) as gb_status,\n" + + " coalesce(wpgc.longitude, wdc.gb_longitude, wdc.longitude) as gb_longitude,\n" + + " coalesce(wpgc.latitude, wdc.gb_latitude, wdc.latitude) as gb_latitude,\n" + + " coalesce(wpgc.ptz_type, wdc.gb_ptz_type, wdc.ptz_type) as gb_ptz_type,\n" + + " coalesce(wpgc.position_type, wdc.gb_position_type, wdc.position_type) as gb_position_type,\n" + + " coalesce(wpgc.room_type, wdc.gb_room_type, wdc.room_type) as gb_room_type,\n" + + " coalesce(wpgc.use_type, wdc.gb_use_type, wdc.use_type) as gb_use_type,\n" + + " coalesce(wpgc.supply_light_type, wdc.gb_supply_light_type, wdc.supply_light_type) as gb_supply_light_type,\n" + + " coalesce(wpgc.direction_type, wdc.gb_direction_type, wdc.direction_type) as gb_direction_type,\n" + + " coalesce(wpgc.resolution, wdc.gb_resolution, wdc.resolution) as gb_resolution,\n" + + " coalesce(wpgc.business_group_id, wdc.gb_business_group_id, wdc.business_group_id) as gb_business_group_id,\n" + + " coalesce(wpgc.download_speed, wdc.gb_download_speed, wdc.download_speed) as gb_download_speed,\n" + + " coalesce(wpgc.svc_space_support_mod, wdc.gb_svc_space_support_mod, wdc.svc_space_support_mod) as gb_svc_space_support_mod,\n" + + " coalesce(wpgc.svc_time_support_mode, wdc.gb_svc_time_support_mode, wdc.svc_time_support_mode) as gb_svc_time_support_mode\n" + + " from wvp_device_channel wdc" + + " left join wvp_platform_channel wpgc on wdc.id = wpgc.device_channel_id " + + " where wpgc.platform_id = #{platformId} and coalesce(wpgc.civil_code, wdc.gb_civil_code, wdc.civil_code) = #{civilCode}" + + ) + List queryShareChannelByCivilCode(@Param("civilCode") String civilCode, @Param("platformId") Integer platformId); + + @Update(value = {" ") - Set queryNotShareForPlatformByChannelList(List channelList, @Param("platformId") Integer platformId); + Set queryNotShareGroupForPlatformByChannelList(List channelList, @Param("platformId") Integer platformId); @Select(" ") - Set queryNotShareForPlatformByGroupList(Set allGroup, @Param("platformId") Integer platformId); + Set queryNotShareGroupForPlatformByGroupList(Set allGroup, @Param("platformId") Integer platformId); + @Select(" ") + " order by id " + + "") Set queryByChannelList(List channelList); @Update(" ") int addPlatformGroup(List groupListNotShare, @Param("platformId") Integer platformId); + @Insert("") + int addPlatformRegion(List regionListNotShare, @Param("platformId") Integer platformId); + @Delete("") void removePlatformGroupById(@Param("id") int id, @Param("platformId") Integer platformId); + @Delete("") + void removePlatformRegionById(@Param("id") int id, @Param("platformId") Integer platformId); + @Select(" ") Set queryShareChildrenGroup(@Param("parentId") String parentId, @Param("platformId") Integer platformId); + @Select(" ") + Set queryShareChildrenRegion(@Param("parentId") String parentId, @Param("platformId") Integer platformId); + @Select(" ") Set queryShareParentGroupByGroupSet(Set groupSet, @Param("platformId") Integer platformId); + + @Select(" ") + Set queryShareParentRegionByRegionSet(Set regionSet, @Param("platformId") Integer platformId); } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java index 4161a259..8f345135 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/RegionMapper.java @@ -1,6 +1,7 @@ package com.genersoft.iot.vmp.gb28181.dao; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; +import com.genersoft.iot.vmp.gb28181.bean.Group; import com.genersoft.iot.vmp.gb28181.bean.Region; import com.genersoft.iot.vmp.gb28181.bean.RegionTree; import org.apache.ibatis.annotations.*; @@ -123,4 +124,42 @@ public interface RegionMapper { @Select("SELECT * from wvp_common_region WHERE device_id = #{deviceId} ") Region queryByDeviceId(@Param("deviceId") String deviceId); + + @Select(" ") + Set queryParentInChannelList(Set regionSet); + + @Select(" ") + Set queryByChannelList(List channelList); + + @Select(" ") + Set queryNotShareRegionForPlatformByChannelList(List channelList, @Param("platformId") Integer platformId); + + @Select(" ") + Set queryNotShareRegionForPlatformByRegionList(Set allRegion, @Param("platformId") Integer platformId); + } 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 5caf87af..439e5db7 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 @@ -4,9 +4,11 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.genersoft.iot.vmp.gb28181.bean.CommonGBChannel; import com.genersoft.iot.vmp.gb28181.bean.Group; import com.genersoft.iot.vmp.gb28181.bean.PlatformChannel; +import com.genersoft.iot.vmp.gb28181.bean.Region; import com.genersoft.iot.vmp.gb28181.dao.CommonGBChannelMapper; import com.genersoft.iot.vmp.gb28181.dao.GroupMapper; import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper; +import com.genersoft.iot.vmp.gb28181.dao.RegionMapper; 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; @@ -18,10 +20,7 @@ import org.springframework.stereotype.Service; import org.springframework.util.Assert; import java.beans.Transient; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author lin @@ -40,6 +39,10 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { @Autowired private GroupMapper groupMapper; + + @Autowired + private RegionMapper regionMapper; + @Autowired private CommonGBChannelMapper commonGBChannelMapper; @@ -58,15 +61,30 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { Assert.notEmpty(channelListNotShare, "所有通道已共享"); int result = platformChannelMapper.addChannels(platformId, channelListNotShare); if (result > 0) { - // 查询通道相关的分组信息是否共享,如果没共享就添加 - Set groupListNotShare = getGroupNotShareByChannelList(channelListNotShare, platformId); - int addGroupResult = platformChannelMapper.addPlatformGroup(new ArrayList<>(groupListNotShare), platformId); - if (addGroupResult > 0) { - for (Group group : groupListNotShare) { - // 分组信息排序时需要将顶层排在最后 - channelListNotShare.add(0, CommonGBChannel.build(group)); + // 查询通道相关的行政区划信息是否共享,如果没共享就添加 + Set regionListNotShare = getRegionNotShareByChannelList(channelListNotShare, platformId); + if (!regionListNotShare.isEmpty()) { + int addGroupResult = platformChannelMapper.addPlatformRegion(new ArrayList<>(regionListNotShare), platformId); + if (addGroupResult > 0) { + for (Region region : regionListNotShare) { + // 分组信息排序时需要将顶层排在最后 + channelListNotShare.add(0, CommonGBChannel.build(region)); + } } } + + // 查询通道相关的分组信息是否共享,如果没共享就添加 + Set groupListNotShare = getGroupNotShareByChannelList(channelListNotShare, platformId); + if (!groupListNotShare.isEmpty()) { + int addGroupResult = platformChannelMapper.addPlatformGroup(new ArrayList<>(groupListNotShare), platformId); + if (addGroupResult > 0) { + for (Group group : groupListNotShare) { + // 分组信息排序时需要将顶层排在最后 + channelListNotShare.add(0, CommonGBChannel.build(group)); + } + } + } + // 发送消息 try { // 发送catalog @@ -83,35 +101,56 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { */ private Set getGroupNotShareByChannelList(List channelList, Integer platformId) { // 获取分组中未分享的节点 - Set groupList = groupMapper.queryNotShareForPlatformByChannelList(channelList, platformId); + Set groupList = groupMapper.queryNotShareGroupForPlatformByChannelList(channelList, platformId); // 获取这些节点的所有父节点 if (groupList.isEmpty()) { return new HashSet<>(); } Set allGroup = getAllGroup(groupList); + allGroup.addAll(groupList); // 获取全部节点中未分享的 - return groupMapper.queryNotShareForPlatformByGroupList(allGroup, platformId); + return groupMapper.queryNotShareGroupForPlatformByGroupList(allGroup, platformId); + } + + /** + * 获取通道使用的分组中未分享的 + */ + private Set getRegionNotShareByChannelList(List channelList, Integer platformId) { + // 获取分组中未分享的节点 + Set regionSet = regionMapper.queryNotShareRegionForPlatformByChannelList(channelList, platformId); + // 获取这些节点的所有父节点 + if (regionSet.isEmpty()) { + return new HashSet<>(); + } + Set allRegion = getAllRegion(regionSet); + allRegion.addAll(regionSet); + // 获取全部节点中未分享的 + return regionMapper.queryNotShareRegionForPlatformByRegionList(allRegion, platformId); } /** * 移除空的共享,并返回移除的分组 */ private Set deleteEmptyGroup(Set groupSet, Integer platformId) { - for (Group group : groupSet) { + Iterator iterator = groupSet.iterator(); + while (iterator.hasNext()) { + Group group = iterator.next(); + // groupSet 为当前通道直接使用的分组,如果已经没有子分组与其他的通道,则可以移除 // 获取分组子节点 Set children = platformChannelMapper.queryShareChildrenGroup(group.getDeviceId(), platformId); if (!children.isEmpty()) { - groupSet.remove(group); + iterator.remove(); continue; } // 获取分组关联的通道 List channelList = commonGBChannelMapper.queryShareChannelByParentId(group.getDeviceId(), platformId); if (!channelList.isEmpty()) { - groupSet.remove(group); + iterator.remove(); continue; } platformChannelMapper.removePlatformGroupById(group.getId(), platformId); } + // 如果空了,说明没有通道需要处理了 if (groupSet.isEmpty()) { return new HashSet<>(); } @@ -125,15 +164,46 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { } } + /** + * 移除空的共享,并返回移除的行政区划 + */ + private Set deleteEmptyRegion(Set regionSet, Integer platformId) { + Iterator iterator = regionSet.iterator(); + while (iterator.hasNext()) { + Region region = iterator.next(); + // groupSet 为当前通道直接使用的分组,如果已经没有子分组与其他的通道,则可以移除 + // 获取分组子节点 + Set children = platformChannelMapper.queryShareChildrenRegion(region.getDeviceId(), platformId); + if (!children.isEmpty()) { + iterator.remove(); + continue; + } + // 获取分组关联的通道 + List channelList = commonGBChannelMapper.queryShareChannelByCivilCode(region.getDeviceId(), platformId); + if (!channelList.isEmpty()) { + iterator.remove(); + continue; + } + platformChannelMapper.removePlatformRegionById(region.getId(), platformId); + } + // 如果空了,说明没有通道需要处理了 + if (regionSet.isEmpty()) { + return new HashSet<>(); + } + Set parent = platformChannelMapper.queryShareParentRegionByRegionSet(regionSet, platformId); + if (parent.isEmpty()) { + return regionSet; + }else { + Set parentGroupSet = deleteEmptyRegion(parent, platformId); + regionSet.addAll(parentGroupSet); + return regionSet; + } + } + private Set getAllGroup(Set groupList ) { if (groupList.isEmpty()) { return new HashSet<>(); } - for (Group group : groupList) { - if (group.getParentDeviceId() == null) { - - } - } Set channelList = groupMapper.queryParentInChannelList(groupList); if (channelList.isEmpty()) { return channelList; @@ -143,6 +213,20 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { return channelList; } + private Set getAllRegion(Set regionSet ) { + if (regionSet.isEmpty()) { + return new HashSet<>(); + } + + Set channelList = regionMapper.queryParentInChannelList(regionSet); + if (channelList.isEmpty()) { + return channelList; + } + Set allParentRegion = getAllRegion(channelList); + channelList.addAll(allParentRegion); + return channelList; + } + @Override @Transient public int addChannels(Integer platformId, List channelIds) { @@ -150,6 +234,18 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { Assert.notEmpty(channelListNotShare, "通道已共享"); int result = platformChannelMapper.addChannels(platformId, channelListNotShare); if (result > 0) { + // 查询通道相关的行政区划信息是否共享,如果没共享就添加 + Set regionListNotShare = getRegionNotShareByChannelList(channelListNotShare, platformId); + if (!regionListNotShare.isEmpty()) { + int addGroupResult = platformChannelMapper.addPlatformRegion(new ArrayList<>(regionListNotShare), platformId); + if (addGroupResult > 0) { + for (Region region : regionListNotShare) { + // 分组信息排序时需要将顶层排在最后 + channelListNotShare.add(0, CommonGBChannel.build(region)); + } + } + } + // 查询通道相关的分组信息是否共享,如果没共享就添加 Set groupListNotShare = getGroupNotShareByChannelList(channelListNotShare, platformId); if (!groupListNotShare.isEmpty()) { @@ -175,36 +271,55 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService { @Override public int removeAllChannel(Integer platformId) { - List channelListNotShare = platformChannelMapper.queryNotShare(platformId, null); - Assert.notEmpty(channelListNotShare, "未共享任何通道"); - int result = platformChannelMapper.removeChannels(platformId, channelListNotShare); + List channelListShare = platformChannelMapper.queryShare(platformId, null); + Assert.notEmpty(channelListShare, "未共享任何通道"); + int result = platformChannelMapper.removeChannels(platformId, channelListShare); if (result > 0) { - // 查询通道相关的分组信息是否共享,如果没共享就添加 - Set groupSet = groupMapper.queryByChannelList(channelListNotShare); + // 查询通道相关的分组信息 + Set regionSet = regionMapper.queryByChannelList(channelListShare); + Set deleteRegion = deleteEmptyRegion(regionSet, platformId); + if (!deleteRegion.isEmpty()) { + for (Region region : deleteRegion) { + channelListShare.add(0, CommonGBChannel.build(region)); + } + } + + // 查询通道相关的分组信息 + Set groupSet = groupMapper.queryByChannelList(channelListShare); Set deleteGroup = deleteEmptyGroup(groupSet, platformId); if (!deleteGroup.isEmpty()) { for (Group group : deleteGroup) { - channelListNotShare.add(0, CommonGBChannel.build(group)); + channelListShare.add(0, CommonGBChannel.build(group)); } } // 发送消息 try { // 发送catalog - eventPublisher.catalogEventPublish(platformId, channelListNotShare, CatalogEvent.DEL); + eventPublisher.catalogEventPublish(platformId, channelListShare, CatalogEvent.DEL); } catch (Exception e) { - log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListNotShare.size(), e); + log.warn("[移除全部关联通道] 发送失败,数量:{}", channelListShare.size(), e); } } return result; } @Override + @Transient public int removeChannels(Integer platformId, List channelIds) { List channelList = platformChannelMapper.queryShare(platformId, channelIds); Assert.notEmpty(channelList, "所选通道未共享"); int result = platformChannelMapper.removeChannels(platformId, channelList); if (result > 0) { - // 查询通道相关的分组信息是否共享,如果没共享就添加 + // 查询通道相关的分组信息 + Set regionSet = regionMapper.queryByChannelList(channelList); + Set deleteRegion = deleteEmptyRegion(regionSet, platformId); + if (!deleteRegion.isEmpty()) { + for (Region region : deleteRegion) { + channelList.add(0, CommonGBChannel.build(region)); + } + } + + // 查询通道相关的分组信息 Set groupSet = groupMapper.queryByChannelList(channelList); Set deleteGroup = deleteEmptyGroup(groupSet, platformId); if (!deleteGroup.isEmpty()) {