|
|
@ -815,6 +815,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
|
|
|
|
// 直接基于原始数据映射和LocationEnum构建最终结果列表
|
|
|
|
List<Map<String, String>> resultList = Arrays.stream(LocationEnum.values()) |
|
|
|
.filter(location -> !location.getName().equals("平阴北"))// 先过滤掉平阴北
|
|
|
|
.map(location -> { |
|
|
|
Map<String, String> defaultData = new HashMap<String, String>() {{ |
|
|
|
put("value", "0"); |
|
|
@ -837,6 +838,74 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
return new ArrayList(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public TreeMap<String, Integer> entranceToEachTollStation(String startDate, String endDate, String stationType) throws HttpException, IOException { |
|
|
|
// 创建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(); |
|
|
|
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 { |
|
|
|
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(); |
|
|
|
ResponseBody body = response.body(); |
|
|
|
if (body != null) { |
|
|
|
String jsonString = body.string(); |
|
|
|
JSONArray jsonArray = JSON.parseArray(jsonString); |
|
|
|
Map<Integer, Integer> flowPerHour = jsonArray.stream() |
|
|
|
.map(item -> (JSONObject) item) |
|
|
|
.collect(Collectors.groupingBy( |
|
|
|
item -> item.getInteger("data_hour"), |
|
|
|
Collectors.reducing( |
|
|
|
0, |
|
|
|
item -> item.getInteger("total_flow"), |
|
|
|
Integer::sum |
|
|
|
) |
|
|
|
)); |
|
|
|
TreeMap<String, Integer> hashMap = new TreeMap<>(); |
|
|
|
// 示例输出结果
|
|
|
|
flowPerHour.forEach((hour, totalFlow) -> |
|
|
|
hashMap.put(hour.toString(), totalFlow)); |
|
|
|
// 使用带有自定义Comparator的TreeMap进行排序
|
|
|
|
TreeMap<String, Integer> sortedMap = new TreeMap<>((o1, o2) -> { |
|
|
|
int hour1 = Integer.parseInt(o1); |
|
|
|
int hour2 = Integer.parseInt(o2); |
|
|
|
return Integer.compare(hour1, hour2); |
|
|
|
}); |
|
|
|
|
|
|
|
// 将数据放入TreeMap中
|
|
|
|
sortedMap.putAll(hashMap); |
|
|
|
return sortedMap; |
|
|
|
} |
|
|
|
return new TreeMap<>(); |
|
|
|
} catch (IOException e) { |
|
|
|
// 处理异常
|
|
|
|
e.printStackTrace(); |
|
|
|
return new TreeMap(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@ -973,10 +1042,14 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi |
|
|
|
// 构建结果列表
|
|
|
|
List<Map<String, Object>> mapList = new ArrayList<>(); |
|
|
|
for (int i = UniversalEnum.ONE.getNumber(); i <= 13; i++) { |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("name", getTrafficFlowDoorFrameSection(i)); |
|
|
|
map.put("totalFlow", flowCounts.get(i)); |
|
|
|
mapList.add(map); |
|
|
|
// 只添加不为0的车流量数据,后续删除
|
|
|
|
if (!getTrafficFlowDoorFrameSection(i).equals("孝里虚-平阴北虚")){ |
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
map.put("name", getTrafficFlowDoorFrameSection(i)); |
|
|
|
map.put("totalFlow", flowCounts.get(i)); |
|
|
|
mapList.add(map); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
return mapList; |
|
|
|
} |
|
|
|