From a5b842f1f6ab32f1af39f4bcb7e45217e94db761 Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 25 十月 2025 18:14:44 +0800
Subject: [PATCH] fix:完成任务状态,任务同步,高度同步等工作

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 231 insertions(+), 1 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
index 5c3e134..5ae3359 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java
@@ -3,9 +3,14 @@
 import java.util.*;
 import java.text.SimpleDateFormat;
 import java.text.ParseException;
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
 
 import com.ruoyi.system.domain.*;
 import com.ruoyi.system.service.*;
+import com.ruoyi.common.config.TencentMapConfig;
+import com.ruoyi.common.config.BaiduMapConfig;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -24,6 +29,7 @@
 import com.ruoyi.common.enums.BusinessType;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.common.core.page.TableDataInfo;
+import com.ruoyi.common.utils.http.HttpUtils;
 
 /**
  * 杞﹁締GPS鍧愭爣Controller
@@ -51,6 +57,12 @@
 
     @Autowired
     private ICmsGpsCollectService cmsGpsCollectService;
+    
+    @Autowired
+    private TencentMapConfig tencentMapConfig;
+    
+    @Autowired
+    private BaiduMapConfig baiduMapConfig;
 
    /**
      * 鏌ヨ杞﹁締GPS鍧愭爣鍒楄〃
@@ -369,4 +381,222 @@
             throw new Error("鏌ヨ杞﹁締杞ㄨ抗澶辫触锛�" + e.getMessage());
         }
     }
-} 
\ No newline at end of file
+    
+    /**
+     * 鑵捐鍦板浘鍦板潃鎼滅储鎺ュ彛浠g悊
+     */
+    @Anonymous()
+    @GetMapping("/address/search")
+    public AjaxResult searchAddress(String keyword, String region) {
+        try {
+            // 鏋勫缓鑵捐鍦板浘鎼滅储API URL
+            String url = "https://apis.map.qq.com/ws/place/v1/search";
+            String params = "keyword=" + URLEncoder.encode(keyword, StandardCharsets.UTF_8.toString()) + 
+                           "&boundary=region(" + (region != null ? region : "骞垮窞") + ")" + 
+                           "&key=" + tencentMapConfig.getKey();
+            
+            // 鍙戦�丠TTP璇锋眰
+            String response = HttpUtils.sendGet(url, params);
+            
+            // 杩斿洖缁撴灉
+            return AjaxResult.success("鏌ヨ鎴愬姛", response);
+        } catch (Exception e) {
+            logger.error("鍦板潃鎼滅储澶辫触", e);
+            return AjaxResult.error("鍦板潃鎼滅储澶辫触锛�" + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鑵捐鍦板浘閫嗗湴鍧�瑙f瀽鎺ュ彛浠g悊
+     */
+    @Anonymous()
+    @GetMapping("/address/geocoder")
+    public AjaxResult reverseGeocoder(Double lat, Double lng) {
+        try {
+            // 妫�鏌ュ弬鏁�
+            logger.info("閫嗗湴鍧�瑙f瀽璇锋眰鍙傛暟: lat={}, lng={}", lat, lng);
+            
+            if (lat == null || lng == null) {
+                logger.warn("鍙傛暟涓嶅畬鏁达紝缂哄皯缁忕含搴﹀潗鏍�: lat={}, lng={}", lat, lng);
+                return AjaxResult.error("鍙傛暟涓嶅畬鏁达紝缂哄皯缁忕含搴﹀潗鏍�");
+            }
+            
+            // 妫�鏌ュ弬鏁版湁鏁堟��
+            if (Double.isNaN(lat) || Double.isNaN(lng) || 
+                Double.isInfinite(lat) || Double.isInfinite(lng)) {
+                logger.warn("鍙傛暟鏃犳晥锛岀粡绾害鍧愭爣鍖呭惈闈炴硶鍊�: lat={}, lng={}", lat, lng);
+                return AjaxResult.error("鍙傛暟鏃犳晥锛岀粡绾害鍧愭爣鏍煎紡閿欒");
+            }
+            
+            // 鏋勫缓鑵捐鍦板浘閫嗗湴鍧�瑙f瀽API URL
+            String url = "https://apis.map.qq.com/ws/geocoder/v1/";
+            String params = "location=" + lat + "," + lng + 
+                           "&key=" + tencentMapConfig.getKey() + 
+                           "&get_poi=1";
+            
+            // 鍙戦�丠TTP璇锋眰
+            String response = HttpUtils.sendGet(url, params);
+            
+            // 杩斿洖缁撴灉
+            return AjaxResult.success("鏌ヨ鎴愬姛", response);
+        } catch (Exception e) {
+            logger.error("閫嗗湴鍧�瑙f瀽澶辫触: lat={}, lng={}", lat, lng, e);
+            return AjaxResult.error("閫嗗湴鍧�瑙f瀽澶辫触锛�" + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鑵捐鍦板浘璺嚎瑙勫垝鎺ュ彛浠g悊锛堣绠椾袱鐐归棿璺濈锛�
+     */
+    @Anonymous()
+    @GetMapping("/route/distance")
+    public AjaxResult calculateDistance(Double fromLat, Double fromLng, Double toLat, Double toLng) {
+        try {
+            // 妫�鏌ュ弬鏁�
+            if (fromLat == null || fromLng == null || toLat == null || toLng == null) {
+                return AjaxResult.error("鍙傛暟涓嶅畬鏁达紝缂哄皯璧风偣鎴栫粓鐐瑰潗鏍�");
+            }
+            
+            // 鏋勫缓鑵捐鍦板浘璺嚎瑙勫垝API URL
+            String url = "https://apis.map.qq.com/ws/distance/v1/";
+            String params = "mode=driving" +
+                           "&from=" + fromLat + "," + fromLng +
+                           "&to=" + toLat + "," + toLng +
+                           "&key=" + tencentMapConfig.getKey();
+            
+            // 鍙戦�丠TTP璇锋眰
+            String response = HttpUtils.sendGet(url, params);
+            
+            // 杩斿洖缁撴灉
+            return AjaxResult.success("璁$畻鎴愬姛", response);
+        } catch (Exception e) {
+            logger.error("璺濈璁$畻澶辫触", e);
+            return AjaxResult.error("璺濈璁$畻澶辫触锛�" + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鐧惧害鍦板浘鍦扮悊缂栫爜鎺ュ彛浠g悊锛堝湴鍧�杞潗鏍囷級
+     */
+    @Anonymous()
+    @GetMapping("/baidu/geocoding")
+    public AjaxResult baiduGeocoding(String address, String city) {
+        try {
+            // 妫�鏌ュ弬鏁�
+            if (address == null || address.trim().isEmpty()) {
+                return AjaxResult.error("鍙傛暟涓嶅畬鏁达紝缂哄皯鍦板潃淇℃伅");
+            }
+            
+            // 鏋勫缓鐧惧害鍦板浘鍦扮悊缂栫爜API URL
+            String url = "https://api.map.baidu.com/geocoding/v3/";
+            String params = "address=" + URLEncoder.encode(address, StandardCharsets.UTF_8.toString()) +
+                           (city != null && !city.trim().isEmpty() ? 
+                            "&city=" + URLEncoder.encode(city, StandardCharsets.UTF_8.toString()) : "") +
+                           "&output=json" +
+                           "&ak=" + baiduMapConfig.getAk();
+            
+            logger.info("鐧惧害鍦板浘鍦扮悊缂栫爜璇锋眰: address={}, city={}", address, city);
+            
+            // 鍙戦�丠TTP璇锋眰
+            String response = HttpUtils.sendGet(url, params);
+            
+            // 杩斿洖缁撴灉
+            return AjaxResult.success("鏌ヨ鎴愬姛", response);
+        } catch (Exception e) {
+            logger.error("鐧惧害鍦板浘鍦扮悊缂栫爜澶辫触", e);
+            return AjaxResult.error("鍦扮悊缂栫爜澶辫触锛�" + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鐧惧害鍦板浘璺嚎瑙勫垝鎺ュ彛浠g悊锛堣绠椾袱涓潗鏍囦箣闂寸殑椹捐溅璺濈锛�
+     */
+    @Anonymous()
+    @GetMapping("/baidu/route/driving")
+    public AjaxResult baiduRouteDriving(String origin, String destination) {
+        try {
+            // 妫�鏌ュ弬鏁�
+            if (origin == null || origin.trim().isEmpty() || 
+                destination == null || destination.trim().isEmpty()) {
+                return AjaxResult.error("鍙傛暟涓嶅畬鏁达紝缂哄皯璧风偣鎴栫粓鐐瑰潗鏍�");
+            }
+            
+            // 楠岃瘉鍧愭爣鏍煎紡锛堢含搴�,缁忓害锛�
+            String[] originParts = origin.split(",");
+            String[] destParts = destination.split(",");
+            if (originParts.length != 2 || destParts.length != 2) {
+                return AjaxResult.error("鍧愭爣鏍煎紡閿欒锛屽簲涓猴細绾害,缁忓害");
+            }
+            
+            // 鏋勫缓鐧惧害鍦板浘璺嚎瑙勫垝API URL
+            String url = "https://api.map.baidu.com/directionlite/v1/driving";
+            String params = "origin=" + origin +
+                           "&destination=" + destination +
+                           "&ak=" + baiduMapConfig.getAk();
+            
+            logger.info("鐧惧害鍦板浘璺嚎瑙勫垝璇锋眰: origin={}, destination={}", origin, destination);
+            
+            // 鍙戦�丠TTP璇锋眰
+            String response = HttpUtils.sendGet(url, params);
+            
+            // 杩斿洖缁撴灉
+            return AjaxResult.success("璁$畻鎴愬姛", response);
+        } catch (Exception e) {
+            logger.error("鐧惧害鍦板浘璺嚎瑙勫垝澶辫触", e);
+            return AjaxResult.error("璺嚎瑙勫垝澶辫触锛�" + e.getMessage());
+        }
+    }
+    
+    /**
+     * 鐧惧害鍦板浘璁$畻涓や釜鍦板潃涔嬮棿鐨勮窛绂伙紙缁勫悎鎺ュ彛锛氬湴鍧�杞潗鏍� + 璺嚎瑙勫垝锛�
+     */
+    @Anonymous()
+    @GetMapping("/baidu/distance/byAddress")
+    public AjaxResult baiduDistanceByAddress(String fromAddress, String fromCity, 
+                                             String toAddress, String toCity) {
+        try {
+            // 妫�鏌ュ弬鏁�
+            if (fromAddress == null || fromAddress.trim().isEmpty() || 
+                toAddress == null || toAddress.trim().isEmpty()) {
+                return AjaxResult.error("鍙傛暟涓嶅畬鏁达紝缂哄皯璧风偣鎴栫粓鐐瑰湴鍧�");
+            }
+            
+            logger.info("寮�濮嬭绠楀湴鍧�璺濈: fromAddress={}, fromCity={}, toAddress={}, toCity={}", 
+                       fromAddress, fromCity, toAddress, toCity);
+            
+            // 绗竴姝ワ細璧风偣鍦板潃杞潗鏍�
+            String geocodingUrl1 = "https://api.map.baidu.com/geocoding/v3/";
+            String geocodingParams1 = "address=" + URLEncoder.encode(fromAddress, StandardCharsets.UTF_8.toString()) +
+                                     (fromCity != null && !fromCity.trim().isEmpty() ? 
+                                      "&city=" + URLEncoder.encode(fromCity, StandardCharsets.UTF_8.toString()) : "") +
+                                     "&output=json" +
+                                     "&ak=" + baiduMapConfig.getAk();
+            
+            String geocodingResponse1 = HttpUtils.sendGet(geocodingUrl1, geocodingParams1);
+            logger.info("璧风偣鍦扮悊缂栫爜鍝嶅簲: {}", geocodingResponse1);
+            
+            // 绗簩姝ワ細缁堢偣鍦板潃杞潗鏍�
+            String geocodingUrl2 = "https://api.map.baidu.com/geocoding/v3/";
+            String geocodingParams2 = "address=" + URLEncoder.encode(toAddress, StandardCharsets.UTF_8.toString()) +
+                                     (toCity != null && !toCity.trim().isEmpty() ? 
+                                      "&city=" + URLEncoder.encode(toCity, StandardCharsets.UTF_8.toString()) : "") +
+                                     "&output=json" +
+                                     "&ak=" + baiduMapConfig.getAk();
+            
+            String geocodingResponse2 = HttpUtils.sendGet(geocodingUrl2, geocodingParams2);
+            logger.info("缁堢偣鍦扮悊缂栫爜鍝嶅簲: {}", geocodingResponse2);
+            
+            // 瑙f瀽鍧愭爣锛堣繖閲岀畝鍖栧鐞嗭紝瀹為檯搴旇瑙f瀽JSON锛�
+            // 娉ㄦ剰锛氶渶瑕佷粠鍝嶅簲涓彁鍙栧潗鏍囷紝杩欓噷杩斿洖涓棿缁撴灉渚涘墠绔鐞�
+            Map<String, Object> result = new HashMap<>();
+            result.put("fromGeocoding", geocodingResponse1);
+            result.put("toGeocoding", geocodingResponse2);
+            result.put("message", "璇疯В鏋愬潗鏍囧悗璋冪敤 /baidu/route/driving 鎺ュ彛璁$畻璺濈");
+            
+            return AjaxResult.success("鍦扮悊缂栫爜鎴愬姛", result);
+        } catch (Exception e) {
+            logger.error("璁$畻鍦板潃璺濈澶辫触", e);
+            return AjaxResult.error("璁$畻璺濈澶辫触锛�" + e.getMessage());
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1