|
@ -26,28 +26,35 @@ public class CatalogDataCatch { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private IVideoManagerStorage storager; |
|
|
private IVideoManagerStorage storager; |
|
|
|
|
|
|
|
|
public void addReady(String key) { |
|
|
public void addReady(Device device, int sn ) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(device.getDeviceId()); |
|
|
if (catalogData == null || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) { |
|
|
if (catalogData == null || catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end)) { |
|
|
catalogData = new CatalogData(); |
|
|
catalogData = new CatalogData(); |
|
|
catalogData.setChannelList(new ArrayList<>()); |
|
|
catalogData.setChannelList(new ArrayList<>()); |
|
|
|
|
|
catalogData.setDevice(device); |
|
|
|
|
|
catalogData.setSn(sn); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.ready); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.ready); |
|
|
catalogData.setLastTime(new Date(System.currentTimeMillis())); |
|
|
catalogData.setLastTime(new Date(System.currentTimeMillis())); |
|
|
data.put(key, catalogData); |
|
|
data.put(device.getDeviceId(), catalogData); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void put(String key, int total, Device device, List<DeviceChannel> deviceChannelList) { |
|
|
public void put(String deviceId, int sn, int total, Device device, List<DeviceChannel> deviceChannelList) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData == null) { |
|
|
if (catalogData == null) { |
|
|
catalogData = new CatalogData(); |
|
|
catalogData = new CatalogData(); |
|
|
|
|
|
catalogData.setSn(sn); |
|
|
catalogData.setTotal(total); |
|
|
catalogData.setTotal(total); |
|
|
catalogData.setDevice(device); |
|
|
catalogData.setDevice(device); |
|
|
catalogData.setChannelList(new ArrayList<>()); |
|
|
catalogData.setChannelList(new ArrayList<>()); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
|
|
catalogData.setLastTime(new Date(System.currentTimeMillis())); |
|
|
catalogData.setLastTime(new Date(System.currentTimeMillis())); |
|
|
data.put(key, catalogData); |
|
|
data.put(deviceId, catalogData); |
|
|
}else { |
|
|
}else { |
|
|
|
|
|
// 同一个设备的通道同步请求只考虑一个,其他的直接忽略
|
|
|
|
|
|
if (catalogData.getSn() != sn) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
catalogData.setTotal(total); |
|
|
catalogData.setTotal(total); |
|
|
catalogData.setDevice(device); |
|
|
catalogData.setDevice(device); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.runIng); |
|
@ -56,20 +63,20 @@ public class CatalogDataCatch { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public List<DeviceChannel> get(String key) { |
|
|
public List<DeviceChannel> get(String deviceId) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData == null) return null; |
|
|
if (catalogData == null) return null; |
|
|
return catalogData.getChannelList(); |
|
|
return catalogData.getChannelList(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public int getTotal(String key) { |
|
|
public int getTotal(String deviceId) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData == null) return 0; |
|
|
if (catalogData == null) return 0; |
|
|
return catalogData.getTotal(); |
|
|
return catalogData.getTotal(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public SyncStatus getSyncStatus(String key) { |
|
|
public SyncStatus getSyncStatus(String deviceId) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData == null) return null; |
|
|
if (catalogData == null) return null; |
|
|
SyncStatus syncStatus = new SyncStatus(); |
|
|
SyncStatus syncStatus = new SyncStatus(); |
|
|
syncStatus.setCurrent(catalogData.getChannelList().size()); |
|
|
syncStatus.setCurrent(catalogData.getChannelList().size()); |
|
@ -78,10 +85,6 @@ public class CatalogDataCatch { |
|
|
return syncStatus; |
|
|
return syncStatus; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void del(String key) { |
|
|
|
|
|
data.remove(key); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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(); |
|
@ -92,23 +95,30 @@ public class CatalogDataCatch { |
|
|
Calendar calendarBefore30S = Calendar.getInstance(); |
|
|
Calendar calendarBefore30S = Calendar.getInstance(); |
|
|
calendarBefore30S.setTime(new Date()); |
|
|
calendarBefore30S.setTime(new Date()); |
|
|
calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30); |
|
|
calendarBefore30S.set(Calendar.SECOND, calendarBefore30S.get(Calendar.SECOND) - 30); |
|
|
for (String key : keys) { |
|
|
for (String deviceId : keys) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据
|
|
|
if ( catalogData.getLastTime().before(calendarBefore5S.getTime())) { // 超过五秒收不到消息任务超时, 只更新这一部分数据
|
|
|
storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); |
|
|
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.runIng)) { |
|
|
String errorMsg = "更新成功,共" + catalogData.getTotal() + "条,已更新" + catalogData.getChannelList().size() + "条"; |
|
|
storager.resetChannels(catalogData.getDevice().getDeviceId(), catalogData.getChannelList()); |
|
|
|
|
|
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 = "同步失败,等待回复超时"; |
|
|
|
|
|
catalogData.setErrorMsg(errorMsg); |
|
|
|
|
|
} |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
|
|
catalogData.setErrorMsg(errorMsg); |
|
|
|
|
|
} |
|
|
} |
|
|
if (catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除
|
|
|
if (catalogData.getStatus().equals(CatalogData.CatalogDataStatus.end) && catalogData.getLastTime().before(calendarBefore30S.getTime())) { // 超过三十秒,如果标记为end则删除
|
|
|
data.remove(key); |
|
|
data.remove(deviceId); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void setChannelSyncEnd(String key, String errorMsg) { |
|
|
public void setChannelSyncEnd(String deviceId, String errorMsg) { |
|
|
CatalogData catalogData = data.get(key); |
|
|
CatalogData catalogData = data.get(deviceId); |
|
|
if (catalogData == null)return; |
|
|
if (catalogData == null)return; |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
|
|
catalogData.setStatus(CatalogData.CatalogDataStatus.end); |
|
|
catalogData.setErrorMsg(errorMsg); |
|
|
catalogData.setErrorMsg(errorMsg); |
|
|