mirror of
https://gitee.com/pan648540858/wvp-GB28181-pro.git
synced 2026-05-24 14:07:50 +08:00
为目录同步增加首个消息等待时长,默认两分钟,兼容下级数据量大,需要长时间后才能返回的情况
This commit is contained in:
parent
a18635aae6
commit
79e7782700
@ -15,6 +15,7 @@ import com.genersoft.iot.vmp.utils.DateUtil;
|
|||||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||||
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageHelper;
|
||||||
import com.github.pagehelper.PageInfo;
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -30,10 +31,9 @@ import java.util.*;
|
|||||||
* 区域管理类
|
* 区域管理类
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
|
@Slf4j
|
||||||
public class RegionServiceImpl implements IRegionService {
|
public class RegionServiceImpl implements IRegionService {
|
||||||
|
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(RegionServiceImpl.class);
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RegionMapper regionMapper;
|
private RegionMapper regionMapper;
|
||||||
|
|
||||||
|
|||||||
@ -221,13 +221,22 @@ public class CatalogDataManager implements CommandLineRunner {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Set<String> keys = dataMap.keySet();
|
Set<String> keys = dataMap.keySet();
|
||||||
|
// 消息间等待间隔最大五秒
|
||||||
Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5));
|
Instant instantBefore5S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(5));
|
||||||
|
// 消息接收完毕,等待30秒后移除数据
|
||||||
Instant instantBefore30S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(30));
|
Instant instantBefore30S = Instant.now().minusMillis(TimeUnit.SECONDS.toMillis(30));
|
||||||
|
// 初次等待的时间长度,兼容部分下级平台发送初次数据很慢的情况
|
||||||
|
Instant instantBefore2M = Instant.now().minusMillis(TimeUnit.MINUTES.toMillis(2));
|
||||||
for (String dataKey : keys) {
|
for (String dataKey : keys) {
|
||||||
CatalogData catalogData = dataMap.get(dataKey);
|
CatalogData catalogData = dataMap.get(dataKey);
|
||||||
if ( catalogData.getTime().isBefore(instantBefore5S)) {
|
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) {
|
||||||
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) {
|
if ( catalogData.getTime().isBefore(instantBefore2M)) {
|
||||||
|
String errorMsg = "同步失败,等待回复超时";
|
||||||
|
catalogData.setErrorMsg(errorMsg);
|
||||||
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
|
||||||
|
}
|
||||||
|
}else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) {
|
||||||
|
if ( catalogData.getTime().isBefore(instantBefore5S)) {
|
||||||
String deviceId = catalogData.getDevice().getDeviceId();
|
String deviceId = catalogData.getDevice().getDeviceId();
|
||||||
int sn = catalogData.getSn();
|
int sn = catalogData.getSn();
|
||||||
List<DeviceChannel> deviceChannelList = getDeviceChannelList(deviceId, sn);
|
List<DeviceChannel> deviceChannelList = getDeviceChannelList(deviceId, sn);
|
||||||
@ -251,30 +260,27 @@ public class CatalogDataManager implements CommandLineRunner {
|
|||||||
String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + deviceChannelList.size() + "条";
|
String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + deviceChannelList.size() + "条";
|
||||||
catalogData.setErrorMsg(errorMsg);
|
catalogData.setErrorMsg(errorMsg);
|
||||||
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end);
|
||||||
}else if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready)) {
|
|
||||||
String errorMsg = "同步失败,等待回复超时";
|
|
||||||
catalogData.setErrorMsg(errorMsg);
|
|
||||||
}
|
}
|
||||||
}
|
}else {
|
||||||
if ((catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.ready))
|
if (catalogData.getTime().isBefore(instantBefore30S)) {
|
||||||
&& catalogData.getTime().isBefore(instantBefore30S)) { // 超过三十秒,如果标记为end则删除
|
dataMap.remove(dataKey);
|
||||||
dataMap.remove(dataKey);
|
Set<String> redisKeysForChannel = catalogData.getRedisKeysForChannel();
|
||||||
Set<String> redisKeysForChannel = catalogData.getRedisKeysForChannel();
|
if (redisKeysForChannel != null && !redisKeysForChannel.isEmpty()) {
|
||||||
if (redisKeysForChannel != null && !redisKeysForChannel.isEmpty()) {
|
for (String deleteKey : redisKeysForChannel) {
|
||||||
for (String deleteKey : redisKeysForChannel) {
|
redisTemplate.opsForHash().delete(key, deleteKey);
|
||||||
redisTemplate.opsForHash().delete(key, deleteKey);
|
}
|
||||||
}
|
}
|
||||||
}
|
Set<String> redisKeysForRegion = catalogData.getRedisKeysForRegion();
|
||||||
Set<String> redisKeysForRegion = catalogData.getRedisKeysForRegion();
|
if (redisKeysForRegion != null && !redisKeysForRegion.isEmpty()) {
|
||||||
if (redisKeysForRegion != null && !redisKeysForRegion.isEmpty()) {
|
for (String deleteKey : redisKeysForRegion) {
|
||||||
for (String deleteKey : redisKeysForRegion) {
|
redisTemplate.opsForHash().delete(key, deleteKey);
|
||||||
redisTemplate.opsForHash().delete(key, deleteKey);
|
}
|
||||||
}
|
}
|
||||||
}
|
Set<String> redisKeysForGroup = catalogData.getRedisKeysForGroup();
|
||||||
Set<String> redisKeysForGroup = catalogData.getRedisKeysForGroup();
|
if (redisKeysForGroup != null && !redisKeysForGroup.isEmpty()) {
|
||||||
if (redisKeysForGroup != null && !redisKeysForGroup.isEmpty()) {
|
for (String deleteKey : redisKeysForGroup) {
|
||||||
for (String deleteKey : redisKeysForGroup) {
|
redisTemplate.opsForHash().delete(key, deleteKey);
|
||||||
redisTemplate.opsForHash().delete(key, deleteKey);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user