支持国标级联的目录订阅功能
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
@@ -35,6 +36,11 @@ public interface IGbStreamService {
|
||||
/**
|
||||
* 移除国标关联
|
||||
* @param gbStreams
|
||||
* @param platformId
|
||||
*/
|
||||
boolean delPlatformInfo(List<GbStream> gbStreams);
|
||||
boolean delPlatformInfo(String platformId, List<GbStream> gbStreams);
|
||||
|
||||
DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, String deviceGBId);
|
||||
|
||||
void sendCatalogMsg(GbStream gbStream, String type);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
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.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.storager.dao.GbStreamMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.ParentPlatformMapper;
|
||||
import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper;
|
||||
import com.genersoft.iot.vmp.service.IGbStreamService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
@@ -14,6 +21,7 @@ import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@@ -33,6 +41,15 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
@Autowired
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private ParentPlatformMapper platformMapper;
|
||||
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
@Override
|
||||
public PageInfo<GbStream> getAll(Integer page, Integer count) {
|
||||
PageHelper.startPage(page, count);
|
||||
@@ -51,32 +68,62 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
// 放在事务内执行
|
||||
boolean result = false;
|
||||
TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
|
||||
ParentPlatform parentPlatform = platformMapper.getParentPlatByServerGBId(platformId);
|
||||
try {
|
||||
List<DeviceChannel> deviceChannelList = new ArrayList<>();
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
gbStream.setCatalogId(catalogId);
|
||||
gbStream.setPlatformId(platformId);
|
||||
// TODO 修改为批量提交
|
||||
platformGbStreamMapper.add(gbStream);
|
||||
DeviceChannel deviceChannelListByStream = getDeviceChannelListByStream(gbStream, catalogId, parentPlatform.getDeviceGBId());
|
||||
deviceChannelList.add(deviceChannelListByStream);
|
||||
}
|
||||
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
||||
eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
|
||||
result = true;
|
||||
}catch (Exception e) {
|
||||
logger.error("批量保存流与平台的关系时错误", e);
|
||||
dataSourceTransactionManager.rollback(transactionStatus);
|
||||
}
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delPlatformInfo(List<GbStream> gbStreams) {
|
||||
public DeviceChannel getDeviceChannelListByStream(GbStream gbStream, String catalogId, String deviceGBId) {
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(gbStream.getGbId());
|
||||
deviceChannel.setName(gbStream.getName());
|
||||
deviceChannel.setLongitude(gbStream.getLongitude());
|
||||
deviceChannel.setLatitude(gbStream.getLatitude());
|
||||
deviceChannel.setDeviceId(deviceGBId);
|
||||
deviceChannel.setManufacture("wvp-pro");
|
||||
deviceChannel.setStatus(gbStream.isStatus()?1:0);
|
||||
deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId);
|
||||
deviceChannel.setRegisterWay(1);
|
||||
deviceChannel.setCivilCode(sipConfig.getDomain());
|
||||
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<>();
|
||||
for (GbStream gbStream : gbStreams) {
|
||||
platformGbStreamMapper.delByAppAndStream(gbStream.getApp(), gbStream.getStream());
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setChannelId(gbStream.getGbId());
|
||||
deviceChannelList.add(deviceChannel);
|
||||
eventPublisher.catalogEventPublish(platformId, deviceChannel, CatalogEvent.DEL);
|
||||
}
|
||||
|
||||
dataSourceTransactionManager.commit(transactionStatus); //手动提交
|
||||
result = true;
|
||||
}catch (Exception e) {
|
||||
@@ -85,4 +132,27 @@ public class GbStreamServiceImpl implements IGbStreamService {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendCatalogMsg(GbStream gbStream, String type) {
|
||||
List<GbStream> gbStreams = new ArrayList<>();
|
||||
if (gbStream.getGbId() != null) {
|
||||
gbStreams.add(gbStream);
|
||||
}else {
|
||||
StreamProxyItem streamProxyItem = gbStreamMapper.selectOne(gbStream.getApp(), gbStream.getStream());
|
||||
if (streamProxyItem != null && streamProxyItem.getGbId() != null){
|
||||
gbStreams.add(streamProxyItem);
|
||||
}
|
||||
}
|
||||
if (gbStreams.size() > 0) {
|
||||
for (GbStream gs : gbStreams) {
|
||||
List<ParentPlatform> parentPlatforms = platformGbStreamMapper.selectByAppAndStream(gs.getApp(), gs.getStream());
|
||||
if (parentPlatforms.size() > 0) {
|
||||
for (ParentPlatform parentPlatform : parentPlatforms) {
|
||||
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), gs, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,13 @@ package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
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.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaItem;
|
||||
@@ -57,12 +61,18 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
@Autowired
|
||||
private UserSetup userSetup;
|
||||
|
||||
@Autowired
|
||||
private SipConfig sipConfig;
|
||||
|
||||
@Autowired
|
||||
private GbStreamMapper gbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private ParentPlatformMapper parentPlatformMapper;
|
||||
|
||||
@@ -146,6 +156,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(param.getApp(), stream, parentPlatform.getServerGBId());
|
||||
if (streamProxyItems == null) {
|
||||
platformGbStreamMapper.add(param);
|
||||
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), param, CatalogEvent.ADD);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -194,6 +205,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||
public void del(String app, String stream) {
|
||||
StreamProxyItem streamProxyItem = videoManagerStorager.queryStreamProxy(app, stream);
|
||||
if (streamProxyItem != null) {
|
||||
gbStreamService.sendCatalogMsg(streamProxyItem, CatalogEvent.DEL);
|
||||
videoManagerStorager.deleteStreamProxy(app, stream);
|
||||
JSONObject jsonObject = removeStreamProxyFromZlm(streamProxyItem);
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
|
||||
@@ -5,12 +5,16 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.TypeReference;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
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.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.*;
|
||||
import com.genersoft.iot.vmp.service.IGbStreamService;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.IStreamPushService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
@@ -41,6 +45,12 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
@Autowired
|
||||
private PlatformGbStreamMapper platformGbStreamMapper;
|
||||
|
||||
@Autowired
|
||||
private IGbStreamService gbStreamService;
|
||||
|
||||
@Autowired
|
||||
private EventPublisher eventPublisher;
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@@ -115,6 +125,7 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
stream.setStreamType("push");
|
||||
stream.setStatus(true);
|
||||
int add = gbStreamMapper.add(stream);
|
||||
|
||||
// 查找开启了全部直播流共享的上级平台
|
||||
List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
|
||||
if (parentPlatforms.size() > 0) {
|
||||
@@ -122,18 +133,30 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
stream.setCatalogId(parentPlatform.getCatalogId());
|
||||
stream.setPlatformId(parentPlatform.getServerGBId());
|
||||
String streamId = stream.getStream();
|
||||
StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId());
|
||||
if (streamProxyItems == null) {
|
||||
StreamProxyItem streamProxyItem = platformGbStreamMapper.selectOne(stream.getApp(), streamId, parentPlatform.getServerGBId());
|
||||
if (streamProxyItem == null) {
|
||||
platformGbStreamMapper.add(stream);
|
||||
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);
|
||||
}else {
|
||||
if (!streamProxyItem.getGbId().equals(stream.getGbId())) {
|
||||
// 此流使用另一个国标Id已经与该平台关联,移除此记录
|
||||
platformGbStreamMapper.delByAppAndStreamAndPlatform(stream.getApp(), streamId, parentPlatform.getServerGBId());
|
||||
platformGbStreamMapper.add(stream);
|
||||
eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), stream, CatalogEvent.ADD);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return add > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeFromGB(GbStream stream) {
|
||||
// 判断是否需要发送事件
|
||||
gbStreamService.sendCatalogMsg(stream, CatalogEvent.DEL);
|
||||
int del = gbStreamMapper.del(stream.getApp(), stream.getStream());
|
||||
platformGbStreamMapper.delByAppAndStream(stream.getApp(), stream.getStream());
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(stream.getMediaServerId());
|
||||
JSONObject mediaList = zlmresTfulUtils.getMediaList(mediaInfo, stream.getApp(), stream.getStream());
|
||||
if (mediaList == null) {
|
||||
@@ -152,6 +175,8 @@ public class StreamPushServiceImpl implements IStreamPushService {
|
||||
@Override
|
||||
public boolean stop(String app, String streamId) {
|
||||
StreamPushItem streamPushItem = streamPushMapper.selectOne(app, streamId);
|
||||
gbStreamService.sendCatalogMsg(streamPushItem, CatalogEvent.DEL);
|
||||
|
||||
int delStream = streamPushMapper.del(app, streamId);
|
||||
gbStreamMapper.del(app, streamId);
|
||||
platformGbStreamMapper.delByAppAndStream(app, streamId);
|
||||
|
||||
Reference in New Issue
Block a user