添加移除共享到上级平台的通道

结构优化
648540858 2023-12-05 23:23:48 +08:00
parent c4aeef62ef
commit 0d3845af59
11 changed files with 178 additions and 259 deletions

View File

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

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) {
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<CommonGbChannel> channelList = commonGbChannelMapper.queryInIdList(commonGbChannelIdsForSave);
if (channelList != null) {
eventPublisher.catalogEventPublish(platform.getServerGBId(), channelList, CatalogEvent.ADD);
}
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platformId);
if (catalogSubscribe != null) {
List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId, platform);
if (deviceChannelList != null) {
eventPublisher.catalogEventPublish(platformId, deviceChannelList, 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) {
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;
public int removeChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds) {
return 0;
}
}

View File

@ -577,4 +577,15 @@ public interface CommonGbChannelMapper {
@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

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

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