|
|
@ -187,7 +187,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JSONArray vehiclesInTransit() throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
OkHttp okHttp = new OkHttp(20); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
@ -678,7 +678,7 @@ 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(); |
|
|
|
OkHttp okHttp = new OkHttp(20); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
@ -697,53 +697,60 @@ 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 |
|
|
|
public JSONArray trafficFlowAtTollStationEntranceHour(String startDate, String endDate, String stationType) throws HttpException, IOException { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
OkHttp okHttp = new OkHttp(15); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
@ -793,13 +800,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
LocalDate oneYearAgo = currentDate.minusYears(UniversalEnum.ONE.getNumber()); |
|
|
|
String lastYear = oneYearAgo.format(formatter); |
|
|
|
|
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
OkHttp okHttp = new OkHttp(20); |
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
requestParams.put("sysid", sysid); |
|
|
|
//求情地址 startDate 时间
|
|
|
|
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 +896,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(); |
|
|
|
} |
|
|
|
|
|
|
|
//格式化桩号
|
|
|
@ -1093,38 +1107,47 @@ 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 { |
|
|
|
OkHttp okHttp = new OkHttp(); |
|
|
|
OkHttp okHttp = new OkHttp(20); |
|
|
|
|
|
|
|
RequestParams requestParams = new RequestParams(); |
|
|
|
|
|
|
|