Compare commits

...

2 Commits

Author SHA1 Message Date
62cd5e2016 完善重试日志
查询历史录像
2023-09-09 22:49:36 +08:00
b7b70fe42f 查询历史录像 2023-09-09 22:17:03 +08:00

View File

@ -58,20 +58,20 @@ public class WvpService {
public final static int DEFAULT_RETRY_WAIT_TIME = 3;
@SuppressWarnings("UnstableApiUsage")
private static RetryListener defaultRetryListener() {
private static RetryListener defaultRetryListener(String name) {
return new RetryListener() {
@Override
public <V> void onRetry(Attempt<V> attempt) {
log.info("第 {} 次 执行结束", attempt.getAttemptNumber());
log.info("第 {} 次 执行 {} 结束", attempt.getAttemptNumber(), name);
if (attempt.hasException()) {
log.info("异常 {}", attempt.getExceptionCause().getMessage());
log.info("执行 {} 异常 {}", name, attempt.getExceptionCause().getMessage());
}
}
};
}
@SuppressWarnings("UnstableApiUsage")
private static <T> Retryer<JsonResponse<T>> getDefaultRetryer() {
private static <T> Retryer<JsonResponse<T>> getDefaultRetryer(String name) {
return RetryerBuilder.<JsonResponse<T>>newBuilder()
// 异常就重试
.retryIfException()
@ -81,12 +81,12 @@ public class WvpService {
// 重试次数
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
.withRetryListener(defaultRetryListener())
.withRetryListener(defaultRetryListener(name))
.build();
}
@SuppressWarnings("UnstableApiUsage")
private static Retryer<JsonResponse<?>> getDefaultGenericRetryer() {
private static Retryer<JsonResponse<?>> getDefaultGenericRetryer(String name) {
return RetryerBuilder.<JsonResponse<?>>newBuilder()
// 异常就重试
.retryIfException()
@ -96,7 +96,7 @@ public class WvpService {
// 重试次数
.withStopStrategy(StopStrategies.stopAfterAttempt(DEFAULT_RETRY_TIME))
.retryIfResult(result -> result != null && (result.getCode() != 0 || result.getCode() != 200))
.withRetryListener(defaultRetryListener())
.withRetryListener(defaultRetryListener(name))
.build();
}
@ -119,7 +119,7 @@ public class WvpService {
String channelId = wvpProxyDevice.getGbDeviceChannelId();
log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);
Retryer<JsonResponse<?>> genericRetryer = getDefaultGenericRetryer();
Retryer<JsonResponse<?>> genericRetryer = getDefaultGenericRetryer("调用 wvp api 查询设备历史");
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0);
asyncContext.start(() -> {
@ -177,24 +177,27 @@ public class WvpService {
return JsonResponse.success(null);
}
JsonResponse<QueryRecordResp> queryRecord = wvpProxyClient.queryRecord(token, deviceId, channelId, new QueryRecordReq(DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)));
QueryRecordResp queryRecordData = queryRecord.getData();
if (queryRecordData == null) {
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}", deviceCode, deviceId, channelId);
log.error(reason);
log.error("查询历史录像 返回结果 => {}", queryRecord);
writeErrorToResponse(response, JsonResponse.error(reason));
return null;
}
List<QueryRecordResp.RecordListDTO> recordList = queryRecordData.getRecordList();
if (CollectionUtils.isEmpty(recordList)) {
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 查询时间范围 开始时间: {3}, 结束时间: {4}, 录像数量为 0", deviceCode, deviceId, channelId, startTime, endTime);
writeErrorToResponse(response, JsonResponse.error(reason));
return null;
}
log.info("通过 wvp 查询到 {} 条历史录像 设备: {}, 国标id: {}, 通道: {}, 开始时间: {}, 结束时间: {}", recordList.size(), deviceCode, deviceId, channelId, startTime, endTime);
Retryer<JsonResponse<List<QueryRecordResp.RecordListDTO>>> queryRecordRetryer = getDefaultRetryer("调用 wvp 设备历史查询 api");
JsonResponse<List<QueryRecordResp.RecordListDTO>> recordListResponse = queryRecordRetryer.call(() -> {
JsonResponse<QueryRecordResp> queryRecord = wvpProxyClient.queryRecord(token, deviceId, channelId, new QueryRecordReq(DateUtil.formatDateTime(startTime), DateUtil.formatDateTime(endTime)));
QueryRecordResp queryRecordData = queryRecord.getData();
if (queryRecordData == null) {
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 错误信息: {3}", deviceCode, deviceId, channelId, queryRecord.getMsg());
log.error(reason);
log.error("查询历史录像 返回结果 => {}", queryRecord);
throw new JsonException(reason);
}
List<QueryRecordResp.RecordListDTO> recordList = queryRecordData.getRecordList();
if (CollectionUtils.isEmpty(recordList)) {
String reason = MessageFormat.format("通过 wvp 查询历史录像 失败 设备: {0}, 国标id: {1}, 通道: {2}, 查询时间范围 开始时间: {3}, 结束时间: {4}, 录像数量为 0", deviceCode, deviceId, channelId, startTime, endTime);
throw new JsonException(reason);
}
log.info("通过 wvp 查询到 {} 条历史录像 设备: {}, 国标id: {}, 通道: {}, 开始时间: {}, 结束时间: {}", recordList.size(), deviceCode, deviceId, channelId, startTime, endTime);
return JsonResponse.success(recordList);
});
downloadService.download(response, "http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
return queryRecord;
return login;
}
}