From 8aa0bdf539582b9d710503121d911bb166ca7c8e Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 06 七月 2022 09:44:37 +0800
Subject: [PATCH] 数据库优化

---
 src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java |   47 ++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 40 insertions(+), 7 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 eea07e9..9a5be6e 100644
--- a/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStorageImpl.java
@@ -25,11 +25,13 @@
 import org.springframework.transaction.TransactionDefinition;
 import org.springframework.transaction.TransactionStatus;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
 import org.springframework.util.StringUtils;
 
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 
-/**    
+/**
  * 瑙嗛璁惧鏁版嵁瀛樺偍-jdbc瀹炵幇
  * swwheihei
  * 2020骞�5鏈�6鏃� 涓嬪崍2:31:42
@@ -194,20 +196,30 @@
 
 	@Override
 	public boolean resetChannels(String deviceId, List<DeviceChannel> deviceChannelList) {
-		if (deviceChannelList == null) {
+		if (CollectionUtils.isEmpty(deviceChannelList)) {
 			return false;
+		}
+		List<DeviceChannel> allChannelInPlay = deviceChannelMapper.getAllChannelInPlay();
+		Map<String,DeviceChannel> allChannelMapInPlay = new ConcurrentHashMap<>();
+		if (allChannelInPlay.size() > 0) {
+			for (DeviceChannel deviceChannel : allChannelInPlay) {
+				allChannelMapInPlay.put(deviceChannel.getChannelId(), deviceChannel);
+			}
 		}
 		TransactionStatus transactionStatus = dataSourceTransactionManager.getTransaction(transactionDefinition);
 		// 鏁版嵁鍘婚噸
 		List<DeviceChannel> channels = new ArrayList<>();
 		StringBuilder stringBuilder = new StringBuilder();
 		Map<String, Integer> subContMap = new HashMap<>();
-		if (deviceChannelList != null && deviceChannelList.size() > 1) {
+		if (deviceChannelList.size() > 1) {
 			// 鏁版嵁鍘婚噸
 			Set<String> gbIdSet = new HashSet<>();
 			for (DeviceChannel deviceChannel : deviceChannelList) {
 				if (!gbIdSet.contains(deviceChannel.getChannelId())) {
 					gbIdSet.add(deviceChannel.getChannelId());
+					if (allChannelMapInPlay.containsKey(deviceChannel.getChannelId())) {
+						deviceChannel.setStreamId(allChannelMapInPlay.get(deviceChannel.getChannelId()).getStreamId());
+					}
 					channels.add(deviceChannel);
 					if (!StringUtils.isEmpty(deviceChannel.getParentId())) {
 						if (subContMap.get(deviceChannel.getParentId()) == null) {
@@ -234,6 +246,10 @@
 		}
 		if (stringBuilder.length() > 0) {
 			logger.info("[鐩綍鏌ヨ]鏀跺埌鐨勬暟鎹瓨鍦ㄩ噸澶嶏細 {}" , stringBuilder);
+		}
+		if(CollectionUtils.isEmpty(channels)){
+			logger.info("閫氶亾閲嶈锛屾暟鎹负绌�={}" , deviceChannelList);
+			return false;
 		}
 		try {
 			int cleanChannelsResult = deviceChannelMapper.cleanChannelsNotInList(deviceId, channels);
@@ -304,6 +320,9 @@
 		List<DeviceChannel> all;
 		if (catalogUnderDevice != null && catalogUnderDevice) {
 			all = deviceChannelMapper.queryChannels(deviceId, deviceId, query, hasSubChannel, online);
+			// 娴峰悍璁惧鐨刾arentId鏄疭IP id
+			List<DeviceChannel> deviceChannels = deviceChannelMapper.queryChannels(deviceId, sipConfig.getId(), query, hasSubChannel, online);
+			all.addAll(deviceChannels);
 		}else {
 			all = deviceChannelMapper.queryChannels(deviceId, null, query, hasSubChannel, online);
 		}
@@ -453,6 +472,9 @@
 	 */
 	@Override
 	public synchronized boolean insertMobilePosition(MobilePosition mobilePosition) {
+		if (mobilePosition.getDeviceId().equals(mobilePosition.getChannelId())) {
+			mobilePosition.setChannelId(null);
+		}
 		return deviceMobilePositionMapper.insertNewPosition(mobilePosition) > 0;
 	}
 
@@ -692,7 +714,6 @@
 		streamProxyItem.setStatus(true);
 		String now = DateUtil.getNow();
 		streamProxyItem.setCreateTime(now);
-		streamProxyItem.setCreateStamp(System.currentTimeMillis());
 		try {
 			if (streamProxyMapper.add(streamProxyItem) > 0) {
 				if (!StringUtils.isEmpty(streamProxyItem.getGbId())) {
@@ -866,6 +887,11 @@
 	}
 
 	@Override
+	public StreamPushItem getMedia(String app, String stream) {
+		return streamPushMapper.selectOne(app, stream);
+	}
+
+	@Override
 	public void clearMediaList() {
 		streamPushMapper.clear();
 	}
@@ -982,7 +1008,7 @@
 
 	@Override
 	public int setDefaultCatalog(String platformId, String catalogId) {
-		return platformMapper.setDefaultCatalog(platformId, catalogId);
+		return platformMapper.setDefaultCatalog(platformId, catalogId, DateUtil.getNow());
 	}
 
 	@Override
@@ -1095,7 +1121,14 @@
 	}
 
 	@Override
-	public void updateChannelPotion(String deviceId, String channelId, double longitude, double latitude) {
-		deviceChannelMapper.updatePotion(deviceId, channelId, longitude, latitude);
+	public void updateChannelPosition(DeviceChannel deviceChannel) {
+		if (deviceChannel.getChannelId().equals(deviceChannel.getDeviceId())) {
+			deviceChannel.setChannelId(null);
+		}
+		if (deviceChannel.getGpsTime() == null) {
+			deviceChannel.setGpsTime(DateUtil.getNow());
+		}
+
+		deviceChannelMapper.updatePosition(deviceChannel);
 	}
 }

--
Gitblit v1.8.0