|
|
@ -195,7 +195,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -214,6 +214,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -230,7 +235,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -298,6 +303,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
}); |
|
|
|
|
|
|
|
return jsonArray1; |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -313,7 +323,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -331,6 +341,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
} |
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -563,7 +578,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -582,6 +597,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -609,7 +629,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -628,6 +648,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -652,7 +677,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -669,8 +694,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -697,48 +726,55 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
|
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + UniversalEnum.EACH_TOLL_STATION_ENTRANCE_BY_TYPE_OF_HOURLY_TRAFFIC_FLOW.getValue()) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
Map<String, Integer> sumByName = new LinkedHashMap<>(); |
|
|
|
|
|
|
|
List<Map<String, String>> list = new ArrayList(); |
|
|
|
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
|
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
|
|
|
|
|
|
|
|
// 获取当前时间
|
|
|
|
LocalTime now = LocalTime.now(); |
|
|
|
// 获取当前小时数(24小时制)
|
|
|
|
int currentHour = now.getHour(); |
|
|
|
if (jsonObject.getInteger("data_hour") == currentHour) { |
|
|
|
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
|
|
|
|
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
|
|
|
|
|
|
|
|
sumByName.put(name, totalFlow); |
|
|
|
try { |
|
|
|
Response response = okHttp |
|
|
|
.headers(headers) |
|
|
|
.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()); |
|
|
|
} |
|
|
|
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<>(); |
|
|
|
List<Map<String, String>> list = new ArrayList(); |
|
|
|
for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object
|
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
|
|
|
|
// 获取当前时间
|
|
|
|
LocalTime now = LocalTime.now(); |
|
|
|
// 获取当前小时数(24小时制)
|
|
|
|
int currentHour = now.getHour(); |
|
|
|
if (jsonObject.getInteger("data_hour") == currentHour) { |
|
|
|
String name = jsonObject.getString("ts_name"); // 更安全的取值方式
|
|
|
|
int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型
|
|
|
|
|
|
|
|
sumByName.put(name, totalFlow); |
|
|
|
} |
|
|
|
} |
|
|
|
// 正确创建新的映射对象并添加到list中
|
|
|
|
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { |
|
|
|
Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
|
|
|
|
singleResult.put("name", entry.getKey()); |
|
|
|
singleResult.put("value", entry.getValue().toString()); |
|
|
|
list.add(singleResult); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
// 正确创建新的映射对象并添加到list中
|
|
|
|
for (Map.Entry<String, Integer> entry : sumByName.entrySet()) { |
|
|
|
Map<String, String> singleResult = new LinkedHashMap<>(); // 每次循环都创建一个新的映射
|
|
|
|
singleResult.put("name", entry.getKey()); |
|
|
|
singleResult.put("value", entry.getValue().toString()); |
|
|
|
list.add(singleResult); |
|
|
|
} |
|
|
|
return list; |
|
|
|
} |
|
|
|
return new ArrayList(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new ArrayList(); |
|
|
|
} |
|
|
|
return new ArrayList(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -761,7 +797,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -780,6 +816,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -800,6 +841,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
JSONArray body = getResponseBody(nowYear, requestParams, okHttp); |
|
|
|
|
|
|
|
JSONArray bodylast = getResponseBody(lastYear, requestParams, okHttp); |
|
|
|
|
|
|
|
Map<String, List<Map<String, Object>>> map = new HashMap<>(); |
|
|
|
|
|
|
|
if (body != null) { |
|
|
@ -888,23 +930,29 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
requestParams.put("parameters", parameters.toJSONString()); |
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL.getValue()) // 请求地址
|
|
|
|
.data(requestParams) // 请求参数
|
|
|
|
.post(); // 请求方法
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
return JSON.parseArray(jsonString); |
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
|
.url(baseUrl + UniversalEnum.THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL.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(); |
|
|
|
} |
|
|
|
}else { |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|
// 记录日志或处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
|
|
|
|
//格式化桩号
|
|
|
@ -960,7 +1008,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -991,6 +1039,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return mapList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -1010,7 +1063,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
Map<String, String> headers = new HashMap<>(); |
|
|
|
headers.put("Authorization", getAccessToken()); |
|
|
|
|
|
|
|
try { |
|
|
|
Response response // 请求响应
|
|
|
|
= okHttp |
|
|
|
.headers(headers) |
|
|
@ -1078,9 +1131,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
return jsonArray; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return new JSONArray(); |
|
|
|
|
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new JSONArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -1093,34 +1149,43 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); |
|
|
|
LocalDate currentDate = LocalDate.now(); |
|
|
|
String startDate = currentDate.format(formatter); |
|
|
|
Response response = getResponseTrafficFlowAtToll(startDate, UniversalEnum.ONE.getValue()); |
|
|
|
Response responseTwo = getResponseTrafficFlowAtToll(startDate, UniversalEnum.TWO.getValue()); |
|
|
|
|
|
|
|
ResponseBody body = response.body(); |
|
|
|
ResponseBody bodyTwo = responseTwo.body(); |
|
|
|
Integer totalFlow1 = UniversalEnum.ZERO.getNumber(); |
|
|
|
Integer totalFlow2 = UniversalEnum.ZERO.getNumber(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
for (Object item : jsonArray) { |
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
totalFlow1 = totalFlow1 + jsonObject.getInteger("total_flow"); |
|
|
|
try { |
|
|
|
Response response = getResponseTrafficFlowAtToll(startDate, UniversalEnum.ONE.getValue()); |
|
|
|
Response responseTwo = getResponseTrafficFlowAtToll(startDate, UniversalEnum.TWO.getValue()); |
|
|
|
ResponseBody body = response.body(); |
|
|
|
ResponseBody bodyTwo = responseTwo.body(); |
|
|
|
Integer totalFlow1 = UniversalEnum.ZERO.getNumber(); |
|
|
|
Integer totalFlow2 = UniversalEnum.ZERO.getNumber(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
for (Object item : jsonArray) { |
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
totalFlow1 = totalFlow1 + jsonObject.getInteger("total_flow"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (bodyTwo != null) { |
|
|
|
String jsonString = bodyTwo.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
for (Object item : jsonArray) { |
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
totalFlow2 = totalFlow2 + jsonObject.getInteger("total_flow"); |
|
|
|
if (bodyTwo != null) { |
|
|
|
String jsonString = bodyTwo.string(); |
|
|
|
if (JSON.isValidArray(jsonString)) { |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
for (Object item : jsonArray) { |
|
|
|
JSONObject jsonObject = (JSONObject) item; |
|
|
|
totalFlow2 = totalFlow2 + jsonObject.getInteger("total_flow"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return totalFlow1 + totalFlow2; |
|
|
|
} |
|
|
|
catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return UniversalEnum.ZERO.getNumber(); |
|
|
|
} |
|
|
|
return totalFlow1 + totalFlow2; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { |
|
|
|