From bfcb4d23351c5eb8db753ed8670a0d16601c1992 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 13 一月 2022 16:39:32 +0800
Subject: [PATCH] 合并主分支

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java |   72 ++++++++++++++++++++++++-----------
 1 files changed, 49 insertions(+), 23 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 7f0efcd..cf3f549 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
@@ -6,6 +6,7 @@
 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.*;
@@ -23,10 +24,7 @@
 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瀹炵幇
@@ -226,21 +224,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) {
+			int limitCount = 1;
+			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) {
@@ -486,18 +504,21 @@
 		// 鏇存柊缂撳瓨
 		parentPlatformCatch.setParentPlatform(parentPlatform);
 		redisCatchStorage.updatePlatformCatchInfo(parentPlatformCatch);
-		// 鍏变韩鎵�鏈夎棰戞祦锛岄渶瑕佸皢鐜版湁瑙嗛娴佹坊鍔犲埌姝ゅ钩鍙�
-		List<GbStream> gbStreams = gbStreamMapper.selectAll();
-		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(gbStreams);
+		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(gbStreams);
+				}
 			}
 		}
+
 		return result > 0;
 	}
 
@@ -895,4 +916,9 @@
 		}
 		return 0;
 	}
+
+	@Override
+	public int updateStreamGPS(List<GPSMsgInfo> gpsMsgInfos) {
+		return gbStreamMapper.updateStreamGPS(gpsMsgInfos);
+	}
 }

--
Gitblit v1.8.0