From dc1d9646a97ac07d20a911c0daf5bae361964717 Mon Sep 17 00:00:00 2001
From: Lawrence <1934378145@qq.com>
Date: 星期一, 11 一月 2021 20:56:25 +0800
Subject: [PATCH] 优化录像列表获取算法
---
.gitignore | 4 ++--
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java | 38 ++++++++++++++------------------------
2 files changed, 16 insertions(+), 26 deletions(-)
diff --git a/.gitignore b/.gitignore
index 0c96aaf..54054a0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,7 +9,7 @@
# Mobile Tools for Java (J2ME)
.mtj.tmp/
-
+src/main/resources/application-*.yml
# Package Files #
#*.jar
*.war
@@ -18,7 +18,7 @@
*.zip
*.tar.gz
*.rar
-
+*.iml
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/.idea/*
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
index 3ed22b2..c5ae4f5 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
@@ -342,6 +342,7 @@
try {
// 鍥炲200 OK
responseAck(evt);
+ String seqNo = String.valueOf(System.currentTimeMillis());
RecordInfo recordInfo = new RecordInfo();
Element rootElement = getRootElement(evt);
Element deviceIdElement = rootElement.element("DeviceID");
@@ -396,31 +397,21 @@
if (recordInfo.getSumNum() > 0 && recordList.size() > 0 && recordList.size() < recordInfo.getSumNum()) {
// 涓洪槻姝㈣繛缁姹傝璁惧鐨勫綍鍍忔暟鎹紝杩斿洖鏁版嵁閿欎贡锛岀壒澧炲姞sn杩涜鍖哄垎
String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn;
- // TODO 鏆傛椂鐩存帴鎿嶄綔redis瀛樺偍锛屽悗缁皝瑁呬笓鐢ㄧ紦瀛樻帴鍙o紝鏀逛负鏈湴鍐呭瓨缂撳瓨
- if (redis.hasKey(cacheKey)) {
- List<RecordItem> previousList = (List<RecordItem>) redis.get(cacheKey);
- if (previousList != null && previousList.size() > 0) {
- recordList.addAll(previousList);
- }
- // 鏈垎鏀〃绀哄綍鍍忓垪琛ㄨ鎷嗗寘锛屼笖鍔犱笂涔嬪墠鐨勬暟鎹繕鏄笉澶�,淇濆瓨缂撳瓨杩斿洖锛岀瓑寰呬笅涓寘鍐嶅鐞�
- if (recordList.size() < recordInfo.getSumNum()) {
- logger.info("宸茶幏鍙�" + recordList.size() + "椤瑰綍鍍忔暟鎹紝鍏�" + recordInfo.getSumNum() + "椤�");
- redis.set(cacheKey, recordList, 90);
- return;
- } else {
- // 鏈垎鏀〃绀哄綍鍍忚鎷嗗寘锛屼絾鍔犱笂涔嬪墠鐨勬暟鎹瓒冲锛岃繑鍥炲搷搴�
- // 鍥犺澶囧績璺虫湁鐩戝惉redis杩囨湡鏈哄埗锛屼负鎻愰珮鎬ц兘锛屾澶勬墜鍔ㄥ垹闄�
- logger.info("褰曞儚鏁版嵁宸插叏閮ㄨ幏鍙�");
- redis.del(cacheKey);
- }
- } else {
- // 鏈垎鏀湁涓ょ鍙兘锛�1銆佸綍鍍忓垪琛ㄨ鎷嗗寘锛屼笖鏄涓�涓寘,鐩存帴淇濆瓨缂撳瓨杩斿洖锛岀瓑寰呬笅涓寘鍐嶅鐞�
- // 2銆佷箣鍓嶆湁鍖咃紝浣嗚秴鏃舵竻绌轰簡锛岄偅涔堣繖娆n鎵规鐨勫搷搴旀暟鎹凡缁忎笉瀹屾暣锛岀瓑寰呰繃鏈熸椂闂村悗redis鑷姩娓呯┖鏁版嵁
- logger.info("宸茶幏鍙�" + recordList.size() + "椤瑰綍鍍忔暟鎹紝鍏�" + recordInfo.getSumNum() + "椤�");
- logger.info("绛夊緟鍚庣画鐨勫寘...");
- redis.set(cacheKey, recordList, 90);
+ redis.set(cacheKey + "_" + seqNo, recordList, 90);
+ List<Object> cacheKeys = redis.scan(cacheKey + "_*");
+ List<RecordItem> totalRecordList = new ArrayList<RecordItem>();
+ for (int i = 0; i < cacheKeys.size(); i++) {
+ totalRecordList.addAll((List<RecordItem>) redis.get(cacheKeys.get(i).toString()));
+ }
+ if (totalRecordList.size() < recordInfo.getSumNum()) {
+ logger.info("宸茶幏鍙�" + totalRecordList.size() + "椤瑰綍鍍忔暟鎹紝鍏�" + recordInfo.getSumNum() + "椤�");
return;
+ }
+ logger.info("褰曞儚鏁版嵁宸插叏閮ㄨ幏鍙栵紝鍏�" + recordInfo.getSumNum() + "椤�");
+ recordInfo.setRecordList(totalRecordList);
+ for (int i = 0; i < cacheKeys.size(); i++) {
+ redis.del(cacheKeys.get(i).toString());
}
}
// 鑷劧椤哄簭鎺掑簭, 鍏冪礌杩涜鍗囧簭鎺掑垪
@@ -460,7 +451,6 @@
cmder.streamByeCmd(streamInfo.getStreamId());
}
}
-
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
e.printStackTrace();
}
--
Gitblit v1.8.0