diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index cd623bf2..e6ec4a39 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java @@ -1105,22 +1105,30 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi */ @Override public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException { - OkHttp okHttp = new OkHttp(); + // 创建OkHttpClient.Builder实例 + OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); - RequestParams requestParams = new RequestParams(); +// 添加重试拦截器到OkHttpClient + httpClientBuilder.addInterceptor(new RetryInterceptorUtil()); - requestParams.put("sysid", sysid); +// 构建最终的OkHttpClient实例 + OkHttpClient okHttpClient = httpClientBuilder.build(); +// 现在使用带有重试机制的OkHttpClient发起请求 + Map requestParams = new HashMap<>(); + requestParams.put("sysid", sysid); Map headers = new HashMap<>(); headers.put("Authorization", getAccessToken()); + Gson gson = new Gson(); + String requestParamsJson = gson.toJson(requestParams); + //todo 获取路况信息 try { - Response response // 请求响应 - = okHttp - .headers(headers) - .url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue()) // 请求地址 - .data(requestParams) // 请求参数 - .post(); // 请求方法 - + Request request = new Request.Builder() + .url(baseUrl + UniversalEnum.GETS_THE_URI_OF_THE_CURRENT_CONGESTION_EVENT.getValue()) + .headers(Headers.of(headers)) + .post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestParamsJson)) + .build(); + Response response = okHttpClient.newCall(request).execute(); ResponseBody body = response.body(); if (body != null) { String jsonString = body.string();