From 55aaf213477e2068cceb78793baf5813815f52cd 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 08:50:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8B=A5=E5=A0=B5=E8=B7=AF=E6=AE=B5=20?= =?UTF-8?q?=E8=B7=9D=E7=A6=BB=E8=AE=A1=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/src/views/text/index.vue | 157 ++++++++++++++++++ .../impl/DcTrafficStatisticsServiceImpl.java | 67 +++++++- 2 files changed, 218 insertions(+), 6 deletions(-) create mode 100644 ruoyi-ui/src/views/text/index.vue diff --git a/ruoyi-ui/src/views/text/index.vue b/ruoyi-ui/src/views/text/index.vue new file mode 100644 index 00000000..819f50f7 --- /dev/null +++ b/ruoyi-ui/src/views/text/index.vue @@ -0,0 +1,157 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 3dae3729..206c43f3 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 @@ -43,6 +43,9 @@ import java.util.regex.Pattern; @Service public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsService { + // 地球平均半径,单位为公里 + private static final double EARTH_RADIUS = 6371.0; + // 日志记录器 protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -928,8 +931,37 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi Integer asOneRoad = jsonObject.getInteger("as_one_road"); if (asOneRoad == UniversalEnum.ONE.getNumber()){ - String string = jsonObject.getString("road_name"); - System.out.println(string); + + String string = jsonObject.getString("list_link_info"); + JSONArray jsonlist = JSON.parseArray(string); + JSONObject o = (JSONObject) jsonlist.get(0); + + String string1 = o.getString("firstPoint"); + String string2 = o.getString("lastPoint"); + String lngLats = o.getString("lngLats"); + 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; + // System.out.printf("最大距离为: %.2f 米%n", distanceM); + jsonObject.put("max_jam_dist",distanceM);//最大拥堵距离 + String[] split = string1.split(","); + double firstLon = Double.parseDouble(split[0]); + double firstLat = Double.parseDouble(split[1]); + String[] split2 = string2.split(","); + double lastLon = Double.parseDouble(split2[0]); + double lastLat = Double.parseDouble(split2[1]); + //double firstLat = 35.38524527319016; + // double firstLon = 118.39808642864227; + //double lastLat = 35.386351346969604; + // double lastLon = 118.4038907289505; + double distanceKm = calculateDistance(firstLat, firstLon, lastLat, lastLon); + double distanceMeters = distanceKm * 1000; // 将距离转换为米 + //System.out.printf("两点之间的距离为: %.2f 米%n", distanceMeters); + jsonObject.put("jam_dist",distanceMeters);//当前拥堵距离 + return jsonObject; }else { @@ -942,7 +974,7 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi } public DcFacility findNearestFacility(List dcFacilityList, String stakeMarkCode) { - // 将目标桩号转换为整数,以便比较 + // 将目标桩号转换为整数 int targetCodeAsInt = Integer.parseInt(extract(stakeMarkCode)); DcFacility nearestFacility = null; @@ -950,11 +982,9 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi for (DcFacility facility : dcFacilityList) { // 假设每个DcFacility对象中有一个方法或直接字段可以获取处理后的桩号字符串 - String stakeMark = facility.getStakeMark(); // 请替换为实际的getter方法名 - + String stakeMark = facility.getStakeMark(); // 将当前设施的桩号转换为整数 int currentCodeAsInt = Integer.parseInt(extract(stakeMark)); - // 计算与目标桩号的距离(差值的绝对值) int distance = Math.abs(targetCodeAsInt - currentCodeAsInt); @@ -967,5 +997,30 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return nearestFacility; // 返回最近的桩号信息 } +//经纬度计算距离 + + public static double calculateDistance(double startLat, double startLon, double endLat, double endLon) { + + // 将角度转换为弧度 + double startLatRad = Math.toRadians(startLat); + double startLonRad = Math.toRadians(startLon); + double endLatRad = Math.toRadians(endLat); + double endLonRad = Math.toRadians(endLon); + + // 经纬度之差 + double dLat = endLatRad - startLatRad; + double dLon = endLonRad - startLonRad; + + // Haversine公式 + double a = Math.pow(Math.sin(dLat / 2), 2) + + Math.cos(startLatRad) * Math.cos(endLatRad) * + Math.pow(Math.sin(dLon / 2), 2); + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + // 计算两点间的距离 + double distance = EARTH_RADIUS * c; + + return distance; + } }