From c5ddf5985892f052263240a02e21215027e6ee05 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 19 一月 2022 17:40:03 +0800
Subject: [PATCH] 修改readme
---
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java | 478 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 456 insertions(+), 22 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
index 4e24753..dc4d497 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
@@ -1,14 +1,17 @@
package com.genersoft.iot.vmp.storager.impl;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
+import com.genersoft.iot.vmp.conf.SipConfig;
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.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
+import com.genersoft.iot.vmp.service.IGbStreamService;
+import com.genersoft.iot.vmp.service.bean.GPSMsgInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.storager.dao.*;
import com.genersoft.iot.vmp.vmanager.gb28181.platform.bean.ChannelReduce;
import com.github.pagehelper.PageHelper;
@@ -18,22 +21,30 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.stereotype.Component;
-
-import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
/**
- * @Description:瑙嗛璁惧鏁版嵁瀛樺偍-jdbc瀹炵幇
- * @author: swwheihei
- * @date: 2020骞�5鏈�6鏃� 涓嬪崍2:31:42
+ * 瑙嗛璁惧鏁版嵁瀛樺偍-jdbc瀹炵幇
+ * swwheihei
+ * 2020骞�5鏈�6鏃� 涓嬪崍2:31:42
*/
@SuppressWarnings("rawtypes")
@Component
public class VideoManagerStoragerImpl implements IVideoManagerStorager {
private Logger logger = LoggerFactory.getLogger(VideoManagerStoragerImpl.class);
+
+ @Autowired
+ EventPublisher eventPublisher;
+
+ @Autowired
+ SipConfig sipConfig;
@Autowired
DataSourceTransactionManager dataSourceTransactionManager;
@@ -69,6 +80,19 @@
private GbStreamMapper gbStreamMapper;
@Autowired
+ private PlatformCatalogMapper catalogMapper;
+;
+
+ @Autowired
+ private PlatformGbStreamMapper platformGbStreamMapper;
+
+ @Autowired
+ private IGbStreamService gbStreamService;
+
+ @Autowired
+ private ParentPlatformMapper parentPlatformMapper;
+
+ @Autowired
private VideoStreamSessionManager streamSession;
@Autowired
@@ -96,6 +120,7 @@
*/
@Override
public synchronized boolean create(Device device) {
+ redisCatchStorage.updateDevice(device);
return deviceMapper.add(device) > 0;
}
@@ -109,15 +134,19 @@
*/
@Override
public synchronized boolean updateDevice(Device device) {
- String now = this.format.format(new Date(System.currentTimeMillis()));
+ String now = this.format.format(System.currentTimeMillis());
device.setUpdateTime(now);
Device deviceByDeviceId = deviceMapper.getDeviceByDeviceId(device.getDeviceId());
if (deviceByDeviceId == null) {
device.setCreateTime(now);
+ redisCatchStorage.updateDevice(device);
return deviceMapper.add(device) > 0;
}else {
+ redisCatchStorage.updateDevice(device);
+
return deviceMapper.update(device) > 0;
}
+
}
@@ -126,7 +155,7 @@
String channelId = channel.getChannelId();
channel.setDeviceId(deviceId);
channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId()));
- String now = this.format.format(new Date(System.currentTimeMillis()));
+ String now = this.format.format(System.currentTimeMillis());
channel.setUpdateTime(now);
DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId);
if (deviceChannel == null) {
@@ -135,6 +164,134 @@
}else {
deviceChannelMapper.update(channel);
}
+ }
+
+ @Override
+ public int updateChannels(String deviceId, List<DeviceChannel> channels) {
+ List<DeviceChannel> addChannels = new ArrayList<>();
+ List<DeviceChannel> updateChannels = new ArrayList<>();
+ HashMap<String, DeviceChannel> channelsInStore = new HashMap<>();
+ if (channels != null && channels.size() > 0) {
+ List<DeviceChannel> channelList = deviceChannelMapper.queryChannelsByDeviceId(deviceId);
+ if (channelList.size() == 0) {
+ for (DeviceChannel channel : channels) {
+ channel.setDeviceId(deviceId);
+ channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId()));
+ String now = this.format.format(System.currentTimeMillis());
+ channel.setUpdateTime(now);
+ channel.setCreateTime(now);
+ addChannels.add(channel);
+ }
+ }else {
+ for (DeviceChannel deviceChannel : channelList) {
+ channelsInStore.put(deviceChannel.getChannelId(), deviceChannel);
+ }
+ for (DeviceChannel channel : channels) {
+ String channelId = channel.getChannelId();
+ channel.setDeviceId(deviceId);
+ channel.setStreamId(streamSession.getStreamId(deviceId, channel.getChannelId()));
+ String now = this.format.format(System.currentTimeMillis());
+ channel.setUpdateTime(now);
+ if (channelsInStore.get(channel.getChannelId()) != null) {
+ updateChannels.add(channel);
+ }else {
+ addChannels.add(channel);
+ channel.setCreateTime(now);
+ }
+ }
+ }
+ int limitCount = 300;
+ if (addChannels.size() > 0) {
+ if (addChannels.size() > limitCount) {
+ for (int i = 0; i < addChannels.size(); i += limitCount) {
+ int toIndex = i + limitCount;
+ if (i + limitCount > addChannels.size()) {
+ toIndex = addChannels.size();
+ }
+ deviceChannelMapper.batchAdd(addChannels.subList(i, toIndex));
+ }
+ }else {
+ deviceChannelMapper.batchAdd(addChannels);
+ }
+ }
+ if (updateChannels.size() > 0) {
+ if (updateChannels.size() > limitCount) {
+ for (int i = 0; i < updateChannels.size(); i += limitCount) {
+ int toIndex = i + limitCount;
+ if (i + limitCount > updateChannels.size()) {
+ toIndex = updateChannels.size();
+ }
+ deviceChannelMapper.batchUpdate(updateChannels.subList(i, toIndex));
+ }
+ }else {
+ deviceChannelMapper.batchUpdate(updateChannels);
+ }
+ }
+ }
+ return addChannels.size() + updateChannels.size();
+ }
+
+ @Override
+ public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
+ TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
+ // 鏁版嵁鍘婚噸
+ List<DeviceChannel> channels = new ArrayList<>();
+ StringBuilder stringBuilder = new StringBuilder();
+ if (deviceChannelList.size() > 1) {
+ // 鏁版嵁鍘婚噸
+ Set<String> gbIdSet = new HashSet<>();
+ for (DeviceChannel deviceChannel : deviceChannelList) {
+ if (!gbIdSet.contains(deviceChannel.getChannelId())) {
+ gbIdSet.add(deviceChannel.getChannelId());
+ channels.add(deviceChannel);
+ }else {
+ stringBuilder.append(deviceChannel.getChannelId() + ",");
+ }
+ }
+ }else {
+ channels = deviceChannelList;
+ }
+ if (stringBuilder.length() > 0) {
+ logger.debug("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder);
+ }
+ try {
+ int cleanChannelsResult = deviceChannelMapper.cleanChannelsByDeviceId(deviceId);
+ int limitCount = 300;
+ boolean result = cleanChannelsResult < 0;
+ if (!result && channels.size() > 0) {
+ if (channels.size() > limitCount) {
+ for (int i = 0; i < channels.size(); i += limitCount) {
+ int toIndex = i + limitCount;
+ if (i + limitCount > channels.size()) {
+ toIndex = channels.size();
+ }
+ result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0;
+ }
+ }else {
+ result = result || deviceChannelMapper.batchAdd(channels) < 0;
+ }
+ }
+ if (result) {
+ //浜嬪姟鍥炴粴
+ dataSourceTransactionManager.rollback(transactionStatus);
+ }
+ dataSourceTransactionManager.commit(transactionStatus); //鎵嬪姩鎻愪氦
+ return true;
+ }catch (Exception e) {
+ dataSourceTransactionManager.rollback(transactionStatus);
+ return false;
+ }
+
+ }
+
+ @Override
+ public void deviceChannelOnline(String deviceId, String channelId) {
+ deviceChannelMapper.online(deviceId, channelId);
+ }
+
+ @Override
+ public void deviceChannelOffline(String deviceId, String channelId) {
+ deviceChannelMapper.offline(deviceId, channelId);
}
@Override
@@ -162,19 +319,24 @@
public PageInfo queryChannelsByDeviceId(String deviceId, String query, Boolean hasSubChannel, Boolean online, int page, int count) {
// 鑾峰彇鍒版墍鏈夋鍦ㄦ挱鏀剧殑娴�
PageHelper.startPage(page, count);
- List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, null, query, hasSubChannel, online);
+ List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
return new PageInfo<>(all);
}
@Override
+ public List<DeviceChannel> queryChannelsByDeviceIdWithStartAndLimit(String deviceId, String query, Boolean hasSubChannel, Boolean online, int start, int limit) {
+ return deviceChannelMapper.queryChannelsByDeviceIdWithStartAndLimit(deviceId, null, query, hasSubChannel, online, start, limit);
+ }
+
+ @Override
public List<DeviceChannel> queryChannelsByDeviceId(String deviceId) {
- return deviceChannelMapper.queryChannelsByDeviceId(deviceId, null,null, null, null);
+ return deviceChannelMapper.queryChannels(deviceId, null,null, null, null);
}
@Override
public PageInfo<DeviceChannel> querySubChannels(String deviceId, String parentChannelId, String query, Boolean hasSubChannel, String online, int page, int count) {
PageHelper.startPage(page, count);
- List<DeviceChannel> all = deviceChannelMapper.queryChannelsByDeviceId(deviceId, parentChannelId, null, null, null);
+ List<DeviceChannel> all = deviceChannelMapper.queryChannels(deviceId, parentChannelId, null, null, null);
return new PageInfo<>(all);
}
@@ -183,6 +345,11 @@
return deviceChannelMapper.queryChannel(deviceId, channelId);
}
+
+ @Override
+ public int delChannel(String deviceId, String channelId) {
+ return deviceChannelMapper.del(deviceId, channelId);
+ }
/**
* 鑾峰彇澶氫釜璁惧
@@ -250,6 +417,9 @@
}
device.setOnline(1);
logger.info("鏇存柊璁惧鍦ㄧ嚎: " + deviceId);
+ redisCatchStorage.updateDevice(device);
+ List<DeviceChannel> deviceChannelList = deviceChannelMapper.queryOnlineChannelsByDeviceId(deviceId);
+ eventPublisher.catalogEventPublish(null, deviceChannelList, CatalogEvent.ON);
return deviceMapper.update(device) > 0;
}
@@ -265,6 +435,7 @@
Device device = deviceMapper.getDeviceByDeviceId(deviceId);
if (device == null) return false;
device.setOnline(0);
+ redisCatchStorage.updateDevice(device);
return deviceMapper.update(device) > 0;
}
@@ -311,6 +482,9 @@
@Override
public boolean addParentPlatform(ParentPlatform parentPlatform) {
+ if (parentPlatform.getCatalogId() == null) {
+ parentPlatform.setCatalogId(parentPlatform.getServerGBId());
+ }
int result = platformMapper.addParentPlatform(parentPlatform);
return result > 0;
}
@@ -320,6 +494,9 @@
int result = 0;
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();
@@ -339,6 +516,21 @@
// 鏇存柊缂撳瓨
parentPlatformCatch.setParentPlatform(parentPlatform);
redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
+ if (parentPlatform.isEnable()) {
+ // 鍏变韩鎵�鏈夎棰戞祦锛岄渶瑕佸皢鐜版湁瑙嗛娴佹坊鍔犲埌姝ゅ钩鍙�
+ List<GbStream> gbStreams = gbStreamMapper.queryStreamNotInPlatform();
+ if (gbStreams.size() > 0) {
+ for (GbStream gbStream : gbStreams) {
+ gbStream.setCatalogId(parentPlatform.getCatalogId());
+ }
+ if (parentPlatform.isShareAllLiveStream()) {
+ gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId(), parentPlatform.getCatalogId());
+ }else {
+ gbStreamService.delPlatformInfo(parentPlatform.getServerGBId(), gbStreams);
+ }
+ }
+ }
+
return result > 0;
}
@@ -389,10 +581,11 @@
}
@Override
- public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces) {
+ public int updateChannelForGB(String platformId, List<ChannelReduce> channelReduces, String catalogId) {
Map<String, ChannelReduce> deviceAndChannels = new HashMap<>();
for (ChannelReduce channelReduce : channelReduces) {
+ channelReduce.setCatalogId(catalogId);
deviceAndChannels.put(channelReduce.getDeviceId() + "_" + channelReduce.getChannelId(), channelReduce);
}
List<String> deviceAndChannelList = new ArrayList<>(deviceAndChannels.keySet());
@@ -409,6 +602,9 @@
int result = 0;
if (channelReducesToAdd.size() > 0) {
result = platformChannelMapper.addChannels(platformId, channelReducesToAdd);
+ // TODO 鍚庣画缁欏钩鍙板鍔犳帶鍒跺紑鍏充互鎺у埗鏄惁鍝嶅簲鐩綍璁㈤槄
+ List<DeviceChannel> deviceChannelList = getDeviceChannelListByChannelReduceList(channelReducesToAdd, catalogId);
+ eventPublisher.catalogEventPublish(platformId, deviceChannelList, CatalogEvent.ADD);
}
return result;
@@ -419,7 +615,13 @@
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;
}
@@ -427,6 +629,18 @@
public DeviceChannel queryChannelInParentPlatform(String platformId, String channelId) {
DeviceChannel channel = platformChannelMapper.queryChannelInParentPlatform(platformId, channelId);
return channel;
+ }
+
+ @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
@@ -463,7 +677,7 @@
boolean result = false;
streamProxyItem.setStreamType("proxy");
streamProxyItem.setStatus(true);
- String now = this.format.format(new Date(System.currentTimeMillis()));
+ String now = this.format.format(System.currentTimeMillis());
streamProxyItem.setCreateTime(now);
try {
if (gbStreamMapper.add(streamProxyItem)<0 || streamProxyMapper.add(streamProxyItem) < 0) {
@@ -476,6 +690,8 @@
logger.error("鍚戞暟鎹簱娣诲姞娴佷唬鐞嗗け璐ワ細", e);
dataSourceTransactionManager.rollback(transactionStatus);
}
+
+
return result;
}
@@ -576,7 +792,11 @@
streamPushMapper.addAll(streamPushItems);
// TODO 寰呬紭鍖�
for (int i = 0; i < streamPushItems.size(); i++) {
- gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true);
+ int onlineResult = gbStreamMapper.setStatus(streamPushItems.get(i).getApp(), streamPushItems.get(i).getStream(), true);
+ if (onlineResult > 0) {
+ // 鍙戦�佷笂绾块�氱煡
+ eventPublisher.catalogEventPublishForStream(null, streamPushItems.get(i), CatalogEvent.ON);
+ }
}
}
@@ -585,11 +805,30 @@
streamPushMapper.del(streamPushItem.getApp(), streamPushItem.getStream());
streamPushMapper.add(streamPushItem);
gbStreamMapper.setStatus(streamPushItem.getApp(), streamPushItem.getStream(), true);
+
+ if(!StringUtils.isEmpty(streamPushItem.getGbId() )){
+ // 鏌ユ壘寮�鍚簡鍏ㄩ儴鐩存挱娴佸叡浜殑涓婄骇骞冲彴
+ List<ParentPlatform> parentPlatforms = parentPlatformMapper.selectAllAhareAllLiveStream();
+ if (parentPlatforms.size() > 0) {
+ for (ParentPlatform parentPlatform : parentPlatforms) {
+ streamPushItem.setCatalogId(parentPlatform.getCatalogId());
+ streamPushItem.setPlatformId(parentPlatform.getServerGBId());
+ String stream = streamPushItem.getStream();
+ StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream,
+ parentPlatform.getServerGBId());
+ if (streamProxyItems == null) {
+ platformGbStreamMapper.add(streamPushItem);
+ eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), streamPushItem, CatalogEvent.ADD);
+ }
+ }
+ }
+ }
+
}
@Override
- public void removeMedia(String app, String stream) {
- streamPushMapper.del(app, stream);
+ public int removeMedia(String app, String stream) {
+ return streamPushMapper.del(app, stream);
}
@Override
@@ -598,8 +837,8 @@
}
@Override
- public void mediaOutline(String app, String streamId) {
- gbStreamMapper.setStatus(app, streamId, false);
+ public int mediaOutline(String app, String streamId) {
+ return gbStreamMapper.setStatus(app, streamId, false);
}
@Override
@@ -609,7 +848,7 @@
@Override
public void updateMediaServer(MediaServerItem mediaServerItem) {
- String now = this.format.format(new Date(System.currentTimeMillis()));
+ String now = this.format.format(System.currentTimeMillis());
mediaServerItem.setUpdateTime(now);
if (mediaServerMapper.queryOne(mediaServerItem.getId()) != null) {
mediaServerMapper.update(mediaServerItem);
@@ -623,4 +862,199 @@
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) {
+ int result = catalogMapper.add(platformCatalog);
+ if (result > 0) {
+ DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog);
+ eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.ADD);
+ }
+ return result;
+ }
+
+ @Override
+ public PlatformCatalog getCatalog(String id) {
+ return catalogMapper.select(id);
+ }
+
+ @Override
+ public int delCatalog(String id) {
+ PlatformCatalog platformCatalog = catalogMapper.select(id);
+ if (platformCatalog.getChildrenCount() > 0) {
+ List<PlatformCatalog> platformCatalogList = catalogMapper.selectByParentId(platformCatalog.getPlatformId(), platformCatalog.getId());
+ for (PlatformCatalog catalog : platformCatalogList) {
+ if (catalog.getChildrenCount() == 0) {
+ delCatalogExecute(catalog.getId(), catalog.getPlatformId());
+ }else {
+ delCatalog(catalog.getId());
+ }
+ }
+ }
+ return delCatalogExecute(id, platformCatalog.getPlatformId());
+ }
+ private int delCatalogExecute(String id, String platformId) {
+ int delresult = catalogMapper.del(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.delByCatalogId(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(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);
+ }
+
+ @Override
+ public List<PlatformCatalog> queryCatalogInPlatform(String platformId) {
+ return catalogMapper.selectByPlatForm(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);
+ }
+
+ private List<DeviceChannel> getDeviceChannelListByChannelReduceList(List<ChannelReduce> channelReduces, String catalogId) {
+ List<DeviceChannel> deviceChannelList = new ArrayList<>();
+ if (channelReduces.size() > 0){
+ for (ChannelReduce channelReduce : channelReduces) {
+ DeviceChannel deviceChannel = queryChannel(channelReduce.getDeviceId(), channelReduce.getChannelId());
+ deviceChannel.setParental(1);
+ deviceChannel.setParentId(catalogId);
+ deviceChannelList.add(deviceChannel);
+ }
+ }
+ return deviceChannelList;
+ }
+
+ private DeviceChannel getDeviceChannelByCatalog(PlatformCatalog catalog) {
+ ParentPlatform parentPlatByServerGBId = platformMapper.getParentPlatByServerGBId(catalog.getPlatformId());
+ DeviceChannel deviceChannel = new DeviceChannel();
+ deviceChannel.setChannelId(catalog.getId());
+ deviceChannel.setName(catalog.getName());
+ deviceChannel.setLongitude(0.0);
+ deviceChannel.setLatitude(0.0);
+ deviceChannel.setDeviceId(parentPlatByServerGBId.getDeviceGBId());
+ deviceChannel.setManufacture("wvp-pro");
+ deviceChannel.setStatus(1);
+ deviceChannel.setParental(1);
+ deviceChannel.setParentId(catalog.getParentId());
+ deviceChannel.setRegisterWay(1);
+ deviceChannel.setCivilCode(sipConfig.getDomain());
+ deviceChannel.setModel("live");
+ deviceChannel.setOwner("wvp-pro");
+ deviceChannel.setSecrecy("0");
+ 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);
+ }
+
+ @Override
+ public List<ParentPlatform> queryPlatFormListForStreamWithGBId(String app, String stream, List<String> platforms) {
+ return platformGbStreamMapper.queryPlatFormListForGBWithGBId(app, stream, platforms);
+ }
+
+ @Override
+ public GbStream getGbStream(String app, String streamId) {
+ 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);
+ }
}
--
Gitblit v1.8.0