From fa630ed55dae16a78f4b5c43a311208c49d679d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Sat, 29 Jun 2024 09:13:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=A5=E5=A0=B5=E8=B7=AF=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DcTrafficStatisticsController.java | 10 ++++ .../device/handler/DeviceMessageHandler.java | 2 +- .../service/IDcTrafficStatisticsService.java | 3 ++ .../impl/DcTrafficStatisticsServiceImpl.java | 48 ++++++++++++++++++- 4 files changed, 60 insertions(+), 3 deletions(-) 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 a6b8187b..4f1f0f8c 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 @@ -1,6 +1,7 @@ package com.zc.business.controller; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; @@ -571,6 +572,15 @@ public AjaxResult realTimeTrafficFlow(String startDate, String direction,String return AjaxResult.success(jsonArray); } + @ApiOperation("获取当前拥堵路段") + @GetMapping("/current/getTheCurrentCongestedSection") + public AjaxResult getTheCurrentCongestedSection() throws HttpException, IOException { + // 调用服务层方法,获取当前交通指标数据 + JSONObject jsonArray = dcTrafficStatisticsService.getTheCurrentCongestedSection(); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(jsonArray); + } + /** * 获取当前拥堵路段信息 * diff --git a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java index 587987ed..6c7a8dbb 100644 --- a/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java +++ b/zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java @@ -587,7 +587,7 @@ public class DeviceMessageHandler { //设备名称 - meteorologicalDetectorData.setDeviceName(deviceName); + meteorologicalDetectorData.setDeviceName(deviceName+"("+stakeMark+")"); //位置 meteorologicalDetectorData.setStakeMark(stakeMark); //方向 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 ae157d4f..2ffe7473 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 @@ -1,6 +1,7 @@ package com.zc.business.service; import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.zc.business.domain.DcRoadSectionCongestion; import com.zc.common.core.httpclient.exception.HttpException; @@ -55,4 +56,6 @@ public interface IDcTrafficStatisticsService { Map>> realTimeTrafficFlowHour() throws HttpException, IOException; List> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException; + JSONObject getTheCurrentCongestedSection()throws HttpException, IOException; + } 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 000ee932..3dae3729 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 @@ -269,7 +269,6 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi if (body != null) { return JSON.parseArray(body.string()); } - return new JSONArray(); } @@ -813,7 +812,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return jsonArray; } - +//格式化桩号 private static String extract(String input) { Pattern pattern = Pattern.compile("K(\\d{3})\\+(\\d{3})"); Matcher matcher = pattern.matcher(input); @@ -897,6 +896,51 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return null; } + + /** + * 获取路况信息 + * @return + * @throws HttpException + * @throws IOException + */ + @Override + public JSONObject getTheCurrentCongestedSection() throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + requestParams.put("sysid", sysid); + + Map headers = new HashMap<>(); + headers.put("Authorization", getAccessToken()); + + Response response // 请求响应 + = okHttp + .headers(headers) + .url(baseUrl + "/api/dc/query/rd_tr_congestion_jh") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + ResponseBody body = response.body(); + if (body != null) { + JSONArray jsonArray = JSON.parseArray(body.string()); + JSONObject jsonObject = (JSONObject) jsonArray.get(0); + Integer asOneRoad = jsonObject.getInteger("as_one_road"); + + if (asOneRoad == UniversalEnum.ONE.getNumber()){ + String string = jsonObject.getString("road_name"); + System.out.println(string); + return jsonObject; + }else { + + } + + } + + return new JSONObject(); + + } + public DcFacility findNearestFacility(List dcFacilityList, String stakeMarkCode) { // 将目标桩号转换为整数,以便比较 int targetCodeAsInt = Integer.parseInt(extract(stakeMarkCode));