From 97698ee716daa841bca229596651f06513d9fdda Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 01 三月 2022 17:37:19 +0800
Subject: [PATCH] Merge pull request #346 from TristingChen/log-optimization
---
src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java | 68 +++++++++++++++++++++++++++------
1 files changed, 55 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
index ff31d8a..8a015d9 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamPushServiceImpl.java
@@ -28,6 +28,7 @@
import org.springframework.util.StringUtils;
import java.util.*;
+import java.util.stream.Collectors;
@Service
public class StreamPushServiceImpl implements IStreamPushService {
@@ -359,22 +360,63 @@
}
@Override
- public void batchAddForUpload(String platformId, String catalogId, List<StreamPushItem> streamPushItems) {
+ public void batchAddForUpload(List<StreamPushItem> streamPushItems, Map<String, List<String[]>> streamPushItemsForAll ) {
+ // 瀛樺偍鏁版嵁鍒皊tream_push琛�
streamPushMapper.addAll(streamPushItems);
- gbStreamMapper.batchAdd(streamPushItems);
- if (platformId != null) {
- ParentPlatform platform = parentPlatformMapper.getParentPlatByServerGBId(platformId);
- if (platform != null) {
- if (catalogId == null) {
- catalogId = platform.getCatalogId();
- }else {
- PlatformCatalog catalog = platformCatalogMapper.select(catalogId);
- if (catalog == null) {
- return;
+ List<StreamPushItem> streamPushItemForGbStream = streamPushItems.stream()
+ .filter(streamPushItem-> streamPushItem.getId() != null)
+ .collect(Collectors.toList());
+ // 瀛樺偍鏁版嵁鍒癵b_stream琛紝 id浼氳繑鍥炲埌streamPushItemForGbStream閲�
+ if (streamPushItemForGbStream.size() > 0) {
+ gbStreamMapper.batchAdd(streamPushItemForGbStream);
+ }
+ // 鍘婚櫎娌℃湁ID涔熷氨鏄病鏈夊瓨鍌ㄥ埌鏁版嵁搴撶殑鏁版嵁
+ List<StreamPushItem> streamPushItemsForPlatform = streamPushItemForGbStream.stream()
+ .filter(streamPushItem-> streamPushItem.getGbStreamId() != null)
+ .collect(Collectors.toList());
+
+ if (streamPushItemsForPlatform.size() > 0) {
+ List<StreamPushItem> streamPushItemListFroPlatform = new ArrayList<>();
+ Map<String, List<StreamPushItem>> platformForEvent = new HashMap<>();
+ // 閬嶅巻瀛樺偍缁撴灉锛屾煡鎵綼pp+Stream->platformId+catalogId鐨勫搴斿叧绯伙紝鐒跺悗鎵ц鎵归噺鍐欏叆
+ for (StreamPushItem streamPushItem : streamPushItemsForPlatform) {
+ List<String[]> platFormInfoList = streamPushItemsForAll.get(streamPushItem.getApp() + streamPushItem.getStream());
+ if (platFormInfoList != null) {
+ if (platFormInfoList.size() > 0) {
+ for (String[] platFormInfoArray : platFormInfoList) {
+ StreamPushItem streamPushItemForPlatform = new StreamPushItem();
+ streamPushItemForPlatform.setGbStreamId(streamPushItem.getGbStreamId());
+ if (platFormInfoArray.length > 0) {
+ // 鏁扮粍 platFormInfoArray 0 涓哄钩鍙癐D銆� 1涓虹洰褰旾D
+ streamPushItemForPlatform.setPlatformId(platFormInfoArray[0]);
+
+ List<StreamPushItem> streamPushItemsInPlatform = platformForEvent.get(streamPushItem.getPlatformId());
+ if (streamPushItemsInPlatform == null) {
+ streamPushItemsInPlatform = new ArrayList<>();
+ platformForEvent.put(platFormInfoArray[0], streamPushItemsInPlatform);
+ }
+ // 涓哄彂閫侀�氱煡鏁寸悊鏁版嵁
+ streamPushItemForPlatform.setApp(streamPushItem.getApp());
+ streamPushItemForPlatform.setStream(streamPushItem.getStream());
+ streamPushItemForPlatform.setGbId(streamPushItem.getGbId());
+ streamPushItemsInPlatform.add(streamPushItemForPlatform);
+ }
+ if (platFormInfoArray.length > 1) {
+ streamPushItemForPlatform.setCatalogId(platFormInfoArray[1]);
+ }
+ streamPushItemListFroPlatform.add(streamPushItemForPlatform);
+
+
+ }
}
+
}
- platformGbStreamMapper.batchAdd(platformId, catalogId, streamPushItems);
- eventPublisher.catalogEventPublishForStream(platformId, streamPushItems.toArray(new GbStream[0]), CatalogEvent.ADD);
+ }
+ platformGbStreamMapper.batchAdd(streamPushItemListFroPlatform);
+ // 鍙戦�侀�氱煡
+ for (String platformId : platformForEvent.keySet()) {
+ eventPublisher.catalogEventPublishForStream(
+ platformId, platformForEvent.get(platformId).toArray(new GbStream[0]), CatalogEvent.ADD);
}
}
}
--
Gitblit v1.8.0