调整/调试 重试逻辑

This commit is contained in:
shikong 2023-09-09 21:01:29 +08:00
parent 45ac5d5d56
commit 6a25f48852

View File

@ -115,39 +115,12 @@ public class WvpService {
log.info("设备编码 (deviceCode=>{}) 查询到的设备信息 国标id(gbDeviceId => {}), 通道(channelId => {})", deviceCode, deviceId, channelId);
Retryer<JsonResponse<?>> genericRetryer = getDefaultGenericRetryer();
String passwdMd5 = MD5.create().digestHex(wvpProxyConfig.getPasswd());
WvpLoginReq loginReq = WvpLoginReq.builder()
.username(wvpProxyConfig.getUser())
.password(passwdMd5)
.build();
AsyncContext asyncContext = request.startAsync();
asyncContext.setTimeout(0);
asyncContext.start(() -> {
HttpServletResponse asyncResponse = (HttpServletResponse) asyncContext.getResponse();
try {
genericRetryer.call(() -> {
JsonResponse<WvpLoginResp> login = wvpProxyClient.login(loginReq);
String accessToken = login.getData().getAccessToken();
log.info("wvp 登录成功 accessToken => {}", accessToken);
log.debug("通过 wvp 查询设备 国标id(gbDeviceId => {}) 通道信息", deviceId);
JsonResponse<GetDeviceChannelsResp> deviceChannels = wvpProxyClient.getDeviceChannels(accessToken, deviceId, GetDeviceChannelsReq.builder().build());
if (deviceChannels.getData() == null || deviceChannels.getData().getTotal() == 0) {
writeErrorToResponse(asyncResponse, JsonResponse.error(MessageFormat.format("未能获取 设备:{0}, 国标id: {1}, 的通道信息", deviceCode, deviceId)));
return JsonResponse.success(null);
}
List<DeviceChannel> list = deviceChannels.getData().getList();
log.info("通过 wvp 获取到 查询设备 国标id(gbDeviceId => {}), 通道数量 => {}", deviceId, list.size());
DeviceChannel deviceChannel = list.parallelStream().filter(item -> item.getChannelId().equalsIgnoreCase(channelId)).findFirst().orElse(null);
if (deviceChannel == null) {
writeErrorToResponse(asyncResponse, JsonResponse.error(MessageFormat.format("未查询到 设备:{0}, 国标id: {1}, 通道: {2} 信息", deviceCode, deviceId, channelId)));
return JsonResponse.success(null);
}
downloadService.download(asyncResponse, "http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
return login;
});
genericRetryer.call(() -> video(asyncResponse, deviceCode,deviceId,channelId,startTime,endTime));
} catch (RetryException e) {
String reason = MessageFormat.format("查询失败, 已重试 {0} 次", e.getNumberOfFailedAttempts());
log.error(reason);
@ -159,4 +132,33 @@ public class WvpService {
}
});
}
@SneakyThrows
public JsonResponse<?> video(HttpServletResponse response, String deviceCode, String deviceId,String channelId ,Date startTime, Date endTime) {
String passwdMd5 = MD5.create().digestHex(wvpProxyConfig.getPasswd());
WvpLoginReq loginReq = WvpLoginReq.builder()
.username(wvpProxyConfig.getUser())
.password(passwdMd5)
.build();
JsonResponse<WvpLoginResp> login = wvpProxyClient.login(loginReq);
String accessToken = login.getData().getAccessToken();
log.info("wvp 登录成功 accessToken => {}", accessToken);
log.debug("通过 wvp 查询设备 国标id(gbDeviceId => {}) 通道信息", deviceId);
JsonResponse<GetDeviceChannelsResp> deviceChannels = wvpProxyClient.getDeviceChannels(accessToken, deviceId, GetDeviceChannelsReq.builder().build());
if (deviceChannels.getData() == null || deviceChannels.getData().getTotal() == 0) {
writeErrorToResponse(response, JsonResponse.error(MessageFormat.format("未能获取 设备:{0}, 国标id: {1}, 的通道信息", deviceCode, deviceId)));
return JsonResponse.success(null);
}
List<DeviceChannel> list = deviceChannels.getData().getList();
log.info("通过 wvp 获取到 查询设备 国标id(gbDeviceId => {}), 通道数量 => {}", deviceId, list.size());
DeviceChannel deviceChannel = list.parallelStream().filter(item -> item.getChannelId().equalsIgnoreCase(channelId)).findFirst().orElse(null);
if (deviceChannel == null) {
writeErrorToResponse(response, JsonResponse.error(MessageFormat.format("未查询到 设备:{0}, 国标id: {1}, 通道: {2} 信息", deviceCode, deviceId, channelId)));
return JsonResponse.success(null);
}
downloadService.download(response, "http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
return login;
}
}