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 | 213 +++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 183 insertions(+), 30 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 dba268d..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,6 +1,9 @@
package com.genersoft.iot.vmp.storager.impl;
+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;
@@ -24,21 +27,24 @@
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+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;
@@ -137,6 +143,7 @@
return deviceMapper.add(device) > 0;
}else {
redisCatchStorage.updateDevice(device);
+
return deviceMapper.update(device) > 0;
}
@@ -227,21 +234,41 @@
@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 && deviceChannelList.size() > 0) {
- if (deviceChannelList.size() > limitCount) {
- for (int i = 0; i < deviceChannelList.size(); i += limitCount) {
+ 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 > deviceChannelList.size()) {
- toIndex = deviceChannelList.size();
+ if (i + limitCount > channels.size()) {
+ toIndex = channels.size();
}
- result = result || deviceChannelMapper.batchAdd(deviceChannelList.subList(i, toIndex)) < 0;
+ result = result || deviceChannelMapper.batchAdd(channels.subList(i, toIndex)) < 0;
}
}else {
- result = result || deviceChannelMapper.batchAdd(deviceChannelList) < 0;
+ result = result || deviceChannelMapper.batchAdd(channels) < 0;
}
}
if (result) {
@@ -391,6 +418,8 @@
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;
}
@@ -497,7 +526,7 @@
if (parentPlatform.isShareAllLiveStream()) {
gbStreamService.addPlatformInfo(gbStreams, parentPlatform.getServerGBId(), parentPlatform.getCatalogId());
}else {
- gbStreamService.delPlatformInfo(gbStreams);
+ gbStreamService.delPlatformInfo(parentPlatform.getServerGBId(), gbStreams);
}
}
}
@@ -573,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;
@@ -583,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;
}
@@ -601,7 +639,7 @@
@Override
public List<PlatformCatalog> queryStreamInParentPlatformAndCatalog(String platformId, String catalogId) {
- List<PlatformCatalog> catalogs = platformGbStreamMapper.queryChannelInParentPlatformAndCatalogForCatlog(platformId, catalogId);
+ List<PlatformCatalog> catalogs = platformGbStreamMapper.queryChannelInParentPlatformAndCatalogForCatalog(platformId, catalogId);
return catalogs;
}
@@ -722,7 +760,7 @@
* @return
*/
@Override
- public List<GbStream> queryStreamInParentPlatform(String platformId, String gbId) {
+ public GbStream queryStreamInParentPlatform(String platformId, String gbId) {
return gbStreamMapper.queryStreamInPlatform(platformId, gbId);
}
@@ -754,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);
+ }
}
}
@@ -763,6 +805,7 @@
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();
@@ -771,9 +814,11 @@
streamPushItem.setCatalogId(parentPlatform.getCatalogId());
streamPushItem.setPlatformId(parentPlatform.getServerGBId());
String stream = streamPushItem.getStream();
- StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream, parentPlatform.getServerGBId());
+ StreamProxyItem streamProxyItems = platformGbStreamMapper.selectOne(streamPushItem.getApp(), stream,
+ parentPlatform.getServerGBId());
if (streamProxyItems == null) {
platformGbStreamMapper.add(streamPushItem);
+ eventPublisher.catalogEventPublishForStream(parentPlatform.getServerGBId(), streamPushItem, CatalogEvent.ADD);
}
}
}
@@ -841,7 +886,12 @@
@Override
public int addCatalog(PlatformCatalog platformCatalog) {
- return catalogMapper.add(platformCatalog);
+ int result = catalogMapper.add(platformCatalog);
+ if (result > 0) {
+ DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog);
+ eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.ADD);
+ }
+ return result;
}
@Override
@@ -856,23 +906,56 @@
List<PlatformCatalog> platformCatalogList = catalogMapper.selectByParentId(platformCatalog.getPlatformId(), platformCatalog.getId());
for (PlatformCatalog catalog : platformCatalogList) {
if (catalog.getChildrenCount() == 0) {
- catalogMapper.del(catalog.getId());
- platformGbStreamMapper.delByCatalogId(catalog.getId());
- platformChannelMapper.delByCatalogId(catalog.getId());
+ delCatalogExecute(catalog.getId(), catalog.getPlatformId());
}else {
delCatalog(catalog.getId());
}
}
}
- int delresult = catalogMapper.del(id);
- int delStreamresult = platformGbStreamMapper.delByCatalogId(id);
- int delChanneresult = platformChannelMapper.delByCatalogId(id);
- return delresult + delChanneresult + delStreamresult;
+ 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) {
- return catalogMapper.update(platformCatalog);
+ int result = catalogMapper.update(platformCatalog);
+ if (result > 0) {
+ DeviceChannel deviceChannel = getDeviceChannelByCatalog(platformCatalog);
+ eventPublisher.catalogEventPublish(platformCatalog.getPlatformId(), deviceChannel, CatalogEvent.UPDATE);
+ }
+ return result;
}
@Override
@@ -888,11 +971,17 @@
@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());
}
}
@@ -904,4 +993,68 @@
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