From fa6786072367d448f32c84bf958197ef48bf38ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Wed, 30 Oct 2024 11:15:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=9C=A8=E7=BA=BF=E7=8E=87?= =?UTF-8?q?=EF=BC=8C=E4=BA=A4=E9=80=9A=E6=B5=81=E4=BA=8B=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DcDeviceOnlineController.java | 9 +- .../DcTrafficStatisticsController.java | 21 +++++ .../com/zc/business/domain/OnlineSum.java | 8 +- .../com/zc/business/enums/UniversalEnum.java | 5 + .../service/IDcTrafficStatisticsService.java | 6 ++ .../impl/DcTrafficStatisticsServiceImpl.java | 91 +++++++++++++++++++ 6 files changed, 134 insertions(+), 6 deletions(-) diff --git a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java index a3088b5f..5deafaf7 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcDeviceOnlineController.java @@ -151,7 +151,11 @@ public class DcDeviceOnlineController extends BaseController { for (String type : types) { Map map = new HashMap<>(); List listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); + Map> localDateListMap = listOfType.stream() + .collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate())); +/* Map> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); +*/ for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { List dayList = localDateListMap.getOrDefault(date, new ArrayList<>()); map.put(date.toString(), MathUtil.doubleTwoDecimalStr(dayList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0)) + "%"); @@ -191,7 +195,8 @@ public class DcDeviceOnlineController extends BaseController { List listOfType = stringListMap.getOrDefault(type, new ArrayList<>()); // 按日期分组 - Map> localDateListMap = listOfType.stream().collect(Collectors.groupingBy(OnlineSum::getStatisticalDate)); + Map> localDateListMap = listOfType.stream() .collect(Collectors.groupingBy(onlineSum -> onlineSum.getStatisticalDate().toLocalDate())); + // 按日期统计 for (LocalDate date = start.toLocalDate(); date.isBefore(end.toLocalDate().plusDays(1)); date = date.plusDays(1)) { @@ -203,7 +208,7 @@ public class DcDeviceOnlineController extends BaseController { LocalDateTime startHour = LocalDateTime.of(date, LocalTime.of(hour, 0)); LocalDateTime endHour = startHour.plusHours(1); List hourList = dayList.stream() - .filter(os -> os.getStatisticalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().isBefore(ChronoLocalDate.from(endHour))) + .filter(os -> os.getStatisticalDate().toLocalDate().isAfter(ChronoLocalDate.from(startHour)) && os.getStatisticalDate().toLocalDate().isBefore(ChronoLocalDate.from(endHour))) .collect(Collectors.toList()); double averageRate = hourList.stream().mapToDouble(OnlineSum::getOnlineRate).average().orElse(0.0); diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index ed5a33c1..3e28caec 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java @@ -303,6 +303,27 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String // 将查询结果封装为成功响应并返回 return AjaxResult.success(mapList); } + /** + * 车流量异常事件流量查询 + * @param eventId 事件id + */ + @ApiOperation("车流量异常事件流量查询") + @GetMapping("/history/eventtrafficflowcnt") + public AjaxResult eventtrafficflowcnt(String eventId ) throws HttpException { + JSONArray mapList = dcTrafficStatisticsService.eventtrafficflowcnt(eventId); + // 将查询结果封装为成功响应并返回 + return AjaxResult.success(mapList); + } + /** + * 交通流统计分析重点数据查询交通流异常信息 + */ + @ApiOperation("交通流统计分析重点数据查询交通流异常信息") + @GetMapping("/history/exampleQueryTrafficFlowAnomalies") + public AjaxResult exampleQueryTrafficFlowAnomalies(String startTime,String endTime ) throws HttpException { + JSONArray mapList = dcTrafficStatisticsService.exampleQueryTrafficFlowAnomalies(startTime,endTime); + // 将查询结果封装为成功响应并返回 + return AjaxResult.success(mapList); + } /** * 导出车流量时段分析 diff --git a/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java index af568c98..ed5b2da8 100644 --- a/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java +++ b/zc-business/src/main/java/com/zc/business/domain/OnlineSum.java @@ -39,7 +39,7 @@ public class OnlineSum implements java.io.Serializable { @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @Excel(name = "统计日期", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss") - private LocalDate statisticalDate;//统计日期 + private LocalDateTime statisticalDate;//统计日期 private String deviceType;//设备类型 private int totalCount;//当天总次数 private int sendCount;//发送数据包总数 @@ -134,11 +134,11 @@ public class OnlineSum implements java.io.Serializable { this.networkQuality = networkQuality; } - public LocalDate getStatisticalDate() { + public LocalDateTime getStatisticalDate() { return statisticalDate; } - public void setStatisticalDate(LocalDate statisticalDate) { + public void setStatisticalDate(LocalDateTime statisticalDate) { this.statisticalDate = statisticalDate; } @@ -296,7 +296,7 @@ public class OnlineSum implements java.io.Serializable { this.networkQuality = onlineLog.getNetworkQuality(); if(this.deviceStatus.equals(DcDevice.ONLINE)) this.lastOnlineTime = onlineLog.getMonitorTime(); - this.statisticalDate = onlineLog.getMonitorTime().toLocalDate(); + this.statisticalDate = onlineLog.getMonitorTime(); return this; } diff --git a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java index 032ba26f..e4f1a166 100644 --- a/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java +++ b/zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java @@ -1789,6 +1789,11 @@ RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateB // 全路段双向实时车流量 /api/dc/query/gan_jihe_d_vehtypeflow THE_WHOLE_SECTION_TWO_WAY_REAL_TIME_TRAFFIC_FLOW_URL(0, "/api/dc/query/gan_jihe_d_vehtypeflow"), + //车流量异常事件流量查询 + QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS(0,"/api/dc/query/gan_jihe_d_eventtrafficflowcnt"), + // *交通流统计分析重点数据查询交通流异常信息 + TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY(0,"/api/dc/query/gan_jihe_d_trafficexception"), + // 雷达数据 http://www.nmc.cn/publish/radar/chinaall.html RADAR_DATA(0, "http://www.nmc.cn/publish/radar/chinaall.html"), diff --git a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java index 32b6fe4a..9a5cb3c7 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java @@ -65,4 +65,10 @@ public interface IDcTrafficStatisticsService { int trafficFlowAtToll(String startDate)throws HttpException, IOException; int yesterdayTrafficFlowAtToll(String startDate)throws HttpException, IOException; + + JSONArray eventtrafficflowcnt(String eventId) throws HttpException; + /** + * 交通流统计分析重点数据查询交通流异常信息 + */ + JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException; } 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 e0a40fc9..075f19cc 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 @@ -1368,6 +1368,97 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } + @Override + public JSONArray eventtrafficflowcnt(String eventId) throws HttpException { + + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + requestParams.put("sysid", sysid); + + JSONObject parameters = new JSONObject() { + { + put("event_id", eventId); + } + }; + + requestParams.put("parameters", parameters.toJSONString()); + + Map headers = new HashMap<>(); + headers.put("Authorization", getAccessToken()); + try { + Response response // 请求响应 + = okHttp + .headers(headers) + .url(baseUrl + UniversalEnum.QUERY_TRAFFIC_OF_ABNORMAL_TRAFFIC_EVENTS.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(); + } + } + /** + * 交通流统计分析重点数据查询交通流异常信息 + */ + @Override + public JSONArray exampleQueryTrafficFlowAnomalies(String startTime, String endTime) throws HttpException { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + requestParams.put("sysid", sysid); + + JSONObject parameters = new JSONObject() { + { + put("start_time", startTime); + put("end_time", endTime); + } + }; + + requestParams.put("parameters", parameters.toJSONString()); + + Map headers = new HashMap<>(); + headers.put("Authorization", getAccessToken()); + try { + Response response // 请求响应 + = okHttp + .headers(headers) + .url(baseUrl + UniversalEnum.TRAFFIC_FLOW_STATISTICAL_KEY_DATA_QUERY.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(); + } + } + + private Response getResponseTrafficFlowAtToll(String startDate, String stationType) throws HttpException, IOException { // 创建OkHttpClient.Builder实例 OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();