From b46065a201c09ce69f111806f2bda4a5f476bc4e Mon Sep 17 00:00:00 2001
From: wlzboy <66905212@qq.com>
Date: 星期六, 18 十月 2025 17:20:22 +0800
Subject: [PATCH] fix:用户同步,机构同步

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/VehicleGpsController.java |  118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 113 insertions(+), 5 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 f966940..80726d4 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,13 @@
 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 org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.GetMapping;
@@ -24,6 +28,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 +56,9 @@
 
     @Autowired
     private ICmsGpsCollectService cmsGpsCollectService;
+    
+    @Autowired
+    private TencentMapConfig tencentMapConfig;
 
    /**
      * 鏌ヨ杞﹁締GPS鍧愭爣鍒楄〃
@@ -139,6 +147,8 @@
             SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
             String beginTime= sdf.format(dispatchOrd.getDispatchOrdStartDate());
             String endTime=  sdf.format(new Date());
+
+            logger.info("鏌ヨ杞﹁締杞ㄨ抗锛氳溅杈嗗彿锛歿}, 寮�濮嬫椂闂达細{}, 缁撴潫鏃堕棿锛歿}", vehicleNo, beginTime, endTime);
             return this.getAnonymousTracks(vehicleNo,beginTime,endTime);
 //
 //        vehicleGps.setVehicleNo(tbVehicleOrder.getVehicle());
@@ -225,17 +235,20 @@
             // 閫氳繃杞︾墝鍙疯幏鍙栬澶嘔D
             VehicleInfo vehicleInfo = vehicleInfoService.selectVehicleInfoByPlateNumber(vehicleNo);
             if (vehicleInfo == null) {
-                throw new Error("鏈壘鍒拌杞﹁締瀵瑰簲鐨凣PS璁惧");
+
+                // throw new Error("鏈壘鍒拌杞﹁締瀵瑰簲鐨凣PS璁惧");
+                return getDataTable(new ArrayList<>());
             }
 
             // 澶勭悊寮�濮嬫椂闂�
-                beginTime = beginTime.replace("T", " ").replace(" ","%20");
+                beginTime = beginTime.replace("T", " ");
                 if (beginTime.split(":").length == 2) { // 鍙湁灏忔椂鍜屽垎閽�
                     beginTime += ":00";
                 }
                 
                 // 澶勭悊缁撴潫鏃堕棿
-                endTime = endTime.replace("T", " ").replace(" ","%20");
+//                endTime = endTime.replace("T", " ").replace(" ","%20");
+            endTime = endTime.replace("T", " ");
                 if (endTime.split(":").length == 2) { // 鍙湁灏忔椂鍜屽垎閽�
                     endTime += ":59";
                 }
@@ -310,10 +323,12 @@
                 request.setEndtime(endTime);
                 request.setTimezone(8); // 涓浗鏃跺尯
 
+                logger.info("鏌ヨ杞﹁締杞ㄨ抗锛氳溅杈嗗彿锛歿}, 璁惧ID锛歿}, 寮�濮嬫椂闂达細{}, 缁撴潫鏃堕棿锛歿}", vehicleNo, vehicleInfo.getDeviceId(), beginTime, endTime);
                 // 鏌ヨ杞ㄨ抗
                 GpsTrackQueryResponse response = gpsCollectService.queryTracks(request);
                 if (response.getStatus() != 0) {
-                    throw new Error("鏌ヨ杞ㄨ抗澶辫触锛�" + response.getCause());
+                    logger.error("鏌ヨ杞ㄨ抗澶辫触锛岀姸鎬佺爜锛歿}, 閿欒淇℃伅锛歿}", response.getStatus(), response.getCause());
+                    throw new Error("鏌ヨ杞ㄨ抗澶辫触锛�" + (response.getCause() != null ? response.getCause() : "鏈煡閿欒"));
                 }
 
                 // 杞崲GPS51杞ㄨ抗鐐逛负缁熶竴鏍煎紡
@@ -362,4 +377,97 @@
             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());
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.1