From fd878186d55ff5d2fe721d83cbe43eeb1b344470 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=85=B4=E7=90=B3?= <1911390090@qq.com> Date: Mon, 1 Jul 2024 11:12:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=A5=E5=A0=B5=E8=B7=AF=E6=AE=B5=20?= =?UTF-8?q?=E6=A1=A9=E5=8F=B7(=E4=BF=AE=E6=94=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DcTrafficStatisticsServiceImpl.java | 81 ++++++++++++------- 1 file changed, 51 insertions(+), 30 deletions(-) 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 d0a982c6..0b638334 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 @@ -700,7 +700,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } @Override - public Map>> realTimeTrafficFlowHour() throws HttpException, IOException { + public Map>> realTimeTrafficFlowHour() throws HttpException, IOException { DateTimeFormatter formatter = DateTimeFormatter.ofPattern(UniversalEnum.TIME_FORMAT_YEARS_MONTH_DAY.getValue()); LocalDate currentDate = LocalDate.now(); @@ -717,24 +717,25 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi JSONArray body = getResponseBody(nowYear, requestParams, okHttp); JSONArray bodylast = getResponseBody(lastYear, requestParams, okHttp); - Map>> map = new HashMap<>(); + Map>> map = new HashMap<>(); if (body != null) { List> mapList = getMaps(UniversalEnum.ONE.getValue(), body); - map.put(UniversalEnum.ONE.getValue(),mapList); + map.put(UniversalEnum.ONE.getValue(), mapList); List> mapList2 = getMaps(UniversalEnum.THREE.getValue(), body); - map.put(UniversalEnum.TWO.getValue(),mapList2); + map.put(UniversalEnum.TWO.getValue(), mapList2); } if (bodylast != null) { List> mapList = getMaps(UniversalEnum.ONE.getValue(), bodylast); - map.put(UniversalEnum.THREE.getValue(),mapList); + map.put(UniversalEnum.THREE.getValue(), mapList); List> mapList2 = getMaps(UniversalEnum.THREE.getValue(), bodylast); - map.put(UniversalEnum.FOUR.getValue(),mapList2); + map.put(UniversalEnum.FOUR.getValue(), mapList2); } return map; } -//处理 接口响应数据 + + //处理 接口响应数据 private List> getMaps(String direction, JSONArray jsonArray) throws IOException { @@ -792,7 +793,8 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } return mapList; } -// 获取车流量接口 返回 jsonArray + + // 获取车流量接口 返回 jsonArray private JSONArray getResponseBody(String startDate, RequestParams requestParams, OkHttp okHttp) throws HttpException, IOException { JSONObject parameters = new JSONObject() { { @@ -812,10 +814,10 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi .post(); // 请求方法 ResponseBody body = response.body(); JSONArray jsonArray = JSON.parseArray(body.string()); - return jsonArray; + return jsonArray; } -//格式化桩号 + //格式化桩号 private static String extract(String input) { Pattern pattern = Pattern.compile("K(\\d{3})\\+(\\d{3})"); Matcher matcher = pattern.matcher(input); @@ -839,17 +841,17 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return UniversalEnum.EMPTY_STRING.getValue(); } - public List> queryTheGantryDataByPileNumber(String startDate,String stakeMark) throws HttpException, IOException { + public List> queryTheGantryDataByPileNumber(String startDate, String stakeMark) throws HttpException, IOException { if (stakeMark != null) { //处理URl地址栏获取参数+号消失 - stakeMark= stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()); + stakeMark = stakeMark.replace(UniversalEnum.BLANK_SPACE.getValue(), UniversalEnum.PLUS_SIGN.getValue()); } - List> mapList =new ArrayList<>(); + List> mapList = new ArrayList<>(); DcFacility dcFacilityAll = new DcFacility(); dcFacilityAll.setFacilityType(UniversalEnum.TEN.getNumber()); List dcFacilityList = facilityService.listFacility(dcFacilityAll); - DcFacility nearestFacility = findNearestFacility(dcFacilityList,stakeMark); + DcFacility nearestFacility = findNearestFacility(dcFacilityList, stakeMark); OkHttp okHttp = new OkHttp(); @@ -882,13 +884,13 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi System.out.println(jsonArray); for (Object item : jsonArray) { JSONObject jsonObject = (JSONObject) item; - if (jsonObject.getString("gantry_id").equals(nearestFacility.getFacilityCode())) { - Map map = new HashMap<>(); - int totalFlow = jsonObject.getInteger("total_flow"); - int data_hour = jsonObject.getInteger("data_hour"); - map.put("hour",data_hour); - map.put("totalFlow",totalFlow); - mapList.add(map); + if (jsonObject.getString("gantry_id").equals(nearestFacility.getFacilityCode())) { + Map map = new HashMap<>(); + int totalFlow = jsonObject.getInteger("total_flow"); + int data_hour = jsonObject.getInteger("data_hour"); + map.put("hour", data_hour); + map.put("totalFlow", totalFlow); + mapList.add(map); } } @@ -902,12 +904,13 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi /** * 获取路况信息 + * * @return * @throws HttpException * @throws IOException */ @Override - public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException { + public JSONArray getTheCurrentCongestedSection() throws HttpException, IOException { OkHttp okHttp = new OkHttp(); RequestParams requestParams = new RequestParams(); @@ -930,9 +933,16 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi for (Object object : jsonArray) { JSONObject jsonObject = (JSONObject) object; Integer asOneRoad = jsonObject.getInteger("as_one_road"); + double endPileNo = jsonObject.getDouble("end_pile_no"); + double startPileNo = jsonObject.getDouble("start_pile_no"); + String stakeMark = formatNumber(startPileNo); + String endMark = formatNumber(endPileNo); + jsonObject.put("stakeMark", stakeMark);//当前拥堵距离 + jsonObject.put("endMark", endMark);//当前拥堵距离 + //as_one_road //是否为同一条路,1-是,0-否 - if (asOneRoad == UniversalEnum.ZERO.getNumber()){ + if (asOneRoad == UniversalEnum.ZERO.getNumber()) { String string = jsonObject.getString("list_link_info"); JSONArray jsonlist = JSON.parseArray(string); @@ -944,11 +954,11 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi String[] lngLatsString = lngLats.split(";"); double s = Double.parseDouble(lngLatsString[0].split(",")[0]); double s2 = Double.parseDouble(lngLatsString[0].split(",")[1]); - double s3 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[0]); - double s4 = Double.parseDouble(lngLatsString[lngLatsString.length-1].split(",")[1]); - double distanceM = calculateDistance(s2, s, s4, s3)* 1000; + double s3 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[0]); + double s4 = Double.parseDouble(lngLatsString[lngLatsString.length - 1].split(",")[1]); + double distanceM = calculateDistance(s2, s, s4, s3) * 1000; // System.out.printf("最大距离为: %.2f 米%n", distanceM); - jsonObject.put("max_jam_dist",distanceM);//最大拥堵距离 + jsonObject.put("max_jam_dist", distanceM);//最大拥堵距离 String[] split = string1.split(","); double firstLon = Double.parseDouble(split[0]); double firstLat = Double.parseDouble(split[1]); @@ -962,12 +972,12 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi double distanceKm = calculateDistance(firstLat, firstLon, lastLat, lastLon); double distanceMeters = distanceKm * 1000; // 将距离转换为米 //System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters); - jsonObject.put("jam_dist",distanceMeters);//当前拥堵距离 + jsonObject.put("jam_dist", distanceMeters);//当前拥堵距离 } } - return jsonArray; + return jsonArray; } @@ -999,6 +1009,17 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return nearestFacility; // 返回最近的桩号信息 } + + //桩号转换 + public static String formatNumber(double number) { +//将数字分成整数和四舍五入的小数部分 + int integerPart = (int) number; + int decimalPart = (int) Math.round((number - integerPart) * 1000); // 四舍五入到最接近的整数 + + // 将数字格式化为 "K 000+000" + String formattedString = String.format("K%03d+%03d", integerPart, decimalPart); + return formattedString; + } //经纬度计算距离 public static double calculateDistance(double startLat, double startLon, double endLat, double endLon) { @@ -1022,7 +1043,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi // 计算两点间的距离 double distance = EARTH_RADIUS * c; // 保留两位小数,四舍五入 - distance= Double.parseDouble(String.format("%.5f", distance)); + distance = Double.parseDouble(String.format("%.5f", distance)); return distance; }