|
|
@ -1,10 +1,10 @@ |
|
|
|
package com.zc.business.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.google.gson.Gson; |
|
|
|
import com.ruoyi.common.core.redis.RedisCache; |
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils; |
|
|
|
import com.zc.business.constant.RedisKeyConstants; |
|
|
@ -17,14 +17,12 @@ import com.zc.business.enums.UniversalEnum; |
|
|
|
import com.zc.business.service.IDcFacilityService; |
|
|
|
import com.zc.business.service.IDcRoadSectionService; |
|
|
|
import com.zc.business.service.IDcTrafficStatisticsService; |
|
|
|
import com.zc.business.utils.RetryInterceptorUtil; |
|
|
|
import com.zc.business.utils.StakeMarkUtils; |
|
|
|
import com.zc.common.core.httpclient.OkHttp; |
|
|
|
import com.zc.common.core.httpclient.exception.HttpException; |
|
|
|
import com.zc.common.core.httpclient.request.RequestParams; |
|
|
|
import okhttp3.Call; |
|
|
|
import okhttp3.Callback; |
|
|
|
import okhttp3.Response; |
|
|
|
import okhttp3.ResponseBody; |
|
|
|
import okhttp3.*; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
@ -637,6 +635,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
@ -660,46 +659,98 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JSONArray sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// OkHttp okHttp = new OkHttp();
|
|
|
|
//
|
|
|
|
// RequestParams requestParams = new RequestParams();
|
|
|
|
//
|
|
|
|
// requestParams.put("sysid", sysid);
|
|
|
|
//
|
|
|
|
// JSONObject parameters = new JSONObject() {
|
|
|
|
// {
|
|
|
|
// put("start_date", startDate);
|
|
|
|
// put("end_date", endDate);
|
|
|
|
// }
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// requestParams.put("parameters", parameters.toJSONString());
|
|
|
|
//
|
|
|
|
// Map<String, String> headers = new HashMap<>();
|
|
|
|
// headers.put("Authorization", getAccessToken());
|
|
|
|
// try {
|
|
|
|
// Response response // 请求响应
|
|
|
|
// = okHttp
|
|
|
|
// .headers(headers)
|
|
|
|
// .url(baseUrl + UniversalEnum.SECTION_HOURLY_TRAFFIC_FLOW_BY_VEHICLE_TYPE.getValue()) // 请求地址
|
|
|
|
// .data(requestParams) // 请求参数
|
|
|
|
// .post(); // 请求方法
|
|
|
|
//
|
|
|
|
// ResponseBody body = response.body();
|
|
|
|
// if (body != null) {
|
|
|
|
// String jsonString = body.string();
|
|
|
|
// if (JSON.isValidArray(jsonString)) {
|
|
|
|
// return JSON.parseArray(jsonString);
|
|
|
|
// }else {
|
|
|
|
// return new JSONArray();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return new JSONArray();
|
|
|
|
// } catch (IOException e) {
|
|
|
|
// // 处理异常
|
|
|
|
// e.printStackTrace();
|
|
|
|
// return new JSONArray();
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 创建OkHttpClient.Builder实例
|
|
|
|
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); |
|
|
|
|
|
|
|
// 添加重试拦截器到OkHttpClient
|
|
|
|
httpClientBuilder.addInterceptor(new RetryInterceptorUtil()); |
|
|
|
|
|
|
|
// 构建最终的OkHttpClient实例
|
|
|
|
OkHttpClient okHttpClient = httpClientBuilder.build(); |
|
|
|
|
|
|
|
// 现在使用带有重试机制的OkHttpClient发起请求
|
|
|
|
Map<String, Object> requestParams = new HashMap<>(); |
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", startDate); |
|
|
|
put("end_date", endDate); |
|
|
|
} |
|
|
|
}; |
|
|
|
JSONObject parameters = new JSONObject(); |
|
|
|
parameters.put("start_date", startDate); |
|
|
|
parameters.put("end_date", endDate); |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
requestParams.put("parameters", parameters); |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
Gson gson = new Gson(); |
|
|
|
String requestParamsJson = gson.toJson(requestParams); |
|
|
|
// 使用okHttpClient实例发起请求
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + UniversalEnum.SECTION_HOURLY_TRAFFIC_FLOW_BY_VEHICLE_TYPE.getValue()) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(baseUrl + UniversalEnum.SECTION_HOURLY_TRAFFIC_FLOW_BY_VEHICLE_TYPE.getValue()) |
|
|
|
.headers(Headers.of(headers)) |
|
|
|
.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestParamsJson)) |
|
|
|
.build(); |
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
return JSON.parseArray(jsonString); |
|
|
|
}else { |
|
|
|
return new JSONArray(); |
|
|
|
Response response = okHttpClient.newCall(request).execute(); |
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
return JSON.parseArray(jsonString); |
|
|
|
} else { |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return new JSONArray(); |
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -707,39 +758,38 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<Map<String, String>> trafficFlowAtTollStationEntrance(String startDate, String endDate, String stationType) 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); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", startDate); |
|
|
|
put("end_date", endDate); |
|
|
|
put("station_type", stationType); |
|
|
|
} |
|
|
|
}; |
|
|
|
// 构建最终的OkHttpClient实例
|
|
|
|
OkHttpClient okHttpClient = httpClientBuilder.build(); |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
// 现在使用带有重试机制的OkHttpClient发起请求
|
|
|
|
Map<String, Object> requestParams = new HashMap<>(); |
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
JSONObject parameters = new JSONObject(); |
|
|
|
parameters.put("start_date", startDate); |
|
|
|
parameters.put("end_date", endDate); |
|
|
|
parameters.put("station_type", stationType); |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters); |
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
Gson gson = new Gson(); |
|
|
|
String requestParamsJson = gson.toJson(requestParams); |
|
|
|
try { |
|
|
|
Response response = okHttp |
|
|
|
.headers(headers) |
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(baseUrl + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue()) |
|
|
|
.data(requestParams) |
|
|
|
.post(); |
|
|
|
// 确保响应成功
|
|
|
|
if (!response.isSuccessful()) { |
|
|
|
throw new IOException("请求不成功,HTTP代码:" + response.code()); |
|
|
|
} |
|
|
|
.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(); |
|
|
|
System.out.println(jsonString); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
Map<String, Integer> sumByName = new LinkedHashMap<>(); |
|
|
@ -1055,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<String, Object> requestParams = new HashMap<>(); |
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
Map<String, String> 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(); |
|
|
@ -1189,32 +1247,36 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
// 创建OkHttpClient.Builder实例
|
|
|
|
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder(); |
|
|
|
|
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
// 添加重试拦截器到OkHttpClient
|
|
|
|
httpClientBuilder.addInterceptor(new RetryInterceptorUtil()); |
|
|
|
|
|
|
|
JSONObject parameters = new JSONObject() { |
|
|
|
{ |
|
|
|
put("start_date", startDate); |
|
|
|
put("end_date", startDate); |
|
|
|
put("station_type", stationType); |
|
|
|
} |
|
|
|
}; |
|
|
|
// 构建最终的OkHttpClient实例
|
|
|
|
OkHttpClient okHttpClient = httpClientBuilder.build(); |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
// 现在使用带有重试机制的OkHttpClient发起请求
|
|
|
|
Map<String, Object> requestParams = new HashMap<>(); |
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
JSONObject parameters = new JSONObject(); |
|
|
|
parameters.put("start_date", startDate); |
|
|
|
parameters.put("end_date", startDate); |
|
|
|
parameters.put("station_type", stationType); |
|
|
|
|
|
|
|
requestParams.put("parameters", parameters); |
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
Gson gson = new Gson(); |
|
|
|
String requestParamsJson = gson.toJson(requestParams); |
|
|
|
|
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(baseUrl + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue()) |
|
|
|
.headers(Headers.of(headers)) |
|
|
|
.post(RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestParamsJson)) |
|
|
|
.build(); |
|
|
|
Response response = okHttpClient.newCall(request).execute(); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue()) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
return response; |
|
|
|
} |
|
|
|
|
|
|
|