优化国标级联通道发送

结构优化
648540858 2024-01-25 17:04:40 +08:00
parent 5d973ef246
commit 7c7c1cf398
6 changed files with 128 additions and 23 deletions

View File

@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.StreamPush;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxy;
import com.genersoft.iot.vmp.service.bean.CommonGbChannelType;
import com.genersoft.iot.vmp.service.bean.Group;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.service.impl.CommonGbChannelServiceImpl;
import com.genersoft.iot.vmp.utils.DateUtil;
import io.swagger.v3.oas.annotations.media.Schema;
@ -806,4 +807,11 @@ public class CommonGbChannel {
commonGbChannel.setCommonGbBusinessGroupID(group.getCommonGroupTopId());
return commonGbChannel;
}
public static CommonGbChannel getInstance(Region region) {
CommonGbChannel commonGbChannel = new CommonGbChannel();
commonGbChannel.setCommonGbDeviceID(region.getCommonRegionDeviceId());
commonGbChannel.setCommonGbName(region.getCommonRegionName());
return commonGbChannel;
}
}

View File

@ -74,15 +74,12 @@ public class GroupServiceImpl implements IGroupService {
assert group.getCommonGroupDeviceId() != null;
group.setCommonGroupCreateTime(DateUtil.getNow());
group.setCommonGroupUpdateTime(DateUtil.getNow());
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(group.getCommonGroupParentId());
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(group.getCommonGroupDeviceId());
if (ObjectUtils.isEmpty(group.getCommonGroupParentId().trim()) || channelIdType.equals(Gb28181CodeType.BUSINESS_GROUP)) {
group.setCommonGroupParentId(null);
}
if (ObjectUtils.isEmpty(group.getCommonGroupTopId().trim())) {
Gb28181CodeType channelIdTypeForItem = SipUtils.getChannelIdType(group.getCommonGroupDeviceId());
if (channelIdTypeForItem.equals(Gb28181CodeType.BUSINESS_GROUP)) {
group.setCommonGroupTopId(group.getCommonGroupDeviceId());
}
if (ObjectUtils.isEmpty(group.getCommonGroupTopId().trim()) && channelIdType.equals(Gb28181CodeType.BUSINESS_GROUP)) {
group.setCommonGroupTopId(group.getCommonGroupDeviceId());
}
return groupMapper.add(group) > 0;
}
@ -261,9 +258,8 @@ public class GroupServiceImpl implements IGroupService {
@Override
public PageInfo<Group> queryChildGroupList(String groupParentId, int page, int count) {
PageHelper.startPage(page, count);
Gb28181CodeType channelIdType = SipUtils.getChannelIdType(groupParentId);
List<Group> groupList;
if (groupParentId == null || channelIdType == Gb28181CodeType.BUSINESS_GROUP) {
if (groupParentId == null) {
groupList = groupMapper.queryVirtualGroupList(groupParentId);
}else {
groupList = groupMapper.queryChildGroupList(groupParentId);

View File

@ -9,6 +9,7 @@ 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.service.bean.Group;
import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import org.slf4j.Logger;
@ -157,19 +158,24 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
if (channelList.isEmpty()) {
return result;
}
// 查询所有关联了的国标通道
// 查询国标通道关联的分组以及这些分组的父级
if (platform.isShareGroup()) {
Map<String, Group> allDependenceGroupMap = getAllDependenceGroup(channelList);
if (!allDependenceGroupMap.isEmpty()) {
for (Group group : allDependenceGroupMap.values()) {
List<Group> groupList = groupMapper.queryAllByDeviceIds(channelList);
if (!groupList.isEmpty()) {
for (Group group : groupList) {
result.add(CommonGbChannel.getInstance(group));
}
}
}
// 查询国标通道关联的区域以及这些区域的父级
if (platform.isShareRegion()) {
List<Region> regions = regionMapper.queryAllByDeviceIds(channelList);
if (!regions.isEmpty()) {
for (Region region : regions) {
result.add(CommonGbChannel.getInstance(region));
}
}
}
result.addAll(channelList);
}
return result;
@ -195,14 +201,25 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
}
private void getAllParentGroup(Group group, Map<String, Group> allGroupMap, List<Group> resultGroupList) {
if (Objects.equals(group.getCommonGroupDeviceId(), group.getCommonGroupTopId())) {
if (group == null
|| Objects.equals(group.getCommonGroupDeviceId(), group.getCommonGroupTopId())
|| Objects.equals(group.getCommonGroupDeviceId(), group.getCommonGroupParentId())) {
return;
}
Group parentGroup = allGroupMap.get(group.getCommonGroupDeviceId());
Group parentGroup = allGroupMap.get(group.getCommonGroupParentId());
resultGroupList.add(parentGroup);
getAllParentGroup(parentGroup, allGroupMap, resultGroupList);
}
private void getAllParentRegion(Region region, Map<String, Region> allRegionMap, List<Region> resultRegionList) {
if (region.getCommonRegionDeviceId().length() == 2) {
return;
}
Region parentRegion = allRegionMap.get(region.getCommonRegionDeviceId());
resultRegionList.add(parentRegion);
getAllParentRegion(parentRegion, allRegionMap, resultRegionList);
}
@Override
public CommonGbChannel queryChannelByPlatformIdAndChannelDeviceId(Integer platformId, String channelId) {
return platformChannelMapper.queryChannelByPlatformIdAndChannelDeviceId(platformId, channelId);

View File

@ -189,13 +189,12 @@ public interface GroupMapper {
List<CommonGbChannel> queryAllForCommonChannelByDeviceIdSet(Set<String> groupDeviceIdSet);
@Select("<script>" +
" select * " +
" from wvp_common_group" +
" where 1=1" +
"<if test='groupDeviceIdSet != null'> " +
" and common_group_device_id in " +
" WITH recursive temp AS (" +
" SELECT * FROM wvp_common_group wcg WHERE wcg.common_group_device_id in " +
"<foreach collection='commonGbChannelList' item='item' open='(' separator=',' close=')' >#{item.commonGbBusinessGroupID}</foreach>" +
"</if>" +
" UNION ALL" +
" SELECT wcg.* FROM wvp_common_group wcg, temp t WHERE t.common_group_parent_id = wcg.common_group_device_id )" +
" select *from temp" +
"</script>")
List<Group> queryAllByDeviceIds(List<CommonGbChannel> commonGbChannelList);
@ -208,5 +207,6 @@ public interface GroupMapper {
"<foreach collection='groupList' item='item' open='(' separator=',' close=')' >#{item.commonGroupTopId}</foreach>" +
"</if>" +
"</script>")
@MapKey("commonGroupDeviceId")
Map<String, Group> queryAllByTopId(List<Group> groupList);
}

View File

@ -134,4 +134,13 @@ public interface RegionMapper {
"from wvp_common_region")
List<CommonGbChannel> queryAllForCommonChannel();
@Select("<script>" +
" WITH recursive temp AS ( " +
" SELECT * FROM wvp_common_region wcr WHERE wcr.common_region_device_id in " +
"<foreach collection='commonGbChannelList' item='item' open='(' separator=',' close=')' >#{item.commonGbCivilCode}</foreach>" +
" UNION ALL" +
" SELECT wcr.* FROM wvp_common_region wcr, temp t WHERE t.common_region_parent_id = wcr.common_region_device_id )" +
" select *from temp" +
"</script>")
List<Region> queryAllByDeviceIds(List<CommonGbChannel> commonGbChannelList);
}

View File

@ -225,7 +225,7 @@ create table wvp_stream_push (
push_ing bool default false,
self bool default false,
common_gb_channel_id integer,
gb_id character varying(50) default NULL
gb_id character varying(50) default NULL,
longitude double precision,
latitude double precision,
constraint uk_stream_push_app_stream unique (app, stream)
@ -266,6 +266,81 @@ create table wvp_user_role (
update_time character varying(50)
);
CREATE TABLE wvp_common_channel
(
common_gb_id serial primary key,
common_gb_device_id character varying(50) NOT NULL,
common_gb_name character varying(255) DEFAULT NULL,
common_gb_manufacturer character varying(255) DEFAULT NULL,
common_gb_model character varying(255) DEFAULT NULL,
common_gb_owner character varying(255) DEFAULT NULL,
common_gb_civilCode character varying(50) DEFAULT NULL,
common_gb_block character varying(255) DEFAULT NULL,
common_gb_address character varying(255) DEFAULT NULL,
common_gb_parental integer,
common_gb_parent_id character varying(50) DEFAULT NULL,
common_gb_safety_way integer,
common_gb_register_way integer,
common_gb_cert_num character varying(255) DEFAULT NULL,
common_gb_certifiable integer,
common_gb_err_code integer,
common_gb_end_time character varying(50) DEFAULT NULL,
common_gb_secrecy integer,
common_gb_ip_address character varying(50) DEFAULT NULL,
common_gb_port integer,
common_gb_password character varying(50) DEFAULT NULL,
common_gb_status bool default false,
common_gb_longitude double precision,
common_gb_latitude double precision,
common_gb_ptz_type integer,
common_gb_position_type integer,
common_gb_room_type integer,
common_gb_use_type integer,
common_gb_supply_light_type integer,
common_gb_direction_type integer,
common_gb_resolution character varying(255) DEFAULT NULL,
common_gb_business_group_id character varying(255) DEFAULT NULL,
common_gb_download_speed character varying(255) DEFAULT NULL,
common_gb_svc_time_support_mode integer,
common_gb_svc_space_support_mode integer,
type character varying(255) NOT NULL,
update_time character varying(50) NOT NULL,
create_time character varying(50) NOT NULL,
constraint common_gb_device_id unique (common_gb_device_id)
);
CREATE TABLE wvp_common_group
(
common_group_id serial primary key,
common_group_device_id character varying(50) NOT NULL,
common_group_name character varying(255) NOT NULL,
common_group_parent_id character varying(50) DEFAULT NULL,
common_group_top_id character varying(50) DEFAULT NULL,
common_group_create_time character varying(50) NOT NULL,
common_group_update_time character varying(50) NOT NULL,
constraint common_group_device_id unique (common_group_device_id)
);
CREATE TABLE wvp_common_region
(
common_region_id serial primary key,
common_region_device_id character varying(50) NOT NULL,
common_region_name character varying(255) NOT NULL,
common_region_parent_id character varying(50) DEFAULT NULL,
common_region_create_time character varying(50) NOT NULL,
common_region_update_time character varying(50) NOT NULL,
constraint common_region_device_id unique (common_region_device_id)
);
CREATE TABLE wvp_common_channel_platform
(
id serial primary key,
platform_id integer,
common_gb_channel_id integer,
constraint uk_platform_id_common_gb_channel_id unique (platform_id,common_gb_channel_id)
);
/*初始数据*/
INSERT INTO wvp_user VALUES (1, 'admin','21232f297a57a5a743894a0e4a801fc3',1,'2021-04-13 14:14:57','2021-04-13 14:14:57','3e80d1762a324d5b0ff636e0bd16f1e3');