| | |
| | | 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; |
| | |
| | | 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 |
| | |
| | | |
| | | @Autowired |
| | | private ICmsGpsCollectService cmsGpsCollectService; |
| | | |
| | | @Autowired |
| | | private TencentMapConfig tencentMapConfig; |
| | | |
| | | /** |
| | | * 查询车辆GPS坐标列表 |
| | |
| | | } |
| | | |
| | | // 处理开始时间 |
| | | 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"; |
| | | } |
| | |
| | | throw new Error("查询车辆轨迹失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 腾讯地图地址搜索接口代理 |
| | | */ |
| | | @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(); |
| | | |
| | | // 发送HTTP请求 |
| | | String response = HttpUtils.sendGet(url, params); |
| | | |
| | | // 返回结果 |
| | | return AjaxResult.success("查询成功", response); |
| | | } catch (Exception e) { |
| | | logger.error("地址搜索失败", e); |
| | | return AjaxResult.error("地址搜索失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 腾讯地图逆地址解析接口代理 |
| | | */ |
| | | @Anonymous() |
| | | @GetMapping("/address/geocoder") |
| | | public AjaxResult reverseGeocoder(Double lat, Double lng) { |
| | | try { |
| | | // 检查参数 |
| | | logger.info("逆地址解析请求参数: 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("参数无效,经纬度坐标格式错误"); |
| | | } |
| | | |
| | | // 构建腾讯地图逆地址解析API URL |
| | | String url = "https://apis.map.qq.com/ws/geocoder/v1/"; |
| | | String params = "location=" + lat + "," + lng + |
| | | "&key=" + tencentMapConfig.getKey() + |
| | | "&get_poi=1"; |
| | | |
| | | // 发送HTTP请求 |
| | | String response = HttpUtils.sendGet(url, params); |
| | | |
| | | // 返回结果 |
| | | return AjaxResult.success("查询成功", response); |
| | | } catch (Exception e) { |
| | | logger.error("逆地址解析失败: lat={}, lng={}", lat, lng, e); |
| | | return AjaxResult.error("逆地址解析失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 腾讯地图路线规划接口代理(计算两点间距离) |
| | | */ |
| | | @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(); |
| | | |
| | | // 发送HTTP请求 |
| | | String response = HttpUtils.sendGet(url, params); |
| | | |
| | | // 返回结果 |
| | | return AjaxResult.success("计算成功", response); |
| | | } catch (Exception e) { |
| | | logger.error("距离计算失败", e); |
| | | return AjaxResult.error("距离计算失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |