From d79f7128f03c354750f8a1f4c694c4e07dff14e1 Mon Sep 17 00:00:00 2001 From: aikai Date: Mon, 30 Jun 2025 11:42:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(system):=20=E7=A7=BB=E9=99=A4=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E9=80=86=E8=A7=A3=E6=9E=90=E7=9B=B8=E5=85=B3=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 删除了 yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/address/AddressUtil.java 文件- 移除了 yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/attendance/AttendanceController.java 中的 addressInverseResolution 方法 --- .../common/util/address/AddressUtil.java | 82 ------------------- .../attendance/AttendanceController.java | 18 ---- 2 files changed, 100 deletions(-) delete mode 100644 yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/address/AddressUtil.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/address/AddressUtil.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/address/AddressUtil.java deleted file mode 100644 index 9fd92083..00000000 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/address/AddressUtil.java +++ /dev/null @@ -1,82 +0,0 @@ -package cn.iocoder.yudao.framework.common.util.address; - -import java.io.BufferedReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - -public class AddressUtil { - - // 替换成您在天地图官网申请的密钥 - private static final String API_KEY = "e11694af0e347f991a0b18f10f2491d3"; - - public static void main(String[] args) { - // 示例经纬度(深圳腾讯大厦) - double longitude = 115.43835; - double latitude = 28.200279; - // 35.88052,114.8731 - try { - String result = reverseGeocode(longitude, latitude); - System.out.println("逆地理编码结果:"); - System.out.println(result); - } catch (Exception e) { - System.err.println("逆地理编码失败:"); - e.printStackTrace(); - } - } - - - public static String reverseGeocode(double longitude, double latitude) throws Exception { - // 1. 构建请求参数(注意使用双引号) - String postStr = String.format("{\"lon\":%f,\"lat\":%f,\"ver\":2}", longitude, latitude); - - // 2. URL编码参数 - String encodedPostStr = URLEncoder.encode(postStr, StandardCharsets.UTF_8.name()); - - // 3. 构建完整URL - String urlStr = "http://api.tianditu.gov.cn/geocoder?postStr=" + encodedPostStr - + "&type=geocode&tk=" + API_KEY; - - // 4. 创建HTTP连接 - URL url = new URL(urlStr); - HttpURLConnection conn = (HttpURLConnection) url.openConnection(); - conn.setRequestMethod("GET"); - - // 5. 设置请求头(模拟浏览器访问) - conn.setRequestProperty("User-Agent", "Mozilla/5.0"); - conn.setRequestProperty("Accept", "application/json"); - - // 6. 获取响应 - int responseCode = conn.getResponseCode(); - - if (responseCode == HttpURLConnection.HTTP_OK) { - // 读取成功响应 - try (BufferedReader reader = new BufferedReader( - new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8))) { - - StringBuilder response = new StringBuilder(); - String line; - while ((line = reader.readLine()) != null) { - response.append(line); - } - return response.toString(); - } - } else { - // 读取错误信息 - try (BufferedReader errorReader = new BufferedReader( - new InputStreamReader(conn.getErrorStream(), StandardCharsets.UTF_8))) { - - StringBuilder errorResponse = new StringBuilder(); - String line; - while ((line = errorReader.readLine()) != null) { - errorResponse.append(line); - } - - throw new RuntimeException("API请求失败: HTTP " + responseCode - + "\n错误详情: " + errorResponse.toString()); - } - } - } -} diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/attendance/AttendanceController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/attendance/AttendanceController.java index 62380597..23034a63 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/attendance/AttendanceController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/attendance/AttendanceController.java @@ -1,12 +1,9 @@ package cn.iocoder.yudao.module.system.controller.admin.attendance; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.util.address.AddressUtil; import cn.iocoder.yudao.module.system.controller.admin.attendance.dto.*; import cn.iocoder.yudao.module.system.controller.admin.attendance.vo.*; import cn.iocoder.yudao.module.system.service.attendance.AttendanceService; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.validation.annotation.Validated; @@ -123,19 +120,4 @@ public class AttendanceController { return success("ok"); } - - @GetMapping("/addressInverseResolution") - @Operation(summary = "地址逆解析") - @PermitAll - public CommonResult addressInverseResolution(@RequestParam(name = "longitude") double longitude, @RequestParam(name = "latitude") double latitude) { - String result = ""; - try { - result = AddressUtil.reverseGeocode(longitude, latitude); - } catch (Exception e) { - System.err.println("逆地理编码失败:"); - e.printStackTrace(); - } - JSONObject jsonObject = JSON.parseObject(result); - return success(jsonObject); - } }