Merge remote-tracking branch 'origin/database-structure-optimization' into database-structure-optimization

# Conflicts:
#	sql/common.sql
结构优化
648540858 2023-12-06 16:13:27 +08:00
commit 2199db079a
12 changed files with 219 additions and 298 deletions

View File

@ -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,7 +67,7 @@ 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` bigint unsigned NOT NULL,
@ -79,10 +79,21 @@ CREATE TABLE `wvp_common_platform_channel`
DEFAULT CHARSET = utf8mb4
COLLATE = utf8mb4_0900_ai_ci;
drop table `wvp_platform_catalog`;
drop table `wvp_platform_gb_channel`;
drop table `wvp_platform_gb_stream`;
drop table `wvp_resources_tree`;
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;
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;

View File

@ -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;
}
}

View File

@ -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<DeviceChannel> deviceChannelList = new ArrayList<>();
deviceChannelList.add(deviceChannel);
catalogEventPublish(platformId, deviceChannelList, type);
public void catalogEventPublish(String platformId, CommonGbChannel channel, String type) {
List<CommonGbChannel> 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<DeviceChannel> deviceChannels, String type) {
public void catalogEventPublish(String platformId, List<CommonGbChannel> channels, String type) {
CatalogEvent outEvent = new CatalogEvent(this);
List<DeviceChannel> channels = new ArrayList<>();
if (deviceChannels.size() > 1) {
// 数据去重
Set<String> 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);

View File

@ -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<DeviceChannel> deviceChannels;
private List<CommonGbChannel> channels;
private List<GbStream> gbStreams;
private String type;
private String platformId;
public List<DeviceChannel> getDeviceChannels() {
return deviceChannels;
public List<CommonGbChannel> getChannels() {
return channels;
}
public void setDeviceChannels(List<DeviceChannel> deviceChannels) {
this.deviceChannels = deviceChannels;
public void setChannels(List<CommonGbChannel> channels) {
this.channels = channels;
}
public String getType() {

View File

@ -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<ChannelReduce> channelReduces, String catalogId);
int addChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds);
/**
*
* @param platformId
* @param catalogId
* @return
*
*/
int delAllChannelForGB(String platformId, String catalogId);
int removeChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds);
}

View File

@ -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<ChannelReduce> channelReduces, String catalogId) {
ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
if (platform == null) {
logger.warn("更新级联通道信息时未找到平台{}的信息", platformId);
return 0;
@Transactional
public int addChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds) {
assert platform != null;
// 检查通道Id数据是否都是在数据库中存在的数据
List<Integer> commonGbChannelIdsForSave = commonGbChannelMapper.getChannelIdsByIds(commonGbChannelIds);
if (commonGbChannelIdsForSave.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "有效待关联通道Id为空");
}
Map<Integer, ChannelReduce> deviceAndChannels = new HashMap<>();
for (ChannelReduce channelReduce : channelReduces) {
channelReduce.setCatalogId(catalogId);
deviceAndChannels.put(channelReduce.getId(), channelReduce);
// 去除已经关联的部分通道
List<Integer> commonGbChannelIdsInDb = platformChannelMapper.findChannelsInDb(platform.getId(),
commonGbChannelIdsForSave);
if (!commonGbChannelIdsInDb.isEmpty()) {
commonGbChannelIdsForSave.removeAll(commonGbChannelIdsInDb);
}
List<Integer> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
// 查询当前已经存在的
List<Integer> 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<ChannelReduce> 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) {
if (commonGbChannelIdsForSave.size() > BatchLimit.count) {
for (int i = 0; i < commonGbChannelIdsForSave.size(); i += BatchLimit.count) {
int toIndex = i + BatchLimit.count;
if (i + BatchLimit.count > channelReducesToAdd.size()) {
toIndex = channelReducesToAdd.size();
if (i + BatchLimit.count > commonGbChannelIdsForSave.size()) {
toIndex = commonGbChannelIdsForSave.size();
}
int count = platformChannelMapper.addChannels(platformId, channelReducesToAdd.subList(i, toIndex));
result = result || count < 0;
int count = platformChannelMapper.addChannels(platform.getId(), commonGbChannelIdsForSave.subList(i, toIndex));
allCount += count;
logger.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, channelReducesToAdd.size(), toIndex);
logger.info("[关联通道]国标通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platform.getServerGBId(), commonGbChannelIdsForSave.size(), allCount);
}
}else {
allCount = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
result = result || allCount < 0;
logger.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platformId, channelReducesToAdd.size());
allCount = platformChannelMapper.addChannels(platform.getId(), commonGbChannelIdsForSave);
logger.info("[关联通道]国标通道 平台:{}, 关联通道数:{}", platform.getServerGBId(), commonGbChannelIdsForSave.size());
}
if (result) {
//事务回滚
dataSourceTransactionManager.rollback(transactionStatus);
allCount = 0;
}else {
logger.info("[关联通道]国标通道 平台:{}, 正在存入数据库", platformId);
dataSourceTransactionManager.commit(transactionStatus);
}
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId);
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (catalogSubscribe != null) {
List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
if (deviceChannelList != null) {
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
List<CommonGbChannel> channelList = commonGbChannelMapper.queryInIdList(commonGbChannelIdsForSave);
if (channelList != null) {
eventPublisher.catalogEventPublish(platform.getServerGBId(), channelList, CatalogEvent.ADD);
}
}
logger.info("[关联通道]国标通道 平台:{}, 存入数据库成功", platformId);
}
return allCount;
}
private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId, ParentPlatform platform) {
List<DeviceChannel> 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) {
public int removeChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds) {
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<DeviceChannel> deviceChannels = platformChannelMapper.queryAllChannelInCatalog(platformId, catalogId);
eventPublisher.catalogEventPublish(platformId, deviceChannels, CatalogEvent.DEL);
}
return result;
}
}

View File

@ -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<CommonGbChannel> getChannels(String commonGroupId);
@Update(value = "<script>" +
"<foreach collection='channels' item='item' separator=';'>" +
"UPDATE wvp_common_gb_channel SET " +
"UPDATE wvp_common_channel SET " +
"update_time= #{ item.updateTime} " +
" <if test='item.commonGbDeviceID != null' > ,common_gb_device_id= #{ item.commonGbDeviceID} </if>" +
" <if test='item.commonGbName != null' > ,common_gb_name= #{ item.commonGbName} </if>" +
@ -65,16 +65,16 @@ public interface CommonGbChannelMapper {
@Delete(value = "<script>" +
"<foreach collection='channels' item='item' separator=';'>" +
"delete from wvp_common_gb_channel WHERE common_gb_id=#{item.commonGbId}" +
"delete from wvp_common_channel WHERE common_gb_id=#{item.commonGbId}" +
"</foreach>" +
"</script>")
int removeChannelsForGroup(List<CommonGbChannel> 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 = "<script>" +
"insert into wvp_common_gb_channel ( " +
"insert into wvp_common_channel ( " +
"common_gb_device_id" +
" <if test='common_gb_name != null' > ,common_gb_name </if>" +
" <if test='common_gb_manufacturer != null' > ,common_gb_manufacturer </if>" +
@ -152,11 +152,11 @@ public interface CommonGbChannelMapper {
"</script>")
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 = "<script>" +
"UPDATE wvp_common_gb_channel SET " +
"UPDATE wvp_common_channel SET " +
"update_time= #{ updateTime} " +
" <if test='commonGbDeviceID != null' > ,common_gb_device_id= #{ commonGbDeviceID} </if>" +
" <if test='commonGbName != null' > ,common_gb_name= #{ commonGbName} </if>" +
@ -197,14 +197,14 @@ public interface CommonGbChannelMapper {
int update(CommonGbChannel channel);
@Select("select count(1)\n" +
"from wvp_common_gb_channel gc " +
"from wvp_common_channel gc " +
"right join wvp_common_platform_channel pc " +
"on gc.common_gb_device_id = pc.common_gb_channel_id" +
"where gc.common_gb_device_id=#{channelId} and pc.platform_id=#{platformServerId}")
int checkChannelInPlatform(String channelId, String platformServerId);
@Insert(value = "<script>" +
"insert into wvp_common_gb_channel ( " +
"insert into wvp_common_channel ( " +
"common_gb_device_id, " +
"common_gb_name, " +
"common_gb_manufacturer, " +
@ -286,65 +286,65 @@ public interface CommonGbChannelMapper {
int addAll(List<CommonGbChannel> commonGbChannelList);
@Delete("<script> "+
"DELETE from wvp_common_gb_channel WHERE common_gb_device_id in (" +
"DELETE from wvp_common_channel WHERE common_gb_device_id in (" +
"<foreach collection='clearChannels' item='item' separator=',' > #{item}</foreach>" +
" )"+
"</script>")
int deleteByDeviceIDs(List<String> clearChannels);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET commonGbStatus = true WHERE common_gb_id in" +
"UPDATE wvp_common_channel SET commonGbStatus = true WHERE common_gb_id in" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbChannelId}</foreach>" +
"</script>")
void channelsOnlineFromList(List<DeviceChannel> channelList);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET commonGbStatus = false WHERE common_gb_id in" +
"UPDATE wvp_common_channel SET commonGbStatus = false WHERE common_gb_id in" +
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbChannelId}</foreach>" +
"</script>")
void channelsOfflineFromList(List<DeviceChannel> channelList);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_parent_id = null WHERE common_gb_id in" +
"UPDATE wvp_common_channel SET common_gb_parent_id = null WHERE common_gb_id in" +
"<foreach collection='errorParentIdList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
int clearParentIds(List<String> errorParentIdList);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_civilCode = null WHERE common_gb_civilCode in" +
"UPDATE wvp_common_channel SET common_gb_civilCode = null WHERE common_gb_civilCode in" +
"<foreach collection='errorCivilCodeList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
void clearCivilCodes(List<String> errorCivilCodeList);
@Select("<script> "+
"SELECT * FROM wvp_common_gb_channel WHERE common_gb_device_id in" +
"SELECT * FROM wvp_common_channel WHERE common_gb_device_id in" +
"<foreach collection='commonGbChannelList' item='item' open='(' separator=',' close=')' > #{item.commonGbDeviceID}</foreach>" +
"</script>")
List<CommonGbChannel> queryInList(List<CommonGbChannel> commonGbChannelList);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_civilCode = #{commonRegionDeviceIdForNew} WHERE common_gb_civilCode = #{commonRegionDeviceIdForOld}" +
"UPDATE wvp_common_channel SET common_gb_civilCode = #{commonRegionDeviceIdForNew} WHERE common_gb_civilCode = #{commonRegionDeviceIdForOld}" +
"</script>")
void updateChanelRegion(@Param("commonRegionDeviceIdForOld") String commonRegionDeviceIdForOld,
@Param("commonRegionDeviceIdForNew") String commonRegionDeviceIdForNew);
@Update("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_business_group_id = #{groupDeviceIdForNew} WHERE common_gb_business_group_id = #{groupDeviceIdForOld}" +
"UPDATE wvp_common_channel SET common_gb_business_group_id = #{groupDeviceIdForNew} WHERE common_gb_business_group_id = #{groupDeviceIdForOld}" +
"</script>")
void updateChanelGroup(
@Param("groupDeviceIdForOld") String groupDeviceIdForOld,
@Param("groupDeviceIdForNew") String groupDeviceIdForNew);
@Select("<script> "+
"select * from wvp_common_gb_channel where common_gb_civilCode = #{regionDeviceId}" +
"select * from wvp_common_channel where common_gb_civilCode = #{regionDeviceId}" +
"<if test='query != null'> and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) </if>" +
"</script>")
List<CommonGbChannel> getChannelsInRegion(@Param("regionDeviceId") String regionDeviceId,
@Param("query") String query);
@Select("<script> "+
"select * from wvp_common_gb_channel where 1=1 " +
"select * from wvp_common_channel where 1=1 " +
"<if test='groupDeviceId != null'> and common_gb_business_group_id = #{groupDeviceId} </if>" +
"<if test='regionDeviceId != null'> and common_gb_civilCode = #{regionDeviceId} </if>" +
"<if test='inGroup != null &amp; inGroup'> and common_gb_business_group_id is not null </if>" +
@ -365,13 +365,13 @@ public interface CommonGbChannelMapper {
@Select("<script> "+
"select * from wvp_common_gb_channel where 1=1 " +
"select * from wvp_common_channel where 1=1 " +
"<if test='query != null'> and ( common_gb_device_id LIKE concat('%',#{query},'%') or common_gb_name LIKE concat('%',#{query},'%') ) </if>" +
"</script>")
List<CommonGbChannel> query(@Param("query") String query);
@Select("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_business_group_id = null WHERE common_gb_business_group_id in" +
"UPDATE wvp_common_channel SET common_gb_business_group_id = null WHERE common_gb_business_group_id in" +
"<foreach collection='groupList' item='item' open='(' separator=',' close=')' > #{item.commonGroupDeviceId}</foreach>" +
"</script>")
void removeGroupInfo(@Param("groupList") List<Group> groupList);
@ -379,7 +379,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
"<foreach collection='param.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_business_group_id = #{param.commonGbBusinessGroupID}" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
@ -389,7 +389,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
"<foreach collection='commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_business_group_id = null" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
@ -398,14 +398,14 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_business_group_id = null" +
" WHERE common_gb_business_group_id = #{commonGbBusinessGroupID}" +
"</script>"})
void removeFromGroupByGroupId(@Param("commonGbBusinessGroupID") String commonGbBusinessGroupID);
@Select("<script> "+
"UPDATE wvp_common_gb_channel SET common_gb_civilCode = null WHERE common_gb_civilCode in" +
"UPDATE wvp_common_channel SET common_gb_civilCode = null WHERE common_gb_civilCode in" +
"<foreach collection='regionList' item='item' open='(' separator=',' close=')' > #{item.commonRegionDeviceId}</foreach>" +
"</script>")
void removeRegionInfo(@Param("regionList") List<Region> regionList);
@ -413,7 +413,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
"<foreach collection='commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_civilCode = null" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
@ -422,7 +422,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_civilCode = null" +
" WHERE common_gb_civilCode = #{commonGbCivilCode}" +
"</script>"})
@ -431,7 +431,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
"<foreach collection='param.commonGbIds' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET common_gb_civilCode = #{param.commonGbCivilCode}" +
" WHERE common_gb_id = #{item}" +
"</foreach>" +
@ -439,7 +439,7 @@ public interface CommonGbChannelMapper {
void updateChannelToRegion(@Param("param") UpdateCommonChannelToRegion param);
@Insert("<script> " +
"insert into wvp_common_gb_channel " +
"insert into wvp_common_channel " +
"( common_gb_device_id, " +
" common_gb_name, " +
" common_gb_manufacturer, " +
@ -522,7 +522,7 @@ public interface CommonGbChannelMapper {
@Update({"<script>" +
"<foreach collection='commonGbChannels' item='item' separator=';'>" +
" UPDATE" +
" wvp_common_gb_channel" +
" wvp_common_channel" +
" SET update_time=#{item.updateTime}" +
" <if test='item.commonGbDeviceID != null' > ,common_gb_device_id = #{item.commonGbDeviceID} </if>" +
" <if test='item.commonGbName != null' > ,common_gb_name = #{item.commonGbName} </if>" +
@ -567,14 +567,25 @@ public interface CommonGbChannelMapper {
@Delete(value = {" <script>" +
"DELETE " +
"from " +
"wvp_common_gb_channel " +
"wvp_common_channel " +
"WHERE common_gb_id IN " +
"<foreach collection='ids' item='item' open='(' separator=',' close=')' >#{item}</foreach>" +
" </script>"})
int batchDelete(@Param("ids") List<Integer> ids);
@MapKey("commonGbDeviceID")
@Select("select * from wvp_common_gb_channel")
@Select("select * from wvp_common_channel")
Map<String, CommonGbChannel> queryAllChannelsForMap();
@Select("<script> "+
"SELECT * FROM wvp_common_channel WHERE common_gb_id in" +
"<foreach collection='channelIds' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
List<CommonGbChannel> queryInIdList(@Param("channelIds") List<Integer> channelIds);
@Select("<script> "+
"SELECT common_gb_id FROM wvp_common_channel WHERE common_gb_id in" +
"<foreach collection='channelIds' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
List<Integer> getChannelIdsByIds(@Param("channelIds") List<Integer> channelIds);
}

View File

@ -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);

View File

@ -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}, " +

View File

@ -22,64 +22,64 @@ public interface PlatformChannelMapper {
*
*/
@Select("<script> "+
"SELECT device_channel_id from wvp_platform_gb_channel WHERE platform_id=#{platformId} AND device_channel_id in" +
"SELECT device_channel_id from wvp_common_channel_platform WHERE platform_id=#{platformId} AND device_channel_id in" +
"<foreach collection='channelReduces' open='(' item='item' separator=',' close=')'> #{item.id}</foreach>" +
"</script>")
List<Integer> findChannelRelatedPlatform(@Param("platformId") String platformId, @Param("channelReduces") List<ChannelReduce> channelReduces);
@Insert("<script> "+
"INSERT INTO wvp_platform_gb_channel (platform_id, device_channel_id, catalog_id) VALUES" +
"<foreach collection='channelReducesToAdd' item='item' separator=','>" +
" (#{platformId}, #{item.id} , #{item.catalogId} )" +
"INSERT INTO wvp_common_channel_platform (platform_id, common_gb_channel_id) VALUES" +
"<foreach collection='channelIds' item='item' separator=','>" +
" (#{platformId}, #{item})" +
"</foreach>" +
"</script>")
int addChannels(@Param("platformId") String platformId, @Param("channelReducesToAdd") List<ChannelReduce> channelReducesToAdd);
int addChannels(@Param("platformId") Integer platformId, @Param("channelIds") List<Integer> channelIds);
@Delete("<script> "+
"DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId} AND device_channel_id in" +
"DELETE from wvp_common_channel_platform WHERE platform_id=#{platformId} AND device_channel_id in" +
"<foreach collection='channelReducesToDel' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
"</script>")
int delChannelForGB(@Param("platformId") String platformId, @Param("channelReducesToDel") List<ChannelReduce> channelReducesToDel);
@Delete("<script> "+
"DELETE from wvp_platform_gb_channel WHERE device_channel_id in " +
"DELETE from wvp_common_channel_platform WHERE device_channel_id in " +
"( select temp.device_channel_id from " +
"(select pgc.device_channel_id from wvp_platform_gb_channel pgc " +
"(select pgc.device_channel_id from wvp_common_channel_platform pgc " +
"left join wvp_device_channel dc on dc.id = pgc.device_channel_id where dc.device_id =#{deviceId} " +
") temp)" +
"</script>")
int delChannelForDeviceId(String deviceId);
@Delete("<script> "+
"DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId}" +
"DELETE from wvp_common_channel_platform WHERE platform_id=#{platformId}" +
"</script>")
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<DeviceChannel> 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<DeviceChannel> 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<PlatformCatalog> 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<Device> queryVideoDeviceByPlatformIdAndChannelId(@Param("platformId") String platformId, @Param("channelId") String channelId);
@Delete("<script> "+
"DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId} and catalog_id=#{id}" +
"DELETE from wvp_common_channel_platform WHERE platform_id=#{platformId} and catalog_id=#{id}" +
"</script>")
int delByCatalogId(@Param("platformId") String platformId, @Param("id") String id);
@Delete("<script> "+
"DELETE from wvp_platform_gb_channel WHERE catalog_id=#{parentId} AND platform_id=#{platformId} AND channel_id=#{id}" +
"DELETE from wvp_common_channel_platform WHERE catalog_id=#{parentId} AND platform_id=#{platformId} AND channel_id=#{id}" +
"</script>")
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<ParentPlatform> queryPlatFormListForGBWithGBId(@Param("channelId") String channelId, @Param("platforms") List<String> platforms);
@Delete("<script> " +
"DELETE from wvp_platform_gb_channel WHERE platform_id=#{serverGBId}" +
"DELETE from wvp_common_channel_platform WHERE platform_id=#{serverGBId}" +
"</script>")
void delByPlatformId(String serverGBId);
@Delete("<script> " +
"DELETE from wvp_platform_gb_channel WHERE platform_id=#{platformId} and catalog_id=#{catalogId}" +
"DELETE from wvp_common_channel_platform WHERE platform_id=#{platformId} and catalog_id=#{catalogId}" +
"</script>")
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<Device> 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<String> queryParentPlatformByChannelId(String channelId);
@Select("<script> "+
"select common_gb_channel_id from wvp_common_channel_platform WHERE platform_id=#{platformId} AND common_gb_channel_id in" +
"<foreach collection='channelIds' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
"</script>")
List<Integer> findChannelsInDb(@Param("platformId") Integer platformId, @Param("channelIds") List<Integer> channelIds);
}

View File

@ -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<ChannelReduce> 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<ChannelReduce> 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<ChannelReduce> allChannelForDevice = deviceChannelService.queryAllChannelList(param.getPlatformId());
result = platformChannelService.updateChannelForGB(param.getPlatformId(), allChannelForDevice, param.getCatalogId());
ParentPlatform platform = platformService.queryPlatformByServerGBId(param.getPlatformId());
if (platform == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
}
}else {
result = platformChannelService.updateChannelForGB(param.getPlatformId(), param.getChannelReduces(), param.getCatalogId());
if (platform.isShareAllChannel()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "已开启共享所有通道,不需要添加了");
}
if (result <= 0) {
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());
ParentPlatform platform = platformService.queryPlatformByServerGBId(param.getPlatformId());
if (platform == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
}
}else {
result = storager.delChannelForGB(param.getPlatformId(), param.getChannelReduces());
if (platform.isShareAllChannel()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "已开启共享所有通道,不支持部分移除");
}
if (result <= 0) {
if (param.getCommonGbChannelIds() == null || param.getCommonGbChannelIds().isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100);
}
if (platformChannelService.removeChannelForGB(platform,param.getCommonGbChannelIds()) <= 0) {
throw new ControllerException(ErrorCode.ERROR100);
}
}

View File

@ -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<ChannelReduce> channelReduces;
@Schema(description = "待关联的通道ID")
private List<Integer> commonGbChannelIds;
public String getPlatformId() {
return platformId;
@ -31,27 +26,11 @@ public class UpdateChannelParam {
this.platformId = platformId;
}
public List<ChannelReduce> getChannelReduces() {
return channelReduces;
public List<Integer> getCommonGbChannelIds() {
return commonGbChannelIds;
}
public void setChannelReduces(List<ChannelReduce> 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<Integer> commonGbChannelIds) {
this.commonGbChannelIds = commonGbChannelIds;
}
}