From 764d04b497356ba6bcbb75fd42b51eca750f7223 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 29 五月 2024 15:02:51 +0800
Subject: [PATCH] 调整上级观看消息的发送

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java |   46 ++++++++++++++++++++++++++--------------------
 1 files changed, 26 insertions(+), 20 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
index 7b03e2a..b1eef31 100755
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -1,5 +1,6 @@
 package com.genersoft.iot.vmp.storager.impl;
 
+import com.baomidou.dynamic.datasource.annotation.DS;
 import com.genersoft.iot.vmp.conf.SipConfig;
 import com.genersoft.iot.vmp.conf.UserSetting;
 import com.genersoft.iot.vmp.gb28181.bean.*;
@@ -16,7 +17,6 @@
 import com.genersoft.iot.vmp.web.gb28181.dto.DeviceChannelExtend;
 import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.PageInfo;
-import com.sun.org.apache.xml.internal.resolver.Catalog;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +38,7 @@
  */
 @SuppressWarnings("rawtypes")
 @Component
+@DS("master")
 public class VideoManagerStorageImpl implements IVideoManagerStorage {
 
 	private final Logger logger = LoggerFactory.getLogger(VideoManagerStorageImpl.class);
@@ -74,7 +75,7 @@
     private PlatformChannelMapper platformChannelMapper;
 
 	@Autowired
-    private PlatformCatalogMapper platformCatalogMapper;
+	private PlatformCatalogMapper platformCatalogMapper;
 
 	@Autowired
     private StreamProxyMapper streamProxyMapper;
@@ -123,6 +124,7 @@
 
 		List<DeviceChannel> updateChannels = new ArrayList<>();
 		List<DeviceChannel> addChannels = new ArrayList<>();
+		List<DeviceChannel> deleteChannels = new ArrayList<>();
 		StringBuilder stringBuilder = new StringBuilder();
 		Map<String, Integer> subContMap = new HashMap<>();
 
@@ -136,7 +138,7 @@
 			gbIdSet.add(deviceChannel.getChannelId());
 			if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
 				deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
-				deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
+				deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).getHasAudio());
 				if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){
 					List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId());
 					if (!CollectionUtils.isEmpty(strings)){
@@ -153,6 +155,7 @@
 				deviceChannel.setUpdateTime(DateUtil.getNow());
 				addChannels.add(deviceChannel);
 			}
+			allChannelMap.remove(deviceChannel.getChannelId());
 			channels.add(deviceChannel);
 			if (!ObjectUtils.isEmpty(deviceChannel.getParentId())) {
 				if (subContMap.get(deviceChannel.getParentId()) == null) {
@@ -163,7 +166,8 @@
 				}
 			}
 		}
-		if (channels.size() > 0) {
+		deleteChannels.addAll(allChannelMap.values());
+		if (!channels.isEmpty()) {
 			for (DeviceChannel channel : channels) {
 				if (subContMap.get(channel.getChannelId()) != null){
 					Integer count = subContMap.get(channel.getChannelId());
@@ -184,20 +188,8 @@
 		}
 		try {
 			int limitCount = 50;
-			int cleanChannelsResult = 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();
-					}
-					cleanChannelsResult += this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels.subList(i, toIndex));
-				}
-			} else {
-				cleanChannelsResult = this.deviceChannelMapper.cleanChannelsNotInList(deviceId, channels);
-			}
-			boolean result = cleanChannelsResult < 0;
-			if (!result && addChannels.size() > 0) {
+			boolean result = false;
+			if (!result && !addChannels.isEmpty()) {
 				if (addChannels.size() > limitCount) {
 					for (int i = 0; i < addChannels.size(); i += limitCount) {
 						int toIndex = i + limitCount;
@@ -210,7 +202,7 @@
 					result = result || deviceChannelMapper.batchAdd(addChannels) < 0;
 				}
 			}
-			if (!result && updateChannels.size() > 0) {
+			if (!result && !updateChannels.isEmpty()) {
 				if (updateChannels.size() > limitCount) {
 					for (int i = 0; i < updateChannels.size(); i += limitCount) {
 						int toIndex = i + limitCount;
@@ -221,6 +213,20 @@
 					}
 				}else {
 					result = result || deviceChannelMapper.batchUpdate(updateChannels) < 0;
+				}
+			}
+			if (!result && !deleteChannels.isEmpty()) {
+				System.out.println("鍒犻櫎锛� " + deleteChannels.size());
+				if (deleteChannels.size() > limitCount) {
+					for (int i = 0; i < deleteChannels.size(); i += limitCount) {
+						int toIndex = i + limitCount;
+						if (i + limitCount > deleteChannels.size()) {
+							toIndex = deleteChannels.size();
+						}
+						result = result || deviceChannelMapper.batchDel(deleteChannels.subList(i, toIndex)) < 0;
+					}
+				}else {
+					result = result || deviceChannelMapper.batchDel(deleteChannels) < 0;
 				}
 			}
 
@@ -268,7 +274,7 @@
 					deviceChannel.setUpdateTime(DateUtil.getNow());
 					if (allChannelMap.containsKey(deviceChannel.getChannelId())) {
 						deviceChannel.setStreamId(allChannelMap.get(deviceChannel.getChannelId()).getStreamId());
-						deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).isHasAudio());
+						deviceChannel.setHasAudio(allChannelMap.get(deviceChannel.getChannelId()).getHasAudio());
 						if (allChannelMap.get(deviceChannel.getChannelId()).isStatus() !=deviceChannel.isStatus()){
 							List<String> strings = platformChannelMapper.queryParentPlatformByChannelId(deviceChannel.getChannelId());
 							if (!CollectionUtils.isEmpty(strings)){

--
Gitblit v1.8.0