无关风月
1 天以前 1fd6775420288be4dce934fe845328e9501bf023
bug修改,增加坐标系转换
4个文件已修改
2个文件已添加
168 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCleanerController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLocationController.java 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/CoordinateTransform.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/HighPrecisionCoordinateTransformUtil.java 60 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-applet/src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TCleanerController.java
@@ -130,9 +130,9 @@
        for (TCleanerImportExcel locationExcel : locationExcelList) {
            System.err.println(locationExcel);
            TCleaner tCleaner = new TCleaner();
            TProjectDept projectDept = projects.stream().filter(e -> e.getProjectName().equals(locationExcel.getProjectName())).findFirst().orElse(null);
            TProjectDept projectDept = projects.stream().filter(e -> e.getCode().equals(locationExcel.getCleanerCode())).findFirst().orElse(null);
            if (projectDept==null){
                result.append("保洁员:[", locationExcel.getCleanerName()+"]未查询到部门");
                result.append("保洁员:[", locationExcel.getCleanerName()+"]未查询到片区");
                continue;
            }else{
                if (projectDept.getParentId().equals("0")){
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLocationController.java
@@ -27,6 +27,7 @@
import com.ruoyi.system.service.*;
import com.ruoyi.system.utils.CustomerImportFailedData;
import com.ruoyi.system.vo.system.*;
import com.ruoyi.web.controller.tool.HighPrecisionCoordinateTransformUtil;
import com.sun.org.apache.bcel.internal.generic.NEW;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
@@ -405,12 +406,15 @@
            }
            location.setLocationAddress(locationExcel.getLocationAddress());
            String[] addressLonLat = locationExcel.getLocationAddressLonLat().split("/");
            location.setLocationLon(addressLonLat[0]);
            location.setLocationLat(addressLonLat[1]);
            double[] start = HighPrecisionCoordinateTransformUtil.wgs84ToGcj02ViaGaode(Double.parseDouble(addressLonLat[1]), Double.parseDouble(addressLonLat[0]));
            location.setLocationLon(String.valueOf(start[1]));
            location.setLocationLat(String.valueOf(start[0]));
            location.setLocationAddressEnd(locationExcel.getLocationAddressEnd());
            String[] addressEndLonLat = locationExcel.getLocationAddressEndLonLat().split("/");
            location.setLocationLonEnd(addressEndLonLat[0]);
            location.setLocationLatEnd(addressEndLonLat[1]);
            double[] end = HighPrecisionCoordinateTransformUtil.wgs84ToGcj02ViaGaode(Double.parseDouble(addressEndLonLat[1]), Double.parseDouble(addressEndLonLat[0]));
            location.setLocationLonEnd(String.valueOf(end[1]));
            location.setLocationLatEnd(String.valueOf(end[0]));
            TProjectDept projectDept = deptList.stream().filter(dept -> dept.getCode().equals(locationExcel.getDeptCode())).findFirst().orElse(null);
            if(Objects.nonNull(projectDept)){
                location.setProjectId(projectDept.getId());
@@ -425,7 +429,8 @@
                result.append("路段名:[", locationExcel.getLocationName()+"]未查询到点位负责人");
                continue;
            }
            TCleaner tCleaner = cleaners.stream().filter(cleaner -> cleaner.getCleanerCode().equals(locationExcel.getCleanerCodeClear())
            TCleaner tCleaner = cleaners.stream().filter(cleaner -> cleaner.getCleanerCode().equals(
                    locationExcel.getCleanerCodeClear())
                    && cleaner.getDeptCode().equals(locationExcel.getDeptCodeClear())
                    && cleaner.getProjectCode().equals(locationExcel.getProjectCodeClear())
                    && cleaner.getCleanerName().equals(locationExcel.getCleanerName())).findFirst().orElse(null);
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/CoordinateTransform.java
New file
@@ -0,0 +1,85 @@
package com.ruoyi.web.controller.tool;
public class CoordinateTransform {
    private static final double PI = 3.1415926535897932384626;
    private static final double A = 6378245.0;
    private static final double EE = 0.00669342162296594323;
    private static final double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
    /**
     * WGS84转GCJ-02坐标
     * @param wgLat WGS84坐标纬度
     * @param wgLon WGS84坐标经度
     * @return 转换后的GCJ-02坐标[纬度, 经度]
     */
    public static double[] wgs84ToGcj02(double wgLat, double wgLon) {
        if (outOfChina(wgLat, wgLon)) {
            return new double[]{wgLat, wgLon};
        }
        double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);
        double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);
        double radLat = wgLat / 180.0 * PI;
        double magic = Math.sin(radLat);
        magic = 1 - EE * magic * magic;
        double sqrtMagic = Math.sqrt(magic);
        dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI);
        dLon = (dLon * 180.0) / (A / sqrtMagic * Math.cos(radLat) * PI);
        double mgLat = wgLat + dLat;
        double mgLon = wgLon + dLon;
        return new double[]{mgLat, mgLon};
    }
    /**
     * GCJ-02转BD09坐标(百度坐标系,腾讯地图部分接口可能使用)
     * @param ggLat GCJ-02坐标纬度
     * @param ggLon GCJ-02坐标经度
     * @return 转换后的BD09坐标[纬度, 经度]
     */
    public static double[] gcj02ToBd09(double ggLat, double ggLon) {
        double x = ggLon, y = ggLat;
        double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * X_PI);
        double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * X_PI);
        double bdLon = z * Math.cos(theta) + 0.0065;
        double bdLat = z * Math.sin(theta) + 0.006;
        return new double[]{bdLat, bdLon};
    }
    /**
     * WGS84直接转BD09坐标
     * @param wgLat WGS84坐标纬度
     * @param wgLon WGS84坐标经度
     * @return 转换后的BD09坐标[纬度, 经度]
     */
    public static double[] wgs84ToBd09(double wgLat, double wgLon) {
        double[] gcj02 = wgs84ToGcj02(wgLat, wgLon);
        return gcj02ToBd09(gcj02[0], gcj02[1]);
    }
    private static boolean outOfChina(double lat, double lon) {
        if (lon < 72.004 || lon > 137.8347)
            return true;
        if (lat < 0.8293 || lat > 55.8271)
            return true;
        return false;
    }
    private static double transformLat(double x, double y) {
        double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
        ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
        return ret;
    }
    private static double transformLon(double x, double y) {
        double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
        ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
        ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
        ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
        return ret;
    }
    // 测试方法
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/HighPrecisionCoordinateTransformUtil.java
New file
@@ -0,0 +1,60 @@
package com.ruoyi.web.controller.tool;
import okhttp3.*;
import com.alibaba.fastjson.JSONObject;
import java.io.IOException;
public class HighPrecisionCoordinateTransformUtil {
    private static final String GAODE_API_KEY = "e700a58329a38b2d8980790d9b1b5b06"; // 需要申请高德地图API Key
    private static final String GAODE_CONVERT_URL = "https://restapi.amap.com/v3/assistant/coordinate/convert";
    private static final OkHttpClient client = new OkHttpClient();
    /**
     * 使用高德地图API进行高精度坐标转换 WGS84 -> GCJ-02
     * @param wgLat WGS84纬度
     * @param wgLon WGS84经度
     * @return 转换后的GCJ-02坐标 [纬度, 经度]
     */
    public static double[] wgs84ToGcj02ViaGaode(double wgLat, double wgLon) {
        String url = GAODE_CONVERT_URL +
            "?locations=" + wgLon + "," + wgLat +
            "&coordsys=gps" +
            "&output=json" +
            "&key=" + GAODE_API_KEY;
        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        try {
            Response response = client.newCall(request).execute();
            if (response.isSuccessful() && response.body() != null) {
                String responseBody = response.body().string();
                JSONObject jsonObject = JSONObject.parseObject(responseBody);
                if ("1".equals(jsonObject.getString("status"))) {
                    String[] locations = jsonObject.getString("locations").split(",");
                    // 返回格式: [纬度, 经度]
                    return new double[]{
                        Double.parseDouble(locations[1]), // 纬度
                        Double.parseDouble(locations[0])  // 经度
                    };
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        // API调用失败时回退到原来的算法
        return CoordinateTransform.wgs84ToGcj02(wgLat, wgLon);
    }
    /**
     * 测试方法
     */
}
ruoyi-admin/src/main/resources/application.yml
@@ -1,4 +1,4 @@
# 项目相关配置
spring:
  profiles:
    active: test
    active: prod
ruoyi-applet/src/main/resources/application.yml
@@ -1,4 +1,4 @@
# 项目相关配置
spring:
  profiles:
    active: test
    active: prod