From d6262acf6ab2a5083e62ea98299b378f61cd5421 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 20 四月 2023 16:42:44 +0800
Subject: [PATCH] 更新readme
---
src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java | 46 +++++++++++++++++++++++++---------------------
1 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
index 75b9f59..38cdf7c 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/CatalogDataCatch.java
@@ -4,24 +4,20 @@
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
import com.genersoft.iot.vmp.gb28181.bean.SyncStatus;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import java.time.Instant;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
@Component
public class CatalogDataCatch {
public static Map<String, CatalogData> data = new ConcurrentHashMap<>();
-
- @Autowired
- private DeferredResultHolder deferredResultHolder;
@Autowired
private IVideoManagerStorage storager;
@@ -34,7 +30,7 @@
catalogData.setDevice(device);
catalogData.setSn(sn);
catalogData.setStatus(CatalogData.CatalogDataStatus.ready);
- catalogData.setLastTime(new Date(System.currentTimeMillis()));
+ catalogData.setLastTime(Instant.now());
data.put(device.getDeviceId(), catalogData);
}
}
@@ -46,9 +42,9 @@
catalogData.setSn(sn);
catalogData.setTotal(total);
catalogData.setDevice(device);
- catalogData.setChannelList(Collections.synchronizedList(new ArrayList<>()));
+ catalogData.setChannelList(deviceChannelList);
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
- catalogData.setLastTime(new Date(System.currentTimeMillis()));
+ catalogData.setLastTime(Instant.now());
data.put(deviceId, catalogData);
}else {
// 鍚屼竴涓澶囩殑閫氶亾鍚屾璇锋眰鍙�冭檻涓�涓紝鍏朵粬鐨勭洿鎺ュ拷鐣�
@@ -59,7 +55,7 @@
catalogData.setDevice(device);
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng);
catalogData.getChannelList().addAll(deviceChannelList);
- catalogData.setLastTime(new Date(System.currentTimeMillis()));
+ catalogData.setLastTime(Instant.now());
}
}
@@ -88,6 +84,11 @@
syncStatus.setCurrent(catalogData.getChannelList().size());
syncStatus.setTotal(catalogData.getTotal());
syncStatus.setErrorMsg(catalogData.getErrorMsg());
+ if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) {
+ syncStatus.setSyncIng(false);
+ }else {
+ syncStatus.setSyncIng(true);
+ }
return syncStatus;
}
@@ -102,21 +103,24 @@
@Scheduled(fixedRate = 5 * 1000) //姣�5绉掓墽琛屼竴娆�, 鍙戠幇鏁版嵁5绉掓湭鏇存柊鍒欑Щ闄ゆ暟鎹苟璁や负鏁版嵁鎺ユ敹瓒呮椂
private void timerTask(){
Set<String> keys = data.keySet();
- Calendar calendarBefore5S = Calendar.getInstance();
- calendarBefore5S.setTime(new Date());
- calendarBefore5S.set(Calendar.SECOND, calendarBefore5S.get(Calendar.SECOND) - 5);
- Calendar calendarBefore30S = Calendar.getInstance();
- calendarBefore30S.setTime(new Date());
- calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30);
+ Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5));
+ Instant instantBefore30S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(30));
+
for (String deviceId : keys) {
CatalogData catalogData = data.get(deviceId);
- if ( catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 瓒呰繃浜旂鏀朵笉鍒版秷鎭换鍔¤秴鏃讹紝 鍙洿鏂拌繖涓�閮ㄥ垎鏁版嵁
+ if ( catalogData.getLastTime().isBefore(instantBefore5S)) {
+ // 瓒呰繃浜旂鏀朵笉鍒版秷鎭换鍔¤秴鏃讹紝 鍙洿鏂拌繖涓�閮ㄥ垎鏁版嵁, 鏀跺埌鏁版嵁涓庡0鏄庣殑鎬绘暟涓�鑷达紝鍒欓噸缃�氶亾鏁版嵁锛屾暟鎹笉鍏ㄥ垯鍙鏀跺埌鐨勬暟鎹仛鏇存柊鎿嶄綔
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) {
- storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
+ if (catalogData.getTotal() == catalogData.getChannelList().size()) {
+ storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
+ }else {
+ storager.updateChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList());
+ }
+ String errorMsg = "鏇存柊鎴愬姛锛屽叡" + catalogData.getTotal() + "鏉★紝宸叉洿鏂�" + catalogData.getChannelList().size() + "鏉�";
+ catalogData.setErrorMsg(errorMsg);
if (catalogData.getTotal() != catalogData.getChannelList().size()) {
- String errorMsg = "鏇存柊鎴愬姛锛屽叡" + catalogData.getTotal() + "鏉★紝宸叉洿鏂�" + catalogData.getChannelList().size() + "鏉�";
- catalogData.setErrorMsg(errorMsg);
+
}
}else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) {
String errorMsg = "鍚屾澶辫触锛岀瓑寰呭洖澶嶈秴鏃�";
@@ -124,7 +128,7 @@
}
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
}
- if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 瓒呰繃涓夊崄绉掞紝濡傛灉鏍囪涓篹nd鍒欏垹闄�
+ if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().isBefore(instantBefore30S)) { // 瓒呰繃涓夊崄绉掞紝濡傛灉鏍囪涓篹nd鍒欏垹闄�
data.remove(deviceId);
}
}
--
Gitblit v1.8.0