From a18fba84952287272feba0783ad7fc47e7642a94 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: Wed, 21 Aug 2024 17:40:01 +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
---
.../iot/vmp/gb28181/dao/GroupMapper.java | 40 +++++++
.../gb28181/dao/PlatformChannelMapper.java | 18 +++
.../iot/vmp/gb28181/dao/PlatformMapper.java | 8 +-
.../iot/vmp/gb28181/dao/RegionMapper.java | 11 ++
.../service/impl/GbChannelServiceImpl.java | 44 ++------
.../impl/PlatformChannelServiceImpl.java | 104 +++++++++++++++++-
web_src/src/components/PlatformEdit.vue | 2 -
数据库/2.7.2-重构/初始化-mysql-2.7.2.sql | 92 +++++++++-------
8 files changed, 239 insertions(+), 80 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java
index 2058b654..dd56ad91 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/dao/GroupMapper.java
@@ -188,4 +188,44 @@ public interface GroupMapper {
" #{item.gbBusinessGroupId}" +
" ")
Set queryBusinessGroupInChannelList(List channelList);
+
+ @Select(" ")
+ List queryForPlatform(@Param("platformId") Integer platformId);
+
+ @Select(" ")
+ Set queryNotShareForPlatformByChannelList(List channelList, @Param("platformId") Integer platformId);
+
+ @Select(" ")
+ Set queryNotShareForPlatformByGroupList(Set allGroup, @Param("platformId") Integer platformId);
+
+ @Select(" ")
+ Set queryByChannelList(List channelList);
}
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 06ba21fe..52a3c08d 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
@@ -343,4 +343,22 @@ public interface PlatformChannelMapper {
"")
int removeChannels(@Param("platformId") Integer platformId, List channelList);
+ @Insert("")
+ int addPlatformGroup(List groupListNotShare, @Param("platformId") Integer platformId);
+
+ @Delete("")
+ int removePlatformGroup(List groupList, @Param("platformId") Integer platformId);
+
+ @Delete("")
+ void removePlatformGroupById(@Param("id") int id, @Param("platformId") Integer platformId);
}
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 b15b0d2e..db080ae6 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
@@ -15,11 +15,11 @@ public interface PlatformMapper {
@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,status,catalog_group, update_time," +
- " create_time, as_message_channel, send_stream_ip, auto_push_channel, catalog_with_platform,catalog_with_group,catalog_with_region, "+
+ " create_time, as_message_channel, send_stream_ip, auto_push_channel, catalog_with_platform, custom_group, custom_civil_code, "+
" civil_code,manufacturer,model,address,register_way,secrecy) " +
" VALUES (#{enable}, #{name}, #{serverGBId}, #{serverGBDomain}, #{serverIp}, #{serverPort}, #{deviceGBId}, #{deviceIp}, " +
" #{devicePort}, #{username}, #{password}, #{expires}, #{keepTimeout}, #{transport}, #{characterSet}, #{ptz}, #{rtcp}, #{status}, #{catalogGroup},#{updateTime}," +
- " #{createTime}, #{asMessageChannel}, #{sendStreamIp}, #{autoPushChannel}, #{catalogWithPlatform}, #{catalogWithGroup},#{catalogWithRegion}, " +
+ " #{createTime}, #{asMessageChannel}, #{sendStreamIp}, #{autoPushChannel}, #{catalogWithPlatform}, #{customGroup},#{customCivilCode}, " +
" #{civilCode}, #{manufacturer}, #{model}, #{address}, #{registerWay}, #{secrecy})")
int add(Platform parentPlatform);
@@ -48,8 +48,8 @@ public interface PlatformMapper {
" send_stream_ip=#{sendStreamIp}, " +
" auto_push_channel=#{autoPushChannel}, " +
" catalog_with_platform=#{catalogWithPlatform}, " +
- " catalog_with_group=#{catalogWithGroup}, " +
- " catalog_with_region=#{catalogWithRegion}, " +
+ " custom_group=#{customGroup}, " +
+ " custom_civil_code=#{customCivilCode}, " +
" civil_code=#{civilCode}, " +
" manufacturer=#{manufacturer}, " +
" model=#{model}, " +
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 42446b76..d0d6625b 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
@@ -116,4 +116,15 @@ public interface RegionMapper {
" #{item.parentDeviceId}" +
" ")
Set queryParentInChannelList(Set regionChannelList);
+
+ @Select(" ")
+ List queryByPlatform(@Param("platformId") Integer platformId);
+
}
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 f1a45c1f..37afc575 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
@@ -322,37 +322,22 @@ public class GbChannelServiceImpl implements IGbChannelService {
CommonGBChannel channel = CommonGBChannel.build(platform);
channelList.add(channel);
}
-
- // 是否包含行政区划信息
+ // 关联的行政区划信息
if (platform.getCatalogWithRegion()) {
- Set regionChannelList = regionMapper.queryInChannelList(commonGBChannelList);
+ // 查询关联平台的行政区划信息
+ List regionChannelList = regionMapper.queryByPlatform(platform.getId());
if (!regionChannelList.isEmpty()) {
- // 获取这些节点的所有父节点, 使用set滤重
- Set allRegion = getAllRegion(regionChannelList);
- allRegion.addAll(regionChannelList);
- for (Region region : allRegion) {
- channelList.add(CommonGBChannel.build(region));
- }
+ channelList.addAll(regionChannelList);
}
}
- // 是否包含分组信息
if (platform.getCatalogWithGroup()) {
- // 虚拟组织
- Set groupChannelList = groupMapper.queryInChannelList(commonGBChannelList);
- // 业务分组
- Set businessGroupChannelList = groupMapper.queryBusinessGroupInChannelList(commonGBChannelList);
+ // 关联的分组信息
+ List groupChannelList = groupMapper.queryForPlatform(platform.getId());
if (!groupChannelList.isEmpty()) {
- // 获取这些节点的所有父节点
- Set allGroup = getAllGroup(groupChannelList);
- allGroup.addAll(groupChannelList);
- if (!businessGroupChannelList.isEmpty()) {
- allGroup.addAll(businessGroupChannelList);
- }
- for (Group group : allGroup) {
- channelList.add(CommonGBChannel.build(group));
- }
+ channelList.addAll(groupChannelList);
}
}
+
channelList.addAll(commonGBChannelList);
return channelList;
}
@@ -370,18 +355,7 @@ public class GbChannelServiceImpl implements IGbChannelService {
return channelList;
}
- private Set getAllGroup(Set regionChannelList ) {
- if (regionChannelList.isEmpty()) {
- return new HashSet<>();
- }
- Set channelList = groupMapper.queryParentInChannelList(regionChannelList);
- if (channelList.isEmpty()) {
- return channelList;
- }
- Set allParentRegion = getAllGroup(channelList);
- channelList.addAll(allParentRegion);
- return channelList;
- }
+
@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 b98389c6..0fc89a20 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
@@ -2,7 +2,10 @@ package com.genersoft.iot.vmp.gb28181.service.impl;
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.dao.CommonGBChannelMapper;
+import com.genersoft.iot.vmp.gb28181.dao.GroupMapper;
import com.genersoft.iot.vmp.gb28181.dao.PlatformChannelMapper;
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
@@ -14,7 +17,11 @@ import org.springframework.beans.factory.annotation.Autowired;
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;
/**
* @author lin
@@ -28,7 +35,13 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
private PlatformChannelMapper platformChannelMapper;
@Autowired
- EventPublisher eventPublisher;
+ private EventPublisher eventPublisher;
+
+ @Autowired
+ private GroupMapper groupMapper;
+
+ @Autowired
+ private CommonGBChannelMapper commonGBChannelMapper;
@Override
@@ -39,11 +52,21 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
}
@Override
+ @Transient
public int addAllChannel(Integer platformId) {
List channelListNotShare = platformChannelMapper.queryNotShare(platformId, null);
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));
+ }
+ }
// 发送消息
try {
// 发送catalog
@@ -55,12 +78,76 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
return result;
}
+ /**
+ * 获取通道使用的分组中未分享的
+ */
+ private Set getGroupNotShareByChannelList(List channelList, Integer platformId) {
+ // 获取分组中未分享的节点
+ Set groupList = groupMapper.queryNotShareForPlatformByChannelList(channelList, platformId);
+ // 获取这些节点的所有父节点
+ if (groupList.isEmpty()) {
+ return new HashSet<>();
+ }
+ Set allGroup = getAllGroup(groupList);
+ // 获取全部节点中未分享的
+ return groupMapper.queryNotShareForPlatformByGroupList(allGroup, platformId);
+ }
+
+ /**
+ * 移除空的共享,并返回移除的分组
+ */
+ private Set deleteEmptyGroup(Set groupSet, Integer platformId) {
+ for (Group group : groupSet) {
+ // 获取分组子节点
+ List children = platformChannelMapper.getShareChildrenGroup(group.getDeviceId(), platformId);
+ if (!children.isEmpty()) {
+ groupSet.remove(group);
+ continue;
+ }
+ // 获取分组关联的通道
+ List channelList = platformChannelMapper.queryShareChannelByParentId(group.getDeviceId(), platformId);
+ if (!channelList.isEmpty()) {
+ groupSet.remove(group);
+ continue;
+ }
+ platformChannelMapper.removePlatformGroupById(group.getId(), platformId);
+ }
+ if (!groupSet.isEmpty()) {
+
+ }
+
+
+ }
+
+ private Set getAllGroup(Set groupList ) {
+ if (groupList.isEmpty()) {
+ return new HashSet<>();
+ }
+ Set channelList = groupMapper.queryParentInChannelList(groupList);
+ if (channelList.isEmpty()) {
+ return channelList;
+ }
+ Set allParentRegion = getAllGroup(channelList);
+ channelList.addAll(allParentRegion);
+ return channelList;
+ }
+
@Override
+ @Transient
public int addChannels(Integer platformId, List channelIds) {
List channelListNotShare = platformChannelMapper.queryNotShare(platformId, channelIds);
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));
+ }
+ }
// 发送消息
try {
// 发送catalog
@@ -78,6 +165,12 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
Assert.notEmpty(channelListNotShare, "未共享任何通道");
int result = platformChannelMapper.removeChannels(platformId, channelListNotShare);
if (result > 0) {
+ // 查询通道相关的分组信息是否共享,如果没共享就添加
+ Set groupSet = groupMapper.queryByChannelList(channelListNotShare);
+ Set deleteGroup = deleteEmptyGroup(groupSet, platformId);
+ if (!deleteGroup.isEmpty()) {
+ channelListNotShare.add(0, CommonGBChannel.build(group));
+ }
// 发送消息
try {
// 发送catalog
@@ -95,6 +188,15 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
Assert.notEmpty(channelList, "所选通道未共享");
int result = platformChannelMapper.removeChannels(platformId, channelList);
if (result > 0) {
+ // 查询通道相关的分组信息是否共享,如果没共享就添加
+ List groupListShareEmptyChannel = getGroupShareEmptyChannel(channelList, platformId);
+ int addGroupResult = platformChannelMapper.removePlatformGroup(groupListShareEmptyChannel, platformId);
+ if (addGroupResult > 0) {
+ for (Group group : groupListShareEmptyChannel) {
+ // 分组信息排序时需要将顶层排在最后
+ channelList.add(0, CommonGBChannel.build(group));
+ }
+ }
// 发送消息
try {
// 发送catalog
diff --git a/web_src/src/components/PlatformEdit.vue b/web_src/src/components/PlatformEdit.vue
index 9d93b619..fa929801 100644
--- a/web_src/src/components/PlatformEdit.vue
+++ b/web_src/src/components/PlatformEdit.vue
@@ -125,8 +125,6 @@
-
-
diff --git a/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql b/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql
index 7893ff63..0b73ff7c 100644
--- a/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql
+++ b/数据库/2.7.2-重构/初始化-mysql-2.7.2.sql
@@ -282,49 +282,65 @@ create table wvp_platform
);
-create table wvp_platform_gb_channel
+create table wvp_platform_channel
(
- id serial primary key,
- platform_id integer,
- device_channel_id integer,
- device_id character varying(50),
- name character varying(255),
- manufacturer character varying(50),
- model character varying(50),
- owner character varying(50),
- civil_code character varying(50),
- block character varying(50),
- address character varying(50),
- parental integer,
- parent_id character varying(50),
- safety_way integer,
- register_way integer,
- cert_num character varying(50),
- certifiable integer,
- err_code integer,
- end_time character varying(50),
- secrecy integer,
- ip_address character varying(50),
- port integer,
- password character varying(255),
- status character varying(50),
- longitude double precision,
- latitude double precision,
- ptz_type integer,
- position_type integer,
- room_type integer,
- use_type integer,
- supply_light_type integer,
- direction_type integer,
- resolution character varying(255),
- business_group_id character varying(255),
- download_speed character varying(255),
- svc_space_support_mod integer,
- svc_time_support_mode integer,
+ id serial primary key,
+ platform_id integer,
+ device_channel_id integer,
+ device_id character varying(50),
+ name character varying(255),
+ manufacturer character varying(50),
+ model character varying(50),
+ owner character varying(50),
+ civil_code character varying(50),
+ block character varying(50),
+ address character varying(50),
+ parental integer,
+ parent_id character varying(50),
+ safety_way integer,
+ register_way integer,
+ cert_num character varying(50),
+ certifiable integer,
+ err_code integer,
+ end_time character varying(50),
+ secrecy integer,
+ ip_address character varying(50),
+ port integer,
+ password character varying(255),
+ status character varying(50),
+ longitude double precision,
+ latitude double precision,
+ ptz_type integer,
+ position_type integer,
+ room_type integer,
+ use_type integer,
+ supply_light_type integer,
+ direction_type integer,
+ resolution character varying(255),
+ business_group_id character varying(255),
+ download_speed character varying(255),
+ svc_space_support_mod integer,
+ svc_time_support_mode integer,
constraint uk_platform_gb_channel_platform_id_catalog_id_device_channel_id unique (platform_id, device_channel_id),
constraint uk_platform_gb_channel_device_id unique (device_id)
);
+create table wvp_platform_group
+(
+ id serial primary key,
+ platform_id integer,
+ group_id integer,
+ constraint uk_wvp_platform_group_id_catalog_platform_id_group_id unique (platform_id, group_id)
+);
+
+create table wvp_platform_region
+(
+ id serial primary key,
+ platform_id integer,
+ region_id integer,
+ constraint uk_wvp_platform_group_id_catalog_platform_id_group_id unique (platform_id, region_id)
+);
+
create table wvp_stream_proxy
(
id serial primary key,