修复更新通道状态回复不准的问题

This commit is contained in:
648540858 2022-04-18 12:55:54 +08:00
parent 15b36e7be6
commit 2d7a571832
5 changed files with 30 additions and 4 deletions

View File

@ -78,7 +78,6 @@ public class CatalogDataCatch {
public SyncStatus getSyncStatus(String deviceId) { public SyncStatus getSyncStatus(String deviceId) {
CatalogData catalogData = data.get(deviceId); CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return null; if (catalogData == null) return null;
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) return null;
SyncStatus syncStatus = new SyncStatus(); SyncStatus syncStatus = new SyncStatus();
syncStatus.setCurrent(catalogData.getChannelList().size()); syncStatus.setCurrent(catalogData.getChannelList().size());
syncStatus.setTotal(catalogData.getTotal()); syncStatus.setTotal(catalogData.getTotal());
@ -86,6 +85,12 @@ public class CatalogDataCatch {
return syncStatus; return syncStatus;
} }
public boolean isSyncRunning(String deviceId) {
CatalogData catalogData = data.get(deviceId);
if (catalogData == null) return false;
return !catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end);
}
@Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时 @Scheduled(fixedRate = 5 * 1000) //每5秒执行一次, 发现数据5秒未更新则移除数据并认为数据接收超时
private void timerTask(){ private void timerTask(){
Set<String> keys = data.keySet(); Set<String> keys = data.keySet();

View File

@ -223,6 +223,14 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp
} }
} }
public boolean isSyncRunning(String deviceId) {
if (catalogDataCatch.get(deviceId) == null) {
return false;
}else {
return catalogDataCatch.isSyncRunning(deviceId);
}
}
public void setChannelSyncReady(Device device, int sn) { public void setChannelSyncReady(Device device, int sn) {
catalogDataCatch.addReady(device, sn); catalogDataCatch.addReady(device, sn);
} }

View File

@ -43,6 +43,13 @@ public interface IDeviceService {
*/ */
SyncStatus getChannelSyncStatus(String deviceId); SyncStatus getChannelSyncStatus(String deviceId);
/**
* 查看是否仍在同步
* @param deviceId 设备ID
* @return
*/
Boolean isSyncRunning(String deviceId);
/** /**
* 通道同步 * 通道同步
* @param device * @param device

View File

@ -99,6 +99,11 @@ public class DeviceServiceImpl implements IDeviceService {
return catalogResponseMessageHandler.getChannelSyncProgress(deviceId); return catalogResponseMessageHandler.getChannelSyncProgress(deviceId);
} }
@Override
public Boolean isSyncRunning(String deviceId) {
return catalogResponseMessageHandler.isSyncRunning(deviceId);
}
@Override @Override
public void sync(Device device) { public void sync(Device device) {
if (catalogResponseMessageHandler.getChannelSyncProgress(device.getDeviceId()) != null) { if (catalogResponseMessageHandler.getChannelSyncProgress(device.getDeviceId()) != null) {

View File

@ -164,12 +164,13 @@ public class DeviceQuery {
logger.debug("设备通道信息同步API调用deviceId" + deviceId); logger.debug("设备通道信息同步API调用deviceId" + deviceId);
} }
Device device = storager.queryVideoDevice(deviceId); Device device = storager.queryVideoDevice(deviceId);
SyncStatus syncStatus = deviceService.getChannelSyncStatus(deviceId); boolean status = deviceService.isSyncRunning(deviceId);
// 已存在则返回进度 // 已存在则返回进度
if (syncStatus != null && syncStatus.getErrorMsg() == null) { if (status) {
WVPResult<SyncStatus> wvpResult = new WVPResult<>(); WVPResult<SyncStatus> wvpResult = new WVPResult<>();
wvpResult.setCode(0); wvpResult.setCode(0);
wvpResult.setData(syncStatus); SyncStatus channelSyncStatus = deviceService.getChannelSyncStatus(deviceId);
wvpResult.setData(channelSyncStatus);
return wvpResult; return wvpResult;
} }
deviceService.sync(device); deviceService.sync(device);