临时提交

结构优化
648540858 2023-12-07 18:04:53 +08:00
parent 4897d9a501
commit dc4385da74
28 changed files with 251 additions and 1644 deletions

View File

@ -95,6 +95,15 @@ alter table wvp_platform
alter table wvp_platform
add share_region bool default false;
alter table wvp_device_channel
add common_gb_channel_id integer;
alter table wvp_stream_push
add common_gb_channel_id integer;
alter table wvp_stream_proxy
add common_gb_channel_id integer;

View File

@ -248,6 +248,7 @@ create table wvp_stream_proxy (
update_time character varying(50),
stream_key character varying(255),
enable_disable_none_reader bool default false,
common_gb_channel_id integer,
constraint uk_stream_proxy_app_stream unique (app, stream)
);
@ -266,6 +267,7 @@ create table wvp_stream_push (
update_time character varying(50),
push_ing bool default false,
self bool default false,
common_gb_channel_id integer,
constraint uk_stream_push_app_stream unique (app, stream)
);

View File

@ -1,6 +1,5 @@
package com.genersoft.iot.vmp.gb28181.bean;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import io.swagger.v3.oas.annotations.media.Schema;
@Schema(description = "通道信息")

View File

@ -1,13 +1,12 @@
package com.genersoft.iot.vmp.media.zlm.dto;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* @author lin
*/
@Schema(description = "拉流代理的信息")
public class StreamProxyItem extends GbStream {
public class StreamProxyItem {
@Schema(description = "类型")
private String type;
@ -44,6 +43,12 @@ public class StreamProxyItem extends GbStream {
@Schema(description = "拉流代理时zlm返回的key用于停止拉流代理")
private String streamKey;
/**
* ID
*/
@Schema(description = "国标通用信息ID")
private int commonGbChannelId;
public String getType() {
return type;
}
@ -52,32 +57,31 @@ public class StreamProxyItem extends GbStream {
this.type = type;
}
@Override
public String getApp() {
return app;
}
@Override
public void setApp(String app) {
this.app = app;
}
@Override
public String getStream() {
return stream;
}
@Override
public void setStream(String stream) {
this.stream = stream;
}
@Override
public String getMediaServerId() {
return mediaServerId;
}
@Override
public void setMediaServerId(String mediaServerId) {
this.mediaServerId = mediaServerId;
}
@ -177,4 +181,12 @@ public class StreamProxyItem extends GbStream {
public void setStreamKey(String streamKey) {
this.streamKey = streamKey;
}
public int getCommonGbChannelId() {
return commonGbChannelId;
}
public void setCommonGbChannelId(int commonGbChannelId) {
this.commonGbChannelId = commonGbChannelId;
}
}

View File

@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
import java.util.List;
@Schema(description = "推流信息")
public class StreamPushItem extends GbStream implements Comparable<StreamPushItem>{
public class StreamPushItem implements Comparable<StreamPushItem>{
/**
* id
@ -133,20 +133,17 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
@Schema(description = "是否自己平台的推流")
private boolean self;
/**
* ID
*/
@Schema(description = "国标通用信息ID")
private int commonGbChannelId;
public String getVhost() {
return vhost;
}
public void setVhost(String vhost) {
this.vhost = vhost;
}
@Override
public int compareTo(@NotNull StreamPushItem streamPushItem) {
return Long.valueOf(DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(super.createTime)
return Long.valueOf(DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(this.createTime)
- DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(streamPushItem.getCreateTime())).intValue();
}
@ -179,22 +176,18 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.id = id;
}
@Override
public String getApp() {
return app;
}
@Override
public void setApp(String app) {
this.app = app;
}
@Override
public String getStream() {
return stream;
}
@Override
public void setStream(String stream) {
this.stream = stream;
}
@ -231,7 +224,6 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.originSock = originSock;
}
public String getOriginTypeStr() {
return originTypeStr;
}
@ -264,13 +256,18 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.tracks = tracks;
}
public String getVhost() {
return vhost;
}
public void setVhost(String vhost) {
this.vhost = vhost;
}
@Override
public String getMediaServerId() {
return mediaServerId;
}
@Override
public void setMediaServerId(String mediaServerId) {
this.mediaServerId = mediaServerId;
}
@ -283,7 +280,6 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.serverId = serverId;
}
public String getPushTime() {
return pushTime;
}
@ -300,12 +296,10 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.updateTime = updateTime;
}
@Override
public String getCreateTime() {
return createTime;
}
@Override
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
@ -326,64 +320,12 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
this.self = self;
}
// @Override
// public Integer getGbStreamId() {
// return super.getGbStreamId();
// }
//
// @Override
// public void setGbStreamId(Integer gbStreamId) {
// super.setGbStreamId(gbStreamId);
// }
//
//
// public String getGbId() {
// return super.getGbId();
// }
//
// public void setGbId(String gbId) {
// super.setGbId(gbId);
// }
//
// public String getName() {
// return super.getName();
// }
//
// public void setName(String name) {
// super.setName(name);
// }
//
// public double getLongitude() {
// return super.getLongitude();
// }
//
// public void setLongitude(double longitude) {
// super.setLongitude(longitude);
// }
//
// public double getLatitude() {
// return super.getLatitude();
// }
//
// public void setLatitude(double latitude) {
// super.setLatitude(latitude);
// }
//
// public String getStreamType() {
// return super.getStreamType();
// }
//
// public void setStreamType(String streamType) {
// super.setStreamType(streamType);
// }
//
// public boolean isStatus() {
// return super.isStatus();
// }
//
// public void setStatus(boolean status) {
// super.setStatus(status);
// }
public int getCommonGbChannelId() {
return commonGbChannelId;
}
public void setCommonGbChannelId(int commonGbChannelId) {
this.commonGbChannelId = commonGbChannelId;
}
}

View File

@ -22,8 +22,6 @@ public interface ICommonGbChannelService {
int add(CommonGbChannel channel);
int addFromGbChannel(DeviceChannel channel);
int delete(String channelId);
int update(CommonGbChannel channel);

View File

@ -40,12 +40,6 @@ public interface IDeviceChannelService {
*/
ResourceBaseInfo getOverview();
/**
*
* @param platformId
* @return
*/
List<ChannelReduce> queryAllChannelList(String platformId);
/**
*

View File

@ -1,74 +0,0 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.github.pagehelper.PageInfo;
import java.util.List;
/**
*
*/
public interface IGbStreamService {
/**
*
* @param page
* @param count
* @return
*/
PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId,String query,String mediaServerId);
/**
*
* @param app
* @param stream
*/
void del(String app, String stream);
/**
*
* @param gbStreams
*/
boolean addPlatformInfo(List<GbStream> gbStreams, String platformId, String catalogId);
/**
*
* @param gbStreams
* @param platformId
*/
boolean delPlatformInfo(String platformId, List<GbStream> gbStreams);
DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, ParentPlatform platform);
void sendCatalogMsg(GbStream gbStream, String type);
void sendCatalogMsgs(List<GbStream> gbStreams, String type);
/**
* gbIdname
* @param streamPushItemForUpdate
* @return
*/
int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate);
DeviceChannel getDeviceChannelListByStreamWithStatus(GbStream gbStream, String catalogId, ParentPlatform platform);
/**
*
* @param platformId
* @return
*/
List<GbStream> getAllGBChannels(String platformId);
/**
*
* @param platformId
* @param catalogId
*/
void delAllPlatformInfo(String platformId, String catalogId);
List<GbStream> getGbChannelWithGbid(String gbId);
}

View File

@ -57,4 +57,9 @@ public interface IPlatformService {
void sendNotifyMobilePosition(String platformId);
void addSimulatedSubscribeInfo(ParentPlatform parentPlatform);
/**
*
*/
boolean delete(String serverGBId);
}

View File

@ -1,5 +1,6 @@
package com.genersoft.iot.vmp.service;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
@ -101,7 +102,7 @@ public interface IStreamPushService {
/**
*
*/
boolean add(StreamPushItem stream);
boolean add(StreamPushItem stream, CommonGbChannel commonGbChannel);
/**
* app+Streanm

View File

@ -71,23 +71,13 @@ public class CommonGbChannelServiceImpl implements ICommonGbChannelService {
@Override
public int add(CommonGbChannel channel) {
// TODO 给标记了共享所有通道的上级·平台发送数据
return commonGbChannelMapper.add(channel);
}
@Override
public int addFromGbChannel(DeviceChannel channel) {
CommonGbChannel commonGbChannel = commonGbChannelMapper.queryByDeviceID(channel.getChannelId());
logger.info("[添加通用通道]来自国标通道,国标编号: {}, 同步所有字段", channel.getChannelId());
if (commonGbChannel != null) {
logger.info("[添加通用通道]来自国标通道,失败,已存在。国标编号: {}", channel.getChannelId());
return 0;
}
CommonGbChannel commonChannelFromDeviceChannel = getCommonChannelFromDeviceChannel(channel, null);
return commonGbChannelMapper.add(commonChannelFromDeviceChannel);
}
@Override
public int delete(String channelId) {
return commonGbChannelMapper.deleteByDeviceID(channelId);
}

View File

@ -16,7 +16,6 @@ import com.genersoft.iot.vmp.service.bean.Region;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ResourceBaseInfo;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -201,12 +200,6 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService {
return new ResourceBaseInfo(total, online);
}
@Override
public List<ChannelReduce> queryAllChannelList(String platformId) {
return channelMapper.queryChannelListInAll(null, null, null, platformId, null);
}
@Override
public boolean updateAllGps(Device device) {
List<DeviceChannel> deviceChannels = channelMapper.getChannelsWithoutTransform(device.getDeviceId());

View File

@ -1,272 +0,0 @@
package com.genersoft.iot.vmp.service.impl;
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.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
import com.genersoft.iot.vmp.storager.dao.PlatformCatalogMapper;
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.List;
@Service
public class GbStreamServiceImpl implements IGbStreamService {
private final static Logger logger = LoggerFactory.getLogger(GbStreamServiceImpl.class);
@Autowired
DataSourceTransactionManager dataSourceTransactionManager;
@Autowired
TransactionDefinition transactionDefinition;
@Autowired
private GbStreamMapper gbStreamMapper;
@Autowired
private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private SubscribeHolder subscribeHolder;
@Autowired
private ParentPlatformMapper platformMapper;
@Autowired
private PlatformCatalogMapper catalogMapper;
@Autowired
private EventPublisher eventPublisher;
@Override
public PageInfo<GbStream> getAll(Integer page, Integer count, String platFormId, String catalogId, String query, String mediaServerId) {
PageHelper.startPage(page, count);
List<GbStream> all = gbStreamMapper.selectAll(platFormId, catalogId, query, mediaServerId);
return new PageInfo<>(all);
}
@Override
public void del(String app, String stream) {
gbStreamMapper.del(app, stream);
}
@Override
public boolean addPlatformInfo(List<GbStream> gbStreams, String platformId, String catalogId) {
// 放在事务内执行
boolean result = false;
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
ParentPlatform parentPlatform = platformMapper.getParentPlatByServerGBId(platformId);
if (catalogId == null) {
catalogId = parentPlatform.getCatalogId();
}
try {
List<DeviceChannel> deviceChannelList = new ArrayList<>();
for (int i = 0; i < gbStreams.size(); i++) {
GbStream gbStream = gbStreams.get(i);
gbStream.setCatalogId(catalogId);
gbStream.setPlatformId(platformId);
// TODO 修改为批量提交
platformGbStreamMapper.add(gbStream);
logger.info("[关联通道]直播流通道 平台:{}, 共需关联通道数:{}, 已关联:{}", platformId, gbStreams.size(), i + 1);
DeviceChannel deviceChannelListByStream = getDeviceChannelListByStreamWithStatus(gbStream, catalogId, parentPlatform);
deviceChannelList.add(deviceChannelListByStream);
}
dataSourceTransactionManager.commit(transactionStatus); //手动提交
if (subscribeHolder.getCatalogSubscribe(platformId) != null) {
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
}
result = true;
}catch (Exception e) {
logger.error("批量保存流与平台的关系时错误", e);
dataSourceTransactionManager.rollback(transactionStatus);
}
return result;
}
@Override
public DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, ParentPlatform platform) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
deviceChannel.setName(gbStream.getName());
deviceChannel.setLongitude(gbStream.getLongitude());
deviceChannel.setLatitude(gbStream.getLatitude());
deviceChannel.setDeviceId(platform.getDeviceGBId());
deviceChannel.setManufacture("wvp-pro");
deviceChannel.setStatus(gbStream.isStatus());
deviceChannel.setRegisterWay(1);
PlatformCatalog catalog = catalogMapper.selectByPlatFormAndCatalogId(platform.getServerGBId(), catalogId);
if (catalog != null) {
deviceChannel.setCivilCode(catalog.getCivilCode());
deviceChannel.setParentId(catalog.getParentId());
deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId());
}else {
deviceChannel.setCivilCode(platform.getAdministrativeDivision());
deviceChannel.setParentId(platform.getDeviceGBId());
}
deviceChannel.setModel("live");
deviceChannel.setOwner("wvp-pro");
deviceChannel.setParental(0);
deviceChannel.setSecrecy("0");
return deviceChannel;
}
@Override
public boolean delPlatformInfo(String platformId, List<GbStream> gbStreams) {
// 放在事务内执行
boolean result = false;
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try {
List<DeviceChannel> deviceChannelList = new ArrayList<>();
platformGbStreamMapper.delByAppAndStreamsByPlatformId(gbStreams, platformId);
for (GbStream gbStream : gbStreams) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
deviceChannelList.add(deviceChannel);
}
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL);
dataSourceTransactionManager.commit(transactionStatus); //手动提交
result = true;
}catch (Exception e) {
logger.error("批量移除流与平台的关系时错误", e);
dataSourceTransactionManager.rollback(transactionStatus);
}
return result;
}
@Override
public void sendCatalogMsg(GbStream gbStream, String type) {
if (gbStream == null || type == null) {
logger.warn("[发送目录订阅]类型流信息或类型为NULL");
return;
}
List<GbStream> gbStreams = new ArrayList<>();
if (gbStream.getGbId() != null) {
gbStreams.add(gbStream);
}else {
GbStream gbStreamIndb = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream());
if (gbStreamIndb != null && gbStreamIndb.getGbId() != null){
gbStreams.add(gbStreamIndb);
}
}
sendCatalogMsgs(gbStreams, type);
}
@Override
public void sendCatalogMsgs(List<GbStream> gbStreams, String type) {
if (gbStreams.size() > 0) {
for (GbStream gs : gbStreams) {
if (ObjectUtils.isEmpty(gs.getGbId())){
continue;
}
List<ParentPlatform> parentPlatforms = platformGbStreamMapper.selectByAppAndStream(gs.getApp(), gs.getStream());
if (parentPlatforms.size() > 0) {
for (ParentPlatform parentPlatform : parentPlatforms) {
if (parentPlatform != null) {
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), gs, type);
}
}
}
}
}
}
@Override
public int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate) {
return gbStreamMapper.updateGbIdOrName(streamPushItemForUpdate);
}
@Override
public DeviceChannel getDeviceChannelListByStreamWithStatus(GbStream gbStream, String catalogId, ParentPlatform platform) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
deviceChannel.setName(gbStream.getName());
deviceChannel.setLongitude(gbStream.getLongitude());
deviceChannel.setLatitude(gbStream.getLatitude());
deviceChannel.setDeviceId(platform.getDeviceGBId());
deviceChannel.setManufacture("wvp-pro");
// todo 目前是每一条查询一次,需要优化
Boolean status = null;
if ("proxy".equals(gbStream.getStreamType())) {
status = gbStreamMapper.selectStatusForProxy(gbStream.getApp(), gbStream.getStream());
}else {
status = gbStreamMapper.selectStatusForPush(gbStream.getApp(), gbStream.getStream());
}
deviceChannel.setStatus(status != null && status);
deviceChannel.setRegisterWay(1);
PlatformCatalog catalog = catalogMapper.selectByPlatFormAndCatalogId(platform.getServerGBId(), catalogId);
if (catalog != null) {
deviceChannel.setCivilCode(catalog.getCivilCode());
deviceChannel.setParentId(catalog.getParentId());
deviceChannel.setBusinessGroupId(catalog.getBusinessGroupId());
}else {
deviceChannel.setCivilCode(platform.getAdministrativeDivision());
deviceChannel.setParentId(platform.getDeviceGBId());
}
deviceChannel.setModel("live");
deviceChannel.setOwner("wvp-pro");
deviceChannel.setParental(0);
deviceChannel.setSecrecy("0");
return deviceChannel;
}
@Override
public List<GbStream> getAllGBChannels(String platformId) {
return gbStreamMapper.selectAll(platformId, null, null, null);
}
@Override
public void delAllPlatformInfo(String platformId, String catalogId) {
if (platformId == null) {
return ;
}
ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformId);
if (platform == null) {
return ;
}
if (ObjectUtils.isEmpty(catalogId)) {
catalogId = platform.getDeviceGBId();
}
if (platformGbStreamMapper.delByPlatformAndCatalogId(platformId, catalogId) > 0) {
List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformId, catalogId);
List<DeviceChannel> deviceChannelList = new ArrayList<>();
for (GbStream gbStream : gbStreams) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
deviceChannelList.add(deviceChannel);
}
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL);
}
}
@Override
public List<GbStream> getGbChannelWithGbid(String gbId) {
return gbStreamMapper.selectByGBId(gbId);
}
}

View File

@ -28,7 +28,7 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
private final static Logger logger = LoggerFactory.getLogger(PlatformChannelServiceImpl.class);
@Autowired
private PlatformChannelMapper platformChannelMapper;
private CommonChannelPlatformMapper platformChannelMapper;
@Autowired
private CommonChannelMapper commonGbChannelMapper;
@ -42,16 +42,6 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Autowired
private SubscribeHolder subscribeHolder;
@Autowired
private DeviceChannelMapper deviceChannelMapper;
@Autowired
private PlatformCatalogMapper catalogManager;
@Autowired
private ParentPlatformMapper platformMapper;
@Autowired
EventPublisher eventPublisher;
@ -100,6 +90,32 @@ public class PlatformChannelServiceImpl implements IPlatformChannelService {
@Override
public int removeChannelForGB(ParentPlatform platform, List<Integer> commonGbChannelIds) {
return 0;
assert platform != null;
if (commonGbChannelIds.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "有效待关联通道Id为空");
}
int allCount = 0;
if (commonGbChannelIds.size() > BatchLimit.count) {
for (int i = 0; i < commonGbChannelIds.size(); i += BatchLimit.count) {
int toIndex = i + BatchLimit.count;
if (i + BatchLimit.count > commonGbChannelIds.size()) {
toIndex = commonGbChannelIds.size();
}
int count = platformChannelMapper.removeChannels(platform.getId(), commonGbChannelIds.subList(i, toIndex));
allCount += count;
logger.info("[关联通道]国标通道 平台:{}, 取消关联通道数:{}, 已关联:{}", platform.getServerGBId(), commonGbChannelIds.size(), allCount);
}
}else {
allCount = platformChannelMapper.removeChannels(platform.getId(), commonGbChannelIds);
logger.info("[关联通道]国标通道 平台:{}, 取消关联通道数:{}", platform.getServerGBId(), commonGbChannelIds.size());
}
SubscribeInfo catalogSubscribe = subscribeHolder.getCatalogSubscribe(platform.getServerGBId());
if (catalogSubscribe != null) {
List<CommonGbChannel> channelList = commonGbChannelMapper.queryInIdList(commonGbChannelIds);
if (channelList != null) {
eventPublisher.catalogEventPublish(platform.getServerGBId(), channelList, CatalogEvent.DEL);
}
}
return allCount;
}
}

View File

@ -1,7 +1,9 @@
package com.genersoft.iot.vmp.service.impl;
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
@ -15,6 +17,7 @@ import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import gov.nist.javax.sip.message.SIPRequest;
@ -50,15 +53,6 @@ public class PlatformServiceImpl implements IPlatformService {
@Autowired
private ParentPlatformMapper platformMapper;
@Autowired
private PlatformCatalogMapper catalogMapper;
@Autowired
private PlatformChannelMapper platformChannelMapper;
@Autowired
private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@ -427,4 +421,51 @@ public class PlatformServiceImpl implements IPlatformService {
}
}
}
@Override
public boolean delete(String serverGBId) {
ParentPlatform parentPlatform = platformMapper.getParentPlatByServerGBId(serverGBId);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(serverGBId);
if (parentPlatform == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
}
// TODO 发送取消订阅的消息,等待市场检验后确定需要再添加此项,暂时记录
// 可通过发送subscription-state 头域为terminated 的 NOTIFY 消息主动结束订阅, NOTIFY消息体可为空,
// 订阅方接收到该消息后回复200 OK 响应。
// 停止推流
stopAllPush(parentPlatform.getServerGBId());
// 停止发送位置订阅定时任务
String sendMobilePositionTaskKey = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() + "_MobilePosition_" + parentPlatform.getServerGBId();
if (dynamicTask.contains(sendMobilePositionTaskKey)) {
dynamicTask.stop(sendMobilePositionTaskKey);
}
// 停止注册
final String registerTaskKey = REGISTER_KEY_PREFIX + parentPlatform.getServerGBId();
if (dynamicTask.contains(registerTaskKey)) {
dynamicTask.stop(registerTaskKey);
}
// 清除定时心跳
final String keepaliveTaskKey = KEEPALIVE_KEY_PREFIX + parentPlatform.getServerGBId();
if (dynamicTask.contains(keepaliveTaskKey)) {
dynamicTask.stop(keepaliveTaskKey);
}
// 删除缓存的订阅信息
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
// 发送注销的请求
if (parentPlatformCatch != null && parentPlatformCatch.getSipTransactionInfo() != null) {
// 发送离线消息,无论是否成功都删除缓存
try {
commanderForPlatform.unregister(parentPlatform, parentPlatformCatch.getSipTransactionInfo(), null, null);
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
} finally {
// 清空redis缓存
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
}
}
return true;
}
}

View File

@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.conf.MediaConfig;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.*;
@ -13,9 +14,10 @@ import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.*;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OriginType;
import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.service.ICommonGbChannelService;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.service.bean.CommonGbChannelType;
import com.genersoft.iot.vmp.service.bean.StreamPushItemFromRedis;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.dao.*;
@ -30,6 +32,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.*;
@ -40,27 +43,12 @@ public class StreamPushServiceImpl implements IStreamPushService {
private final static Logger logger = LoggerFactory.getLogger(StreamPushServiceImpl.class);
@Autowired
private GbStreamMapper gbStreamMapper;
@Autowired
private StreamPushMapper streamPushMapper;
@Autowired
private StreamProxyMapper streamProxyMapper;
@Autowired
private ParentPlatformMapper parentPlatformMapper;
@Autowired
private PlatformCatalogMapper platformCatalogMapper;
@Autowired
private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private IGbStreamService gbStreamService;
@Autowired
private EventPublisher eventPublisher;
@ -76,6 +64,9 @@ public class StreamPushServiceImpl implements IStreamPushService {
@Autowired
private IMediaServerService mediaServerService;
@Autowired
private ICommonGbChannelService commonGbChannelService;
@Autowired
DataSourceTransactionManager dataSourceTransactionManager;
@ -126,8 +117,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
streamPushItem.setOriginUrl(item.getOriginUrl());
streamPushItem.setCreateTime(DateUtil.getNow());
streamPushItem.setAliveSecond(item.getAliveSecond());
streamPushItem.setStatus(true);
streamPushItem.setStreamType("push");
streamPushItem.setVhost(item.getVhost());
streamPushItem.setServerId(item.getSeverId());
return streamPushItem;
@ -145,37 +134,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
return streamPushMapper.selectAllByMediaServerIdWithOutGbID(mediaServerId);
}
@Override
public boolean saveToGB(GbStream stream) {
stream.setStreamType("push");
stream.setStatus(true);
stream.setCreateTime(DateUtil.getNow());
stream.setStreamType("push");
stream.setMediaServerId(mediaConfig.getId());
int add = gbStreamMapper.add(stream);
return add > 0;
}
@Override
public boolean removeFromGB(GbStream stream) {
// 判断是否需要发送事件
gbStreamService.sendCatalogMsg(stream, CatalogEvent.DEL);
platformGbStreamMapper.delByAppAndStream(stream.getApp(), stream.getStream());
int del = gbStreamMapper.del(stream.getApp(), stream.getStream());
MediaServerItem mediaInfo = mediaServerService.getOne(stream.getMediaServerId());
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, stream.getApp(), stream.getStream());
if (mediaList != null) {
if (mediaList.getInteger("code") == 0) {
JSONArray data = mediaList.getJSONArray("data");
if (data == null) {
streamPushMapper.del(stream.getApp(), stream.getStream());
}
}
}
return del > 0;
}
@Override
public StreamPushItem getPush(String app, String streamId) {
return streamPushMapper.selectOne(app, streamId);
@ -456,10 +414,6 @@ public class StreamPushServiceImpl implements IStreamPushService {
if (gbStreams == null || gbStreams.size() == 0) {
return false;
}
gbStreamService.sendCatalogMsgs(gbStreams, CatalogEvent.DEL);
platformGbStreamMapper.delByGbStreams(gbStreams);
gbStreamMapper.batchDelForGbStream(gbStreams);
int delStream = streamPushMapper.delAllForGbStream(gbStreams);
if (delStream > 0) {
for (GbStream gbStream : gbStreams) {
@ -502,27 +456,25 @@ public class StreamPushServiceImpl implements IStreamPushService {
}
@Override
public boolean add(StreamPushItem stream) {
stream.setUpdateTime(DateUtil.getNow());
stream.setCreateTime(DateUtil.getNow());
stream.setServerId(userSetting.getServerId());
@Transactional
public boolean add(StreamPushItem stream, CommonGbChannel commonGbChannel) {
assert !ObjectUtils.isEmpty(commonGbChannel.getCommonGbDeviceID());
assert !ObjectUtils.isEmpty(commonGbChannel.getCommonGbName());
String now = DateUtil.getNow();
commonGbChannel.setCreateTime(now);
commonGbChannel.setUpdateTime(now);
commonGbChannel.setType(CommonGbChannelType.PUSH);
// 放在事务内执行
boolean result = false;
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
try {
int addStreamResult = streamPushMapper.add(stream);
if (!ObjectUtils.isEmpty(stream.getGbId())) {
stream.setStreamType("push");
gbStreamMapper.add(stream);
}
dataSourceTransactionManager.commit(transactionStatus);
result = true;
}catch (Exception e) {
logger.error("批量移除流与平台的关系时错误", e);
dataSourceTransactionManager.rollback(transactionStatus);
commonGbChannelService.add(commonGbChannel);
if (commonGbChannel.getCommonGbId() > 0) {
stream.setCommonGbChannelId(commonGbChannel.getCommonGbId());
}else {
return false;
}
return result;
stream.setUpdateTime(now);
stream.setCreateTime(now);
stream.setServerId(userSetting.getServerId());
return streamPushMapper.add(stream) > 1;
}
@Override

View File

@ -24,7 +24,7 @@ public interface IVideoManagerStorage {
* @param deviceId ID
* @return true: false
*/
public boolean exists(String deviceId);
boolean exists(String deviceId);
/**
*
@ -32,14 +32,14 @@ public interface IVideoManagerStorage {
* @param channelId ID
* @param streamId
*/
public void startPlay(String deviceId, String channelId, String streamId);
void startPlay(String deviceId, String channelId, String streamId);
/**
*
* @param deviceId id
* @param channelId ID
*/
public void stopPlay(String deviceId, String channelId);
void stopPlay(String deviceId, String channelId);
/**
*
@ -47,7 +47,7 @@ public interface IVideoManagerStorage {
* @param deviceId ID
* @return DShadow
*/
public Device queryVideoDevice(String deviceId);
Device queryVideoDevice(String deviceId);
/**
*
@ -57,33 +57,24 @@ public interface IVideoManagerStorage {
* @param count
* @return
*/
public PageInfo<DeviceChannel> queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count);
PageInfo<DeviceChannel> queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, Boolean catalogUnderDevice, int page, int count);
public List<DeviceChannelExtend> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, List<String> channelIds, String query, Boolean hasSubChannel, Boolean online, int start, int limit);
List<DeviceChannelExtend> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, List<String> channelIds, String query, Boolean hasSubChannel, Boolean online, int start, int limit);
/**
*
*
* @param deviceId ID
* @return
*/
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds);
public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId);
/**
*
* @param deviceId ID
* @param channelId ID
*/
public DeviceChannel queryChannel(String deviceId, String channelId);
DeviceChannel queryChannel(String deviceId, String channelId);
/**
*
* @param deviceId ID
* @param channelId ID
*/
public int delChannel(String deviceId, String channelId);
int delChannel(String deviceId, String channelId);
/**
*
@ -91,14 +82,14 @@ public interface IVideoManagerStorage {
* @param count
* @return List<Device>
*/
public PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online);
PageInfo<Device> queryVideoDeviceList(int page, int count,Boolean online);
/**
*
*
* @return List<Device>
*/
public List<Device> queryVideoDeviceList(Boolean online);
List<Device> queryVideoDeviceList(Boolean online);
@ -120,26 +111,6 @@ public interface IVideoManagerStorage {
*/
void cleanChannelsForDevice(String deviceId);
/**
*
* @param parentPlatform
*/
boolean updateParentPlatform(ParentPlatform parentPlatform);
/**
*
* @param parentPlatform
*/
boolean addParentPlatform(ParentPlatform parentPlatform);
/**
*
* @param parentPlatform
*/
boolean deleteParentPlatform(ParentPlatform parentPlatform);
/**
*
* @return
@ -153,36 +124,8 @@ public interface IVideoManagerStorage {
*/
ParentPlatform queryParentPlatByServerGBId(String platformGbId);
/**
* 线
*/
void outlineForAllParentPlatform();
/**
* ()
*/
PageInfo<ChannelReduce> queryAllChannelList(int page, int count, String query, Boolean online, Boolean channelType, String platformId, String catalogId);
/**
*
*/
List<DeviceChannelInPlatform> queryChannelListInParentPlatform(String platformId);
/**
*
* @param platformId
* @param channelReduces
* @return
*/
int delChannelForGB(String platformId, List<ChannelReduce> channelReduces);
DeviceChannel queryChannelInParentPlatform(String platformId, String channelId);
List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId);
List<PlatformCatalog> queryStreamInParentPlatformAndCatalog(String platformId, String catalogId);
Device queryVideoDeviceByPlatformIdAndChannelId(String platformId, String channelId);
@ -214,11 +157,6 @@ public interface IVideoManagerStorage {
*/
public MobilePosition queryLatestPosition(String deviceId);
/**
*
* @param deviceId
*/
public int clearMobilePositionsByDeviceId(String deviceId);
/**
*
@ -228,13 +166,6 @@ public interface IVideoManagerStorage {
*/
public int deleteStreamProxy(String app, String stream);
/**
*
* @param enable
* @return
*/
public List<StreamProxyItem> getStreamProxyListForEnable(boolean enable);
/**
* appstream
* @param app
@ -278,16 +209,6 @@ public interface IVideoManagerStorage {
*/
int mediaOffline(String app, String streamId);
/**
* 线
*/
int mediaOnline(String app, String streamId);
/**
* 线/线
*/
void updateParentPlatformStatus(String platformGbID, boolean online);
/**
* ID/
* @param id ID
@ -296,13 +217,6 @@ public interface IVideoManagerStorage {
*/
List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable);
/**
* ID
* @param channelId ID
* @return
*/
Device queryVideoDeviceByChannelId(String channelId);
/**
* 线
* @param channelId ID
@ -323,28 +237,6 @@ public interface IVideoManagerStorage {
*/
StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId);
/**
*
* @param platformId
* @param parentId
* @return
*/
List<PlatformCatalog> getChildrenCatalogByPlatform(String platformId, String parentId);
int addCatalog(PlatformCatalog platformCatalog);
PlatformCatalog getCatalog(String platformId, String id);
int delCatalog(String platformId, String id);
int updateCatalog(PlatformCatalog platformCatalog);
int setDefaultCatalog(String platformId, String catalogId);
List<DeviceChannel> queryCatalogInPlatform(String serverGBId);
int delRelation(PlatformCatalog platformCatalog);
int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfo);
List<ParentPlatform> queryPlatFormListForGBWithGBId(String channelId, List<String> platforms);
@ -353,19 +245,11 @@ public interface IVideoManagerStorage {
GbStream getGbStream(String app, String streamId);
void delCatalogByPlatformId(String serverGBId);
void delRelationByPlatformId(String serverGBId);
PlatformCatalog queryDefaultCatalogInPlatform(String platformId);
List<ChannelSourceInfo> getChannelSource(String platformId, String gbId);
void updateChannelPosition(DeviceChannel deviceChannel);
void cleanContentForPlatform(String serverGBId);
List<DeviceChannel> queryChannelWithCatalog(String serverGBId);
List<DeviceChannelExtend> queryChannelsByDeviceId(String serial, List<String> channelIds, Boolean online);

View File

@ -150,6 +150,7 @@ public interface CommonChannelMapper {
" <if test='createTime != null' > ,#{createTime}</if>" +
")" +
"</script>")
@Options(useGeneratedKeys=true, keyProperty="commonGbId", keyColumn="common_gb_id")
int add(CommonGbChannel channel);
@Delete("delete from wvp_common_channel where common_gb_device_id = #{channelId}")

View File

@ -17,4 +17,29 @@ import java.util.Map;
public interface CommonChannelPlatformMapper {
@Select(" <script>" +
"select * from wvp_common_channel_platform where platform_id = #{platformId} and common_gb_channel_id in " +
"<foreach collection='commonGbChannelIds' item='item' open='(' separator=',' close=')' >#{item}</foreach>" +
" </script>")
List<Integer> findChannelsInDb(@Param("platformId") Integer platformId,
@Param("commonGbChannelIds") List<Integer> commonGbChannelIds);
@Insert("<script> " +
"INSERT into wvp_common_channel_platform " +
"(platform_id, common_gb_channel_id)" +
"values " +
"<foreach collection='commonGbChannelIds' index='index' item='item' separator=','> " +
"(#{platformId}, #{item}) "+
"</foreach> " +
"</script>")
int addChannels(@Param("platformId") Integer platformId,
@Param("commonGbChannelIds") List<Integer> commonGbChannelIds);
@Delete("<script> " +
"delete from wvp_common_channel_platform " +
"where platform_id = #{platformId} and common_gb_channel_id in " +
"<foreach collection='commonGbChannelIds' item='item' open='(' separator=',' close=')' >#{item}</foreach>" +
"</script>")
int removeChannels(@Param("platformId") Integer platformId,
@Param("commonGbChannelIds") List<Integer> commonGbChannelIds);
}

View File

@ -3,7 +3,6 @@ package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannelInPlatform;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
@ -149,33 +148,6 @@ public interface DeviceChannelMapper {
@Update(value = {"UPDATE wvp_device_channel SET stream_id=#{streamId} WHERE device_id=#{deviceId} AND channel_id=#{channelId}"})
void startPlay(@Param("deviceId") String deviceId, @Param("channelId") String channelId, @Param("streamId") String streamId);
@Select(value = {" <script>" +
"SELECT " +
" dc.id,\n" +
" dc.channel_id,\n" +
" dc.device_id,\n" +
" dc.name,\n" +
" de.manufacturer,\n" +
" de.host_address,\n" +
" dc.sub_count,\n" +
" pgc.platform_id as platform_id,\n" +
" pgc.catalog_id as catalog_id " +
" FROM wvp_device_channel dc " +
" LEFT JOIN wvp_device de ON dc.device_id = de.device_id " +
" LEFT JOIN wvp_platform_gb_channel pgc on pgc.device_channel_id = dc.id " +
" WHERE 1=1 " +
" <if test='query != null'> AND (dc.channel_id LIKE concat('%',#{query},'%') OR dc.name LIKE concat('%',#{query},'%') OR dc.name LIKE concat('%',#{query},'%'))</if> " +
" <if test='online == true' > AND dc.status=true</if> " +
" <if test='online == false' > AND dc.status=false</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == true' > AND dc.sub_count > 0</if> " +
" <if test='hasSubChannel!= null and hasSubChannel == false' > AND dc.sub_count = 0</if> " +
" <if test='catalogId == null ' > AND dc.id not in (select device_channel_id from wvp_platform_gb_channel where platform_id=#{platformId} ) </if> " +
" <if test='catalogId != null ' > AND pgc.platform_id = #{platformId} and pgc.catalog_id=#{catalogId} </if> " +
" ORDER BY dc.device_id, dc.channel_id ASC" +
" </script>"})
List<ChannelReduce> queryChannelListInAll(@Param("query") String query, @Param("online") Boolean online, @Param("hasSubChannel") Boolean hasSubChannel, @Param("platformId") String platformId, @Param("catalogId") String catalogId);
@Select(value = {" <script>" +
"SELECT " +
" dc.*,\n" +

View File

@ -1,173 +0,0 @@
package com.genersoft.iot.vmp.storager.dao;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface GbStreamMapper {
@Insert("INSERT INTO wvp_gb_stream (app, stream, gb_id, name, " +
"longitude, latitude, stream_type,media_server_id,create_time) VALUES" +
"(#{app}, #{stream}, #{gbId}, #{name}, " +
"#{longitude}, #{latitude}, #{streamType}, " +
"#{mediaServerId}, #{createTime})")
@Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gbStreamId")
int add(GbStream gbStream);
@Update("UPDATE wvp_gb_stream " +
"SET app=#{app}," +
"stream=#{stream}," +
"gb_id=#{gbId}," +
"name=#{name}," +
"stream_type=#{streamType}," +
"longitude=#{longitude}, " +
"latitude=#{latitude}," +
"media_server_id=#{mediaServerId}" +
"WHERE app=#{app} AND stream=#{stream}")
int updateByAppAndStream(GbStream gbStream);
@Update("UPDATE wvp_gb_stream " +
"SET app=#{app}," +
"stream=#{stream}," +
"gb_id=#{gbId}," +
"name=#{name}," +
"stream_type=#{streamType}," +
"longitude=#{longitude}, " +
"latitude=#{latitude}," +
"media_server_id=#{mediaServerId}" +
"WHERE gb_stream_id=#{gbStreamId}")
int update(GbStream gbStream);
@Delete("DELETE FROM wvp_gb_stream WHERE app=#{app} AND stream=#{stream}")
int del(@Param("app") String app, @Param("stream") String stream);
@Select("<script> "+
"SELECT gs.* FROM wvp_gb_stream gs " +
"WHERE " +
"1=1 " +
" <if test='catalogId != null'> AND gs.gb_stream_id in" +
"(select pgs.gb_stream_id from wvp_platform_gb_stream pgs where pgs.platform_id = #{platformId} and pgs.catalog_id=#{catalogId})</if> " +
" <if test='catalogId == null'> AND gs.gb_stream_id not in" +
"(select pgs.gb_stream_id from wvp_platform_gb_stream pgs where pgs.platform_id = #{platformId}) </if> " +
" <if test='query != null'> AND (gs.app LIKE concat('%',#{query},'%') OR gs.stream LIKE concat('%',#{query},'%') OR gs.gb_id LIKE concat('%',#{query},'%') OR gs.name LIKE concat('%',#{query},'%'))</if> " +
" <if test='mediaServerId != null' > AND gs.media_server_id=#{mediaServerId} </if>" +
" order by gs.gb_stream_id asc " +
"</script>")
List<GbStream> selectAll(@Param("platformId") String platformId, @Param("catalogId") String catalogId, @Param("query") String query, @Param("mediaServerId") String mediaServerId);
@Select("SELECT * FROM wvp_gb_stream WHERE app=#{app} AND stream=#{stream}")
GbStream selectOne(@Param("app") String app, @Param("stream") String stream);
@Select("SELECT * FROM wvp_gb_stream WHERE gb_id=#{gbId}")
List<GbStream> selectByGBId(String gbId);
@Select("SELECT gs.*, pgs.platform_id as platform_id, pgs.catalog_id as catalog_id FROM wvp_gb_stream gs " +
"LEFT JOIN wvp_platform_gb_stream pgs ON gs.gb_stream_id = pgs.gb_stream_id " +
"WHERE gs.gb_id = #{gbId} AND pgs.platform_id = #{platformId}")
GbStream queryStreamInPlatform(@Param("platformId") String platformId, @Param("gbId") String gbId);
@Select("<script> "+
"select gt.gb_id as channel_id, gt.name, 'wvp-pro' as manufacture, st.status, gt.longitude, gt.latitude, pc.id as parent_id," +
" '1' as register_way, pc.civil_code, 'live' as model, 'wvp-pro' as owner, '0' as parental,'0' as secrecy" +
" from wvp_gb_stream gt " +
" left join (" +
" select " +
" <if test='usPushingAsStatus != true'> sp.status as status, </if>" +
" <if test='usPushingAsStatus == true'> sp.push_ing as status, </if>" +
"sp.app, sp.stream from wvp_stream_push sp" +
" union all" +
" select spxy.status, spxy.app, spxy.stream from wvp_stream_proxy spxy" +
" ) st on st.app = gt.app and st.stream = gt.stream" +
" left join wvp_platform_gb_stream pgs on gt.gb_stream_id = pgs.gb_stream_id" +
" left join wvp_platform_catalog pc on pgs.catalog_id = pc.id and pgs.platform_id = pc.platform_id" +
" where pgs.platform_id=#{platformId}" +
"</script>")
List<DeviceChannel> queryGbStreamListInPlatform(String platformId, @Param("usPushingAsStatus") boolean usPushingAsStatus);
@Select("SELECT gs.* FROM wvp_gb_stream gs left join wvp_platform_gb_stream pgs " +
"ON gs.gb_stream_id = pgs.gb_stream_id WHERE pgs.gb_stream_id is NULL")
List<GbStream> queryStreamNotInPlatform();
@Delete("DELETE FROM wvp_gb_stream WHERE stream_type=#{type} AND gb_id=NULL AND media_server_id=#{mediaServerId}")
void deleteWithoutGBId(@Param("type") String type, @Param("mediaServerId") String mediaServerId);
@Delete("<script> "+
"DELETE FROM wvp_gb_stream where " +
"<foreach collection='streamProxyItemList' item='item' separator='or'>" +
"(app=#{item.app} and stream=#{item.stream}) " +
"</foreach>" +
"</script>")
void batchDel(List<StreamProxyItem> streamProxyItemList);
@Delete("<script> "+
"DELETE FROM wvp_gb_stream where " +
"<foreach collection='gbStreams' item='item' separator='or'>" +
"(app=#{item.app} and stream=#{item.stream}) " +
"</foreach>" +
"</script>")
void batchDelForGbStream(List<GbStream> gbStreams);
@Insert("<script> " +
"INSERT into wvp_gb_stream " +
"(app, stream, gb_id, name, " +
"longitude, latitude, stream_type,media_server_id,create_time)" +
"values " +
"<foreach collection='subList' index='index' item='item' separator=','> " +
"(#{item.app}, #{item.stream}, #{item.gbId}, #{item.name}, " +
"#{item.longitude}, #{item.latitude}, #{item.streamType}, " +
"#{item.mediaServerId}, #{item.createTime}) "+
"</foreach> " +
"</script>")
@Options(useGeneratedKeys = true, keyProperty = "gbStreamId", keyColumn = "gb_stream_id")
void batchAdd(@Param("subList") List<StreamPushItem> subList);
@Update({"<script>" +
"<foreach collection='gpsMsgInfos' item='item' separator=';'>" +
" UPDATE" +
" wvp_gb_stream" +
" SET longitude=#{item.lng}, latitude=#{item.lat} " +
"WHERE gb_id=#{item.id}"+
"</foreach>" +
"</script>"})
int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos);
@Select("<script> "+
"SELECT * FROM wvp_gb_stream where " +
"<foreach collection='streamPushItems' item='item' separator='or'>" +
"(app=#{item.app} and stream=#{item.stream}) " +
"</foreach>" +
"</script>")
List<GbStream> selectAllForAppAndStream(List<StreamPushItem> streamPushItems);
@Update("UPDATE wvp_gb_stream " +
"SET media_server_id=#{mediaServerId}" +
"WHERE app=#{app} AND stream=#{stream}")
void updateMediaServer(String app, String stream, String mediaServerId);
@Update("<script> "+
" <foreach collection='list' item='item' index='index' separator=';'>"+
"UPDATE wvp_gb_stream " +
" SET name=#{item.name},"+
" gb_id=#{item.gb_id}"+
" WHERE app=#{item.app} and stream=#{item.stream}"+
"</foreach>"+
"</script>")
int updateGbIdOrName(List<StreamPushItem> streamPushItemForUpdate);
@Select("SELECT status FROM wvp_stream_proxy WHERE app=#{app} AND stream=#{stream}")
Boolean selectStatusForProxy(@Param("app") String app, @Param("stream") String stream);
@Select("SELECT status FROM wvp_stream_push WHERE app=#{app} AND stream=#{stream}")
Boolean selectStatusForPush(@Param("app") String app, @Param("stream") String stream);
}

View File

@ -67,12 +67,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
@Autowired
private ParentPlatformMapper platformMapper;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private PlatformChannelMapper platformChannelMapper;
@Autowired
private StreamProxyMapper streamProxyMapper;
@ -85,18 +79,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
@Autowired
private UserSetting userSetting;
@Autowired
private PlatformCatalogMapper catalogMapper;
@Autowired
private PlatformGbStreamMapper platformGbStreamMapper;
@Autowired
private IGbStreamService gbStreamService;
@Autowired
private ParentPlatformMapper parentPlatformMapper;
/**
* ID
*
@ -161,12 +143,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, channelIds, null, query, hasSubChannel, online, start, limit);
}
@Override
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId,Boolean online,List<String> channelIds) {
return deviceChannelMapper.queryChannels(deviceId, null,null, null, online,channelIds);
}
@Override
public List<DeviceChannelExtend> queryChannelsByDeviceId(String deviceId, List<String> channelIds, Boolean online) {
return deviceChannelMapper.queryChannelsWithDeviceInfo(deviceId, null,null, null, online,channelIds);
@ -245,62 +221,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceMobilePositionMapper.queryPositionByDeviceIdAndTime(deviceId, channelId, startTime, endTime);
}
@Override
public boolean addParentPlatform(ParentPlatform parentPlatform) {
if (parentPlatform.getCatalogId() == null) {
parentPlatform.setCatalogId(parentPlatform.getServerGBId());
}
int result = platformMapper.addParentPlatform(parentPlatform);
return result > 0;
}
@Override
public boolean updateParentPlatform(ParentPlatform parentPlatform) {
int result = 0;
if (parentPlatform.getCatalogGroup() == 0) {
parentPlatform.setCatalogGroup(1);
}
if (parentPlatform.getAdministrativeDivision() == null) {
parentPlatform.setAdministrativeDivision(parentPlatform.getAdministrativeDivision());
}
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(parentPlatform.getServerGBId()); // .getDeviceGBId());
if (parentPlatform.getId() == null ) {
if (parentPlatform.getCatalogId() == null) {
parentPlatform.setCatalogId(parentPlatform.getServerGBId());
}
result = platformMapper.addParentPlatform(parentPlatform);
if (parentPlatformCatch == null) {
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setParentPlatform(parentPlatform);
parentPlatformCatch.setId(parentPlatform.getServerGBId());
}
}else {
if (parentPlatformCatch == null) { // serverGBId 已变化
ParentPlatform parentPlatById = platformMapper.getParentPlatById(parentPlatform.getId());
// 使用旧的查出缓存ID
parentPlatformCatch = new ParentPlatformCatch();
parentPlatformCatch.setId(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformCatchInfo(parentPlatById.getServerGBId());
}
result = platformMapper.updateParentPlatform(parentPlatform);
}
// 更新缓存
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
return result > 0;
}
@Transactional
@Override
public boolean deleteParentPlatform(ParentPlatform parentPlatform) {
int result = platformMapper.delParentPlatform(parentPlatform);
// 删除关联的通道
platformChannelMapper.cleanChannelForGB(parentPlatform.getServerGBId());
return result > 0;
}
@Override
public ParentPlatform queryParentPlatByServerGBId(String platformGbId) {
return platformMapper.getParentPlatByServerGBId(platformGbId);
@ -321,41 +241,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceMapper.queryDeviceWithAsMessageChannel();
}
@Override
public void outlineForAllParentPlatform() {
platformMapper.outlineForAllParentPlatform();
}
@Override
public PageInfo<ChannelReduce> queryAllChannelList(int page, int count, String query, Boolean online,
Boolean channelType, String platformId, String catalogId) {
PageHelper.startPage(page, count);
List<ChannelReduce> all = deviceChannelMapper.queryChannelListInAll(query, online, channelType, platformId, catalogId);
return new PageInfo<>(all);
}
@Override
public List<DeviceChannelInPlatform> queryChannelListInParentPlatform(String platformId) {
return deviceChannelMapper.queryChannelByPlatformId(platformId);
}
@Override
public int delChannelForGB(String platformId, List<ChannelReduce> channelReduces) {
int result = platformChannelMapper.delChannelForGB(platformId, channelReduces);
List<DeviceChannel> deviceChannelList = new ArrayList<>();
for (ChannelReduce channelReduce : channelReduces) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(channelReduce.getChannelId());
deviceChannelList.add(deviceChannel);
}
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL);
return result;
}
@Override
public DeviceChannel queryChannelInParentPlatform(String platformId, String channelId) {
List<DeviceChannel> channels = platformChannelMapper.queryChannelInParentPlatform(platformId, channelId);
@ -370,18 +255,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
}
@Override
public List<PlatformCatalog> queryChannelInParentPlatformAndCatalog(String platformId, String catalogId) {
List<PlatformCatalog> catalogs = platformChannelMapper.queryChannelInParentPlatformAndCatalog(platformId, catalogId);
return catalogs;
}
@Override
public List<PlatformCatalog> queryStreamInParentPlatformAndCatalog(String platformId, String catalogId) {
List<PlatformCatalog> catalogs = platformGbStreamMapper.queryChannelInParentPlatformAndCatalogForCatalog(platformId, catalogId);
return catalogs;
}
@Override
public Device queryVideoDeviceByPlatformIdAndChannelId(String platformId, String channelId) {
List<Device> devices = platformChannelMapper.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId);
@ -421,16 +294,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceMobilePositionMapper.queryLatestPositionByDevice(deviceId);
}
/**
*
* @param deviceId
*/
@Override
public int clearMobilePositionsByDeviceId(String deviceId) {
return deviceMobilePositionMapper.clearMobilePositionsByDeviceId(deviceId);
}
/**
*
* @param app
@ -442,16 +305,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return streamProxyMapper.del(app, stream);
}
/**
*
* @param enable
* @return
*/
@Override
public List<StreamProxyItem> getStreamProxyListForEnable(boolean enable) {
return streamProxyMapper.selectForEnable(enable);
}
/**
*
* @param page
@ -514,106 +367,16 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return result;
}
@Override
public int mediaOnline(String app, String stream) {
GbStream gbStream = gbStreamMapper.selectOne(app, stream);
int result;
if ("proxy".equals(gbStream.getStreamType())) {
result = streamProxyMapper.updateStatus(app, stream, true);
}else {
result = streamPushMapper.updatePushStatus(app, stream, true);
}
return result;
}
@Override
public void updateParentPlatformStatus(String platformGbID, boolean online) {
platformMapper.updateParentPlatformStatus(platformGbID, online);
}
@Override
public List<StreamProxyItem> getStreamProxyListForEnableInMediaServer(String id, boolean enable) {
return streamProxyMapper.selectForEnableInMediaServer(id, enable);
}
@Override
public Device queryVideoDeviceByChannelId( String channelId) {
Device result = null;
List<DeviceChannel> channelList = deviceChannelMapper.queryChannelByChannelId(channelId);
if (channelList.size() == 1) {
result = deviceMapper.getDeviceByDeviceId(channelList.get(0).getDeviceId());
}
return result;
}
@Override
public StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId) {
return streamProxyMapper.selectOne(app, streamId);
}
@Override
public List<PlatformCatalog> getChildrenCatalogByPlatform(String platformId, String parentId) {
return catalogMapper.selectByParentId(platformId, parentId);
}
@Override
public int addCatalog(PlatformCatalog platformCatalog) {
ParentPlatform platform = platformMapper.getParentPlatByServerGBId(platformCatalog.getPlatformId());
if (platform == null) {
return 0;
}
if (platformCatalog.getId().length() <= 8) {
platformCatalog.setCivilCode(platformCatalog.getParentId());
}else {
if (platformCatalog.getId().length() != 20) {
return 0;
}
if (platformCatalog.getParentId() != null) {
switch (Integer.parseInt(platformCatalog.getId().substring(10, 13))){
case 200:
case 215:
if (platformCatalog.getParentId().length() <= 8) {
platformCatalog.setCivilCode(platformCatalog.getParentId());
}else {
PlatformCatalog catalog = catalogMapper.selectByPlatFormAndCatalogId(platformCatalog.getPlatformId(), platformCatalog.getParentId());
if (catalog != null) {
platformCatalog.setCivilCode(catalog.getCivilCode());
}
}
break;
case 216:
if (platformCatalog.getParentId().length() <= 8) {
platformCatalog.setCivilCode(platformCatalog.getParentId());
}else {
PlatformCatalog catalog = catalogMapper.selectByPlatFormAndCatalogId(platformCatalog.getPlatformId(),platformCatalog.getParentId());
if (catalog == null) {
logger.warn("[添加目录] 无法获取目录{}的CivilCode和BusinessGroupId", platformCatalog.getPlatformId());
break;
}
platformCatalog.setCivilCode(catalog.getCivilCode());
if (Integer.parseInt(platformCatalog.getParentId().substring(10, 13)) == 215) {
platformCatalog.setBusinessGroupId(platformCatalog.getParentId());
}else {
if (Integer.parseInt(platformCatalog.getParentId().substring(10, 13)) == 216) {
platformCatalog.setBusinessGroupId(catalog.getBusinessGroupId());
}
}
}
break;
default:
break;
}
}
}
int result = catalogMapper.add(platformCatalog);
if (result > 0) {
DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog);
eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.ADD);
}
return result;
}
private PlatformCatalog getTopCatalog(String id, String platformId) {
PlatformCatalog catalog = catalogMapper.selectByPlatFormAndCatalogId(platformId, id);
if (catalog.getParentId().equals(platformId)) {
@ -623,90 +386,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
}
}
@Override
public PlatformCatalog getCatalog(String platformId, String id) {
return catalogMapper.selectByPlatFormAndCatalogId(platformId, id);
}
@Override
public int delCatalog(String platformId, String id) {
return delCatalogExecute(id, platformId);
}
private int delCatalogExecute(String id, String platformId) {
int delresult = catalogMapper.del(platformId, id);
DeviceChannel deviceChannelForCatalog = new DeviceChannel();
if (delresult > 0){
deviceChannelForCatalog.setChannelId(id);
eventPublisher.catalogEventPublish(platformId, deviceChannelForCatalog, CatalogEvent.DEL);
}
List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformId, id);
if (gbStreams.size() > 0){
List<DeviceChannel> deviceChannelList = new ArrayList<>();
for (GbStream gbStream : gbStreams) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
deviceChannelList.add(deviceChannel);
}
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL);
}
int delStreamresult = platformGbStreamMapper.delByPlatformAndCatalogId(platformId,id);
List<PlatformCatalog> platformCatalogs = platformChannelMapper.queryChannelInParentPlatformAndCatalog(platformId, id);
if (platformCatalogs.size() > 0){
List<DeviceChannel> deviceChannelList = new ArrayList<>();
for (PlatformCatalog platformCatalog : platformCatalogs) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(platformCatalog.getId());
deviceChannelList.add(deviceChannel);
}
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.DEL);
}
int delChannelresult = platformChannelMapper.delByCatalogId(platformId, id);
return delresult + delChannelresult + delStreamresult;
}
@Override
public int updateCatalog(PlatformCatalog platformCatalog) {
int result = catalogMapper.update(platformCatalog);
if (result > 0) {
DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog);
eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.UPDATE);
}
return result;
}
@Override
public int setDefaultCatalog(String platformId, String catalogId) {
return platformMapper.setDefaultCatalog(platformId, catalogId, DateUtil.getNow());
}
@Override
public List<DeviceChannel> queryCatalogInPlatform(String platformId) {
return catalogMapper.queryCatalogInPlatform(platformId);
}
@Override
public int delRelation(PlatformCatalog platformCatalog) {
if (platformCatalog.getType() == 1) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(platformCatalog.getId());
eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.DEL);
return platformChannelMapper.delByCatalogIdAndChannelIdAndPlatformId(platformCatalog);
}else if (platformCatalog.getType() == 2) {
List<GbStream> gbStreams = platformGbStreamMapper.queryChannelInParentPlatformAndCatalog(platformCatalog.getPlatformId(), platformCatalog.getParentId());
for (GbStream gbStream : gbStreams) {
if (gbStream.getGbId().equals(platformCatalog.getId())) {
DeviceChannel deviceChannel = new DeviceChannel();
deviceChannel.setChannelId(gbStream.getGbId());
eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.DEL);
return platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream());
}
}
}
return 0;
}
@Override
public int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos) {
return gbStreamMapper.updateStreamGPS(gpsMsgInfos);
@ -733,11 +412,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return deviceChannel;
}
@Override
public List<DeviceChannel> queryOnlineChannelsByDeviceId(String deviceId) {
return deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId);
}
@Override
public List<ParentPlatform> queryPlatFormListForGBWithGBId(String channelId, List<String> platforms) {
return platformChannelMapper.queryPlatFormListForGBWithGBId(channelId, platforms);
@ -756,22 +430,6 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
return gbStreamMapper.selectOne(app, streamId);
}
@Override
public void delCatalogByPlatformId(String serverGBId) {
catalogMapper.delByPlatformId(serverGBId);
}
@Override
public void delRelationByPlatformId(String serverGBId) {
platformGbStreamMapper.delByPlatformId(serverGBId);
platformChannelMapper.delByPlatformId(serverGBId);
}
@Override
public PlatformCatalog queryDefaultCatalogInPlatform(String platformId) {
return catalogMapper.selectDefaultByPlatFormId(platformId);
}
@Override
public List<ChannelSourceInfo> getChannelSource(String platformId, String gbId) {
return platformMapper.getChannelSource(platformId, gbId);
@ -788,27 +446,4 @@ public class VideoManagerStorageImpl implements IVideoManagerStorage {
deviceChannelMapper.updatePosition(deviceChannel);
}
@Override
public void cleanContentForPlatform(String serverGBId) {
// List<PlatformCatalog> catalogList = catalogMapper.selectByPlatForm(serverGBId);
// if (catalogList.size() > 0) {
// int result = catalogMapper.delByPlatformId(serverGBId);
// if (result > 0) {
// List<DeviceChannel> deviceChannels = new ArrayList<>();
// for (PlatformCatalog catalog : catalogList) {
// deviceChannels.add(getDeviceChannelByCatalog(catalog));
// }
// eventPublisher.catalogEventPublish(serverGBId, deviceChannels, CatalogEvent.DEL);
// }
// }
catalogMapper.delByPlatformId(serverGBId);
platformChannelMapper.delByPlatformId(serverGBId);
platformGbStreamMapper.delByPlatformId(serverGBId);
}
@Override
public List<DeviceChannel> queryChannelWithCatalog(String serverGBId) {
return deviceChannelMapper.queryChannelWithCatalog(serverGBId);
}
}

View File

@ -1,131 +0,0 @@
package com.genersoft.iot.vmp.vmanager.gb28181.gbStream;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.service.IGbStreamService;
import com.genersoft.iot.vmp.service.IPlatformService;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean.GbStreamParam;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@Tag(name = "视频流关联到级联平台")
@RestController
@RequestMapping("/api/gbStream")
public class GbStreamController {
private final static Logger logger = LoggerFactory.getLogger(GbStreamController.class);
@Autowired
private IGbStreamService gbStreamService;
@Autowired
private IPlatformService platformService;
/**
*
* @param page
* @param count
* @param platformId ID
* @return
*/
@Operation(summary = "查询国标通道")
@Parameter(name = "page", description = "当前页", required = true)
@Parameter(name = "count", description = "每页条数", required = true)
@Parameter(name = "platformId", description = "平台ID", required = true)
@Parameter(name = "catalogId", description = "目录ID")
@Parameter(name = "query", description = "查询内容")
@Parameter(name = "mediaServerId", description = "流媒体ID")
@GetMapping(value = "/list")
@ResponseBody
public PageInfo<GbStream> list(@RequestParam(required = true)Integer page,
@RequestParam(required = true)Integer count,
@RequestParam(required = true)String platformId,
@RequestParam(required = false)String catalogId,
@RequestParam(required = false)String query,
@RequestParam(required = false)String mediaServerId){
if (ObjectUtils.isEmpty(catalogId)) {
catalogId = null;
}
if (ObjectUtils.isEmpty(query)) {
query = null;
}
if (ObjectUtils.isEmpty(mediaServerId)) {
mediaServerId = null;
}
// catalogId 为null 查询未在平台下分配的数据
// catalogId 不为null 查询平台下这个,目录下的通道
return gbStreamService.getAll(page, count, platformId, catalogId, query, mediaServerId);
}
/**
*
* @param gbStreamParam
* @return
*/
@Operation(summary = "移除国标关联")
@DeleteMapping(value = "/del")
@ResponseBody
public void del(@RequestBody GbStreamParam gbStreamParam){
if (gbStreamParam.getGbStreams() == null || gbStreamParam.getGbStreams().size() == 0) {
if (gbStreamParam.isAll()) {
gbStreamService.delAllPlatformInfo(gbStreamParam.getPlatformId(), gbStreamParam.getCatalogId());
}
}else {
gbStreamService.delPlatformInfo(gbStreamParam.getPlatformId(), gbStreamParam.getGbStreams());
}
}
/**
*
* @param gbStreamParam
* @return
*/
@Operation(summary = "保存国标关联")
@PostMapping(value = "/add")
@ResponseBody
public void add(@RequestBody GbStreamParam gbStreamParam){
if (gbStreamParam.getGbStreams() == null || gbStreamParam.getGbStreams().size() == 0) {
if (gbStreamParam.isAll()) {
List<GbStream> allGBChannels = gbStreamService.getAllGBChannels(gbStreamParam.getPlatformId());
gbStreamService.addPlatformInfo(allGBChannels, gbStreamParam.getPlatformId(), gbStreamParam.getCatalogId());
}
}else {
gbStreamService.addPlatformInfo(gbStreamParam.getGbStreams(), gbStreamParam.getPlatformId(), gbStreamParam.getCatalogId());
}
}
/**
*
* @param gbId
* @return
*/
@Operation(summary = "保存国标关联")
@GetMapping(value = "/addWithGbid")
@ResponseBody
public void add(String gbId, String platformGbId, @RequestParam(required = false) String catalogGbId){
List<GbStream> gbStreams = gbStreamService.getGbChannelWithGbid(gbId);
if (gbStreams.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "gbId的信息未找到");
}
gbStreamService.addPlatformInfo(gbStreams, platformGbId, catalogGbId);
}
}

View File

@ -1,54 +0,0 @@
package com.genersoft.iot.vmp.vmanager.gb28181.gbStream.bean;
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
@Schema(description = "国标关联参数")
public class GbStreamParam {
@Schema(description = "平台ID")
private String platformId;
@Schema(description = "目录ID")
private String catalogId;
@Schema(description = "关联所有通道")
private boolean all;
@Schema(description = "流国标信息列表")
private List<GbStream> gbStreams;
public String getPlatformId() {
return platformId;
}
public String getCatalogId() {
return catalogId;
}
public void setCatalogId(String catalogId) {
this.catalogId = catalogId;
}
public void setPlatformId(String platformId) {
this.platformId = platformId;
}
public List<GbStream> getGbStreams() {
return gbStreams;
}
public void setGbStreams(List<GbStream> gbStreams) {
this.gbStreams = gbStreams;
}
public boolean isAll() {
return all;
}
public void setAll(boolean all) {
this.all = all;
}
}

View File

@ -45,27 +45,15 @@ public class PlatformController {
private final static Logger logger = LoggerFactory.getLogger(PlatformController.class);
@Autowired
private UserSetting userSetting;
@Autowired
private IVideoManagerStorage storager;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private SubscribeHolder subscribeHolder;
@Autowired
private ISIPCommanderForPlatform commanderForPlatform;
@Autowired
private SipConfig sipConfig;
@Autowired
private DynamicTask dynamicTask;
@Autowired
private IPlatformService platformService;
@ -215,43 +203,10 @@ public class PlatformController {
if (logger.isDebugEnabled()) {
logger.debug("删除上级平台API调用");
}
if (ObjectUtils.isEmpty(serverGBId)
) {
if (ObjectUtils.isEmpty(serverGBId)) {
throw new ControllerException(ErrorCode.ERROR400);
}
ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(serverGBId);
ParentPlatformCatch parentPlatformCatch = redisCatchStorage.queryPlatformCatchInfo(serverGBId);
if (parentPlatform == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
}
if (parentPlatformCatch == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "平台不存在");
}
// 发送离线消息,无论是否成功都删除缓存
try {
commanderForPlatform.unregister(parentPlatform, parentPlatformCatch.getSipTransactionInfo(), (event -> {
// 清空redis缓存
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
}), (event -> {
// 清空redis缓存
redisCatchStorage.delPlatformCatchInfo(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformKeepalive(parentPlatform.getServerGBId());
redisCatchStorage.delPlatformRegister(parentPlatform.getServerGBId());
}));
} catch (InvalidArgumentException | ParseException | SipException e) {
logger.error("[命令发送失败] 国标级联 注销: {}", e.getMessage());
}
boolean deleteResult = storager.deleteParentPlatform(parentPlatform);
storager.delCatalogByPlatformId(parentPlatform.getServerGBId());
storager.delRelationByPlatformId(parentPlatform.getServerGBId());
// 停止发送位置订阅定时任务
String key = VideoManagerConstants.SIP_SUBSCRIBE_PREFIX + userSetting.getServerId() + "_MobilePosition_" + parentPlatform.getServerGBId();
dynamicTask.stop(key);
// 删除缓存的订阅信息
subscribeHolder.removeAllSubscribe(parentPlatform.getServerGBId());
boolean deleteResult = platformService.delete(serverGBId);
if (!deleteResult) {
throw new ControllerException(ErrorCode.ERROR100);
}

View File

@ -1,137 +0,0 @@
package com.genersoft.iot.vmp.vmanager.gb28181.platform.bean;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import io.swagger.v3.oas.annotations.media.Schema;
/**
* channel使
*/
@Schema(description = "精简的channel信息展示")
public class ChannelReduce {
/**
* deviceChannelID
*/
@Schema(description = "deviceChannel的数据库自增ID")
private int id;
/**
* id
*/
@Schema(description = "通道国标编号")
private String channelId;
/**
* id
*/
@Schema(description = "设备国标编号")
private String deviceId;
/**
*
*/
@Schema(description = "通道名")
private String name;
/**
*
*/
@Schema(description = "生产厂商")
private String manufacturer;
/**
* wan
*/
@Schema(description = "wan地址")
private String hostAddress;
/**
*
*/
@Schema(description = "子节点数")
private int subCount;
/**
* Id
*/
@Schema(description = "平台上级国标编号")
private String platformId;
/**
* Id
*/
@Schema(description = "目录国标编号")
private String catalogId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getChannelId() {
return channelId;
}
public void setChannelId(String channelId) {
this.channelId = channelId;
}
public String getDeviceId() {
return deviceId;
}
public void setDeviceId(String deviceId) {
this.deviceId = deviceId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getHostAddress() {
return hostAddress;
}
public void setHostAddress(String hostAddress) {
this.hostAddress = hostAddress;
}
public int getSubCount() {
return subCount;
}
public void setSubCount(int subCount) {
this.subCount = subCount;
}
public String getPlatformId() {
return platformId;
}
public void setPlatformId(String platformId) {
this.platformId = platformId;
}
public String getCatalogId() {
return catalogId;
}
public void setCatalogId(String catalogId) {
this.catalogId = catalogId;
}
}

View File

@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.streamPush;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.genersoft.iot.vmp.common.CommonGbChannel;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
@ -17,6 +18,7 @@ import com.genersoft.iot.vmp.service.IMediaService;
import com.genersoft.iot.vmp.service.IStreamPushService;
import com.genersoft.iot.vmp.service.impl.StreamPushUploadFileHandler;
import com.genersoft.iot.vmp.vmanager.bean.*;
import com.genersoft.iot.vmp.vmanager.streamPush.bean.StreamPushWithCommonChannelParam;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -59,8 +61,6 @@ public class StreamPushController {
@Autowired
private IMediaService mediaService;
@Autowired
private UserSetting userSetting;
@GetMapping(value = "/list")
@ResponseBody
@ -86,23 +86,11 @@ public class StreamPushController {
return pushList;
}
@PostMapping(value = "/save_to_gb")
@PostMapping(value = "/save")
@ResponseBody
@Operation(summary = "将推流添加到国标")
public void saveToGB(@RequestBody GbStream stream){
if (!streamPushService.saveToGB(stream)){
throw new ControllerException(ErrorCode.ERROR100);
}
}
@Operation(summary = "将推流添加到资源")
public void saveToCommonChannel(@RequestBody StreamPushWithCommonChannelParam param){
@DeleteMapping(value = "/remove_form_gb")
@ResponseBody
@Operation(summary = "将推流移出到国标")
public void removeFormGB(@RequestBody GbStream stream){
if (!streamPushService.removeFromGB(stream)){
throw new ControllerException(ErrorCode.ERROR100);
}
}
@ -256,24 +244,19 @@ public class StreamPushController {
/**
*
* @param stream
* @return
*/
@PostMapping(value = "/add")
@ResponseBody
@Operation(summary = "添加推流信息")
public void add(@RequestBody StreamPushItem stream){
if (ObjectUtils.isEmpty(stream.getGbId())) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "国标ID不可为空");
}
if (ObjectUtils.isEmpty(stream.getApp()) && ObjectUtils.isEmpty(stream.getStream())) {
public void add(@RequestBody StreamPushWithCommonChannelParam param){
if (ObjectUtils.isEmpty(param.getApp()) && ObjectUtils.isEmpty(param.getStream())) {
throw new ControllerException(ErrorCode.ERROR400.getCode(), "app或stream不可为空");
}
stream.setStatus(false);
stream.setPushIng(false);
stream.setAliveSecond(0L);
stream.setTotalReaderCount("0");
if (!streamPushService.add(stream)) {
StreamPushItem streamPushItem = new StreamPushItem();
streamPushItem.setApp(param.getApp());
streamPushItem.setStream(param.getStream());
if (!streamPushService.add(streamPushItem, param)) {
throw new ControllerException(ErrorCode.ERROR100);
}
}

View File

@ -0,0 +1,39 @@
package com.genersoft.iot.vmp.vmanager.streamPush.bean;
import com.genersoft.iot.vmp.common.CommonGbChannel;
/**
*
*/
public class StreamPushWithCommonChannelParam extends CommonGbChannel {
private Integer pushId;
private String app;
private String stream;
public Integer getPushId() {
return pushId;
}
public void setPushId(Integer pushId) {
this.pushId = pushId;
}
public String getApp() {
return app;
}
public void setApp(String app) {
this.app = app;
}
public String getStream() {
return stream;
}
public void setStream(String stream) {
this.stream = stream;
}
}