feat: 根据租户获取景区二维码内容
This commit is contained in:
+18
@@ -7,6 +7,7 @@ import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.device.model.AgeDevice;
|
||||
import com.central.device.model.excel.AgeDeviceExcel;
|
||||
import com.central.device.model.vo.AgeDeviceLocationVO;
|
||||
import com.central.device.service.IAgeDeviceService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -90,6 +91,23 @@ public class AgeDeviceController {
|
||||
return Result.succeed("删除成功");
|
||||
}
|
||||
|
||||
@Operation(summary = "根据设备SN获取设备经纬度")
|
||||
@GetMapping("/location/{deviceSn}")
|
||||
public Result<AgeDeviceLocationVO> getLocationByDeviceSn(@PathVariable String deviceSn) {
|
||||
if (deviceSn == null || deviceSn.trim().isEmpty()) {
|
||||
return Result.failed("deviceSn不能为空");
|
||||
}
|
||||
AgeDevice device = ageDeviceService.getByDeviceSn(deviceSn);
|
||||
if (device == null) {
|
||||
return Result.succeed(null, "暂无数据");
|
||||
}
|
||||
AgeDeviceLocationVO vo = new AgeDeviceLocationVO();
|
||||
vo.setDeviceSn(deviceSn);
|
||||
vo.setLongitude(device.getLongitude());
|
||||
vo.setLatitude(device.getLatitude());
|
||||
return Result.succeed(vo, "查询成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出设备信息
|
||||
*/
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package com.central.device.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 设备经纬度信息
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "设备经纬度信息")
|
||||
public class AgeDeviceLocationVO {
|
||||
|
||||
@Schema(description = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "经度")
|
||||
private Double longitude;
|
||||
|
||||
@Schema(description = "纬度")
|
||||
private Double latitude;
|
||||
}
|
||||
|
||||
+24
-5
@@ -1,12 +1,11 @@
|
||||
package com.central.order.controller;
|
||||
|
||||
import com.central.common.context.LoginUserContextHolder;
|
||||
import com.central.common.context.TenantContextHolder;
|
||||
import com.central.common.model.LoginAppUser;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.model.vo.TourismQrCodeDistanceVO;
|
||||
import com.central.order.service.ITourismService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -16,11 +15,8 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -97,6 +93,29 @@ public class TourismController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据租户ID与经纬度查询二维码列表(包含距离)
|
||||
*/
|
||||
@Operation(summary = "根据租户ID与经纬度查询二维码列表")
|
||||
@Parameters({
|
||||
@Parameter(name = "tenantId", description = "租户ID(如:lsApp)", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "longitude", description = "经度", required = true, in = ParameterIn.QUERY),
|
||||
@Parameter(name = "latitude", description = "纬度", required = true, in = ParameterIn.QUERY)
|
||||
})
|
||||
@GetMapping("/qrcodes/by-tenant")
|
||||
public Result<List<TourismQrCodeDistanceVO>> listQrCodesByTenantWithDistance(
|
||||
@RequestParam String tenantId,
|
||||
@RequestParam BigDecimal longitude,
|
||||
@RequestParam BigDecimal latitude) {
|
||||
try {
|
||||
log.info("根据租户ID与经纬度查询二维码列表: tenantId={}, longitude={}, latitude={}", tenantId, longitude, latitude);
|
||||
return tourismService.listQrCodesByTenantWithDistance(tenantId, longitude, latitude);
|
||||
} catch (Exception e) {
|
||||
log.error("根据租户ID与经纬度查询二维码列表失败: tenantId={}", tenantId, e);
|
||||
return Result.failed("查询失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询附近景区列表
|
||||
*/
|
||||
|
||||
+30
@@ -4,6 +4,9 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.fallback.DeviceCenterServiceFallbackFactory;
|
||||
import com.central.order.model.dto.AgeDeviceLocationDTO;
|
||||
import com.central.order.model.dto.BoatRealtimePositionDTO;
|
||||
import com.central.order.model.dto.DroneLatestTrackPointDTO;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
@@ -103,4 +106,31 @@ public interface DeviceCenterService {
|
||||
@Operation(summary = "无人船紧急停止")
|
||||
@PostMapping("/device/boat/command/emergency-stop")
|
||||
Result<Void> emergencyStopBoat(@RequestParam("deviceSn") String deviceSn);
|
||||
|
||||
/**
|
||||
* 根据设备SN获取设备经纬度(AgeDevice)
|
||||
*
|
||||
* @param deviceSn 设备SN
|
||||
*/
|
||||
@Operation(summary = "根据设备SN获取设备经纬度")
|
||||
@GetMapping("/device/location/{deviceSn}")
|
||||
Result<AgeDeviceLocationDTO> getAgeDeviceLocation(@PathVariable("deviceSn") String deviceSn);
|
||||
|
||||
/**
|
||||
* 获取无人船实时位置
|
||||
*
|
||||
* @param deviceSn 设备SN
|
||||
*/
|
||||
@Operation(summary = "获取无人船实时位置")
|
||||
@GetMapping("/device/boat/track/realtime/{deviceSn}")
|
||||
Result<BoatRealtimePositionDTO> getBoatRealtimePosition(@PathVariable("deviceSn") String deviceSn);
|
||||
|
||||
/**
|
||||
* 获取无人机最新轨迹点
|
||||
*
|
||||
* @param deviceSn 设备SN
|
||||
*/
|
||||
@Operation(summary = "获取无人机最新轨迹点")
|
||||
@GetMapping("/api/device/drone/track/latest/{deviceSn}")
|
||||
Result<DroneLatestTrackPointDTO> getDroneLatestTrackPoint(@PathVariable("deviceSn") String deviceSn);
|
||||
}
|
||||
|
||||
+21
@@ -3,6 +3,9 @@ package com.central.order.feign.fallback;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.model.dto.AgeDeviceLocationDTO;
|
||||
import com.central.order.model.dto.BoatRealtimePositionDTO;
|
||||
import com.central.order.model.dto.DroneLatestTrackPointDTO;
|
||||
import com.central.order.mission.VO.TakeoffRequestVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.cloud.openfeign.FallbackFactory;
|
||||
@@ -77,6 +80,24 @@ public class DeviceCenterServiceFallbackFactory implements FallbackFactory<Devic
|
||||
log.error("调用设备中心emergencyStopBoat失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<AgeDeviceLocationDTO> getAgeDeviceLocation(String deviceSn) {
|
||||
log.error("调用设备中心getAgeDeviceLocation失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<BoatRealtimePositionDTO> getBoatRealtimePosition(String deviceSn) {
|
||||
log.error("调用设备中心getBoatRealtimePosition失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<DroneLatestTrackPointDTO> getDroneLatestTrackPoint(String deviceSn) {
|
||||
log.error("调用设备中心getDroneLatestTrackPoint失败: deviceSn={}, error={}", deviceSn, cause.getMessage());
|
||||
return Result.failed("设备中心服务调用失败");
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.central.order.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 设备经纬度信息(用于Feign反序列化)
|
||||
*/
|
||||
@Data
|
||||
public class AgeDeviceLocationDTO {
|
||||
|
||||
@Schema(description = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "经度")
|
||||
private Double longitude;
|
||||
|
||||
@Schema(description = "纬度")
|
||||
private Double latitude;
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
package com.central.order.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 设备中心:无人船实时位置(用于Feign反序列化)
|
||||
*/
|
||||
@Data
|
||||
public class BoatRealtimePositionDTO {
|
||||
|
||||
@Schema(description = "设备SN")
|
||||
private String deviceSn;
|
||||
|
||||
@Schema(description = "经度")
|
||||
private BigDecimal longitude;
|
||||
|
||||
@Schema(description = "纬度")
|
||||
private BigDecimal latitude;
|
||||
}
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.central.order.model.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 设备中心:无人机最新轨迹点(用于Feign反序列化)
|
||||
*/
|
||||
@Data
|
||||
public class DroneLatestTrackPointDTO {
|
||||
|
||||
@Schema(description = "经度")
|
||||
private Double lng;
|
||||
|
||||
@Schema(description = "纬度")
|
||||
private Double lat;
|
||||
}
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package com.central.order.model.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 二维码距离信息返回对象
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "二维码距离信息")
|
||||
public class TourismQrCodeDistanceVO {
|
||||
|
||||
@Schema(description = "二维码名称")
|
||||
private String qrCodeName;
|
||||
|
||||
@Schema(description = "二维码code(codeId)")
|
||||
private String qrCode;
|
||||
|
||||
@Schema(description = "二维码图片(景区展示图URL)")
|
||||
private String qrCodeImage;
|
||||
|
||||
@Schema(description = "距离(公里)")
|
||||
private BigDecimal distance;
|
||||
|
||||
@Schema(description = "距离描述(如:120m、1.2km)")
|
||||
private String distanceDesc;
|
||||
|
||||
public String getDistanceDesc() {
|
||||
if (distance == null) {
|
||||
return "未知距离";
|
||||
}
|
||||
if (distance.compareTo(BigDecimal.ONE) < 0) {
|
||||
int meters = distance.multiply(new BigDecimal("1000")).intValue();
|
||||
return meters + "m";
|
||||
}
|
||||
return distance.setScale(1, BigDecimal.ROUND_HALF_UP) + "km";
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -6,6 +6,7 @@ import com.central.common.service.ISuperService;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.model.vo.TourismQrCodeDistanceVO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
@@ -98,5 +99,15 @@ public interface ITourismService extends ISuperService<Tourism> {
|
||||
|
||||
|
||||
Result<Map<String, Object>> getTourismInfo(Long tourismId);
|
||||
|
||||
/**
|
||||
* 根据租户ID与经纬度查询二维码列表,并返回距离信息
|
||||
*
|
||||
* @param tenantId 租户ID(如:lsApp)
|
||||
* @param longitude 入参经度
|
||||
* @param latitude 入参纬度
|
||||
* @return 二维码列表(二维码名称、二维码code、二维码图片、距离)
|
||||
*/
|
||||
Result<List<TourismQrCodeDistanceVO>> listQrCodesByTenantWithDistance(String tenantId, BigDecimal longitude, BigDecimal latitude);
|
||||
}
|
||||
|
||||
|
||||
+166
@@ -7,15 +7,21 @@ import com.central.common.feign.UserService;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.common.service.impl.SuperServiceImpl;
|
||||
import com.central.order.feign.DeviceCenterService;
|
||||
import com.central.order.mapper.QrCodeMapper;
|
||||
import com.central.order.mapper.TourismMapper;
|
||||
import com.central.order.model.PackagePlan;
|
||||
import com.central.order.model.QrCode;
|
||||
import com.central.order.model.Tourism;
|
||||
import com.central.order.model.TourismWithDistance;
|
||||
import com.central.order.model.TourismFile;
|
||||
import com.central.order.model.dto.AgeDeviceLocationDTO;
|
||||
import com.central.order.model.vo.TourismQrCodeDistanceVO;
|
||||
import com.central.order.service.IPackagePlanService;
|
||||
import com.central.order.service.ITourismService;
|
||||
import com.central.order.service.ITourismFileService;
|
||||
import com.central.order.feign.FileCenterService;
|
||||
import com.central.order.util.GeoDistanceUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -47,6 +53,12 @@ public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism>
|
||||
@Resource
|
||||
private QrCodeMapper qrCodeMapper;
|
||||
|
||||
@Autowired
|
||||
private IPackagePlanService packagePlanService;
|
||||
|
||||
@Autowired
|
||||
private DeviceCenterService deviceCenterService;
|
||||
|
||||
/**
|
||||
* 列表
|
||||
* @param params
|
||||
@@ -299,4 +311,158 @@ public class TourismServiceImpl extends SuperServiceImpl<TourismMapper, Tourism>
|
||||
return Result.succeed(map,"获取成功");
|
||||
}
|
||||
|
||||
@Override
|
||||
@IgnoreTenantScope
|
||||
public Result<List<TourismQrCodeDistanceVO>> listQrCodesByTenantWithDistance(String tenantId, BigDecimal longitude, BigDecimal latitude) {
|
||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||
return Result.failed("tenantId不能为空");
|
||||
}
|
||||
if (longitude == null || latitude == null) {
|
||||
return Result.failed("经纬度不能为空");
|
||||
}
|
||||
if (longitude.compareTo(BigDecimal.valueOf(-180)) < 0 || longitude.compareTo(BigDecimal.valueOf(180)) > 0) {
|
||||
return Result.failed("经度范围应在-180到180之间");
|
||||
}
|
||||
if (latitude.compareTo(BigDecimal.valueOf(-90)) < 0 || latitude.compareTo(BigDecimal.valueOf(90)) > 0) {
|
||||
return Result.failed("纬度范围应在-90到90之间");
|
||||
}
|
||||
|
||||
List<Tourism> tourisms = baseMapper.selectList(new LambdaQueryWrapper<Tourism>()
|
||||
.eq(Tourism::getTenantId, tenantId)
|
||||
.eq(Tourism::getIsDel, 0)
|
||||
.eq(Tourism::getStatus, 1)
|
||||
.orderByDesc(Tourism::getId));
|
||||
|
||||
if (tourisms == null || tourisms.isEmpty()) {
|
||||
return Result.succeed(List.of(), "暂无数据");
|
||||
}
|
||||
|
||||
Map<String, String> codeIdToImageUrl = new HashMap<>();
|
||||
Map<String, BigDecimal[]> deviceSnToLngLat = new HashMap<>();
|
||||
List<TourismQrCodeDistanceVO> resultList = new ArrayList<>();
|
||||
|
||||
for (Tourism tourism : tourisms) {
|
||||
List<QrCode> qrCodes = getQrcodesByTourismId(tourism.getId());
|
||||
if (qrCodes == null || qrCodes.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (QrCode qrCode : qrCodes) {
|
||||
if (qrCode == null || qrCode.getCodeId() == null || qrCode.getCodeId().trim().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TourismQrCodeDistanceVO vo = new TourismQrCodeDistanceVO();
|
||||
String qrName = qrCode.getName();
|
||||
if (qrName == null || qrName.trim().isEmpty()) {
|
||||
qrName = tourism.getTourismName();
|
||||
}
|
||||
vo.setQrCodeName(qrName);
|
||||
vo.setQrCode(qrCode.getCodeId());
|
||||
|
||||
String imageUrl = resolveQrCodeImageUrl(qrCode.getCodeId(), codeIdToImageUrl);
|
||||
vo.setQrCodeImage(imageUrl);
|
||||
|
||||
BigDecimal[] lngLat = resolveDeviceLngLat(qrCode.getDeviceSn(), deviceSnToLngLat);
|
||||
if (lngLat != null && lngLat.length == 2) {
|
||||
vo.setDistance(GeoDistanceUtils.distanceKm(longitude, latitude, lngLat[0], lngLat[1]));
|
||||
}
|
||||
|
||||
resultList.add(vo);
|
||||
}
|
||||
}
|
||||
|
||||
resultList.sort((a, b) -> {
|
||||
BigDecimal da = a.getDistance();
|
||||
BigDecimal db = b.getDistance();
|
||||
if (da == null && db == null) return 0;
|
||||
if (da == null) return 1;
|
||||
if (db == null) return -1;
|
||||
return da.compareTo(db);
|
||||
});
|
||||
|
||||
return Result.succeed(resultList, "获取成功");
|
||||
}
|
||||
|
||||
private String resolveQrCodeImageUrl(String codeId, Map<String, String> cache) {
|
||||
if (codeId == null || codeId.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (cache.containsKey(codeId)) {
|
||||
return cache.get(codeId);
|
||||
}
|
||||
|
||||
String imageUrl = null;
|
||||
try {
|
||||
List<PackagePlan> plans = packagePlanService.getByCodeId(codeId);
|
||||
if (plans != null && !plans.isEmpty()) {
|
||||
PackagePlan plan = plans.get(0);
|
||||
List<Long> fileIds = parseIdList(plan.getTourismFileIds());
|
||||
if (!fileIds.isEmpty()) {
|
||||
List<TourismFile> files = tourismFileService.findByIds(fileIds);
|
||||
if (files != null) {
|
||||
for (TourismFile file : files) {
|
||||
if (file != null && file.getImageUrl() != null && !file.getImageUrl().trim().isEmpty()) {
|
||||
imageUrl = fileCenterService.getViewUrlByPath(file.getImageUrl());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("解析二维码图片失败: codeId={}, error={}", codeId, e.getMessage());
|
||||
}
|
||||
|
||||
cache.put(codeId, imageUrl);
|
||||
return imageUrl;
|
||||
}
|
||||
|
||||
private BigDecimal[] resolveDeviceLngLat(String deviceSn, Map<String, BigDecimal[]> cache) {
|
||||
if (deviceSn == null || deviceSn.trim().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
if (cache.containsKey(deviceSn)) {
|
||||
return cache.get(deviceSn);
|
||||
}
|
||||
|
||||
BigDecimal[] lngLat = null;
|
||||
try {
|
||||
Result<AgeDeviceLocationDTO> locationResult = deviceCenterService.getAgeDeviceLocation(deviceSn);
|
||||
if (locationResult != null && locationResult.getResp_code() != null && locationResult.getResp_code() == 0) {
|
||||
AgeDeviceLocationDTO data = locationResult.getData();
|
||||
if (data != null && data.getLongitude() != null && data.getLatitude() != null) {
|
||||
lngLat = new BigDecimal[]{BigDecimal.valueOf(data.getLongitude()), BigDecimal.valueOf(data.getLatitude())};
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("获取设备经纬度失败: deviceSn={}, error={}", deviceSn, e.getMessage());
|
||||
}
|
||||
|
||||
cache.put(deviceSn, lngLat);
|
||||
return lngLat;
|
||||
}
|
||||
|
||||
private List<Long> parseIdList(String ids) {
|
||||
if (ids == null || ids.trim().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
String[] parts = ids.split(",");
|
||||
List<Long> list = new ArrayList<>();
|
||||
for (String part : parts) {
|
||||
if (part == null) {
|
||||
continue;
|
||||
}
|
||||
String v = part.trim();
|
||||
if (v.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
list.add(Long.parseLong(v));
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.central.order.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
|
||||
/**
|
||||
* 经纬度距离计算工具类
|
||||
*/
|
||||
public final class GeoDistanceUtils {
|
||||
|
||||
private static final double EARTH_RADIUS_KM = 6371.0;
|
||||
|
||||
private GeoDistanceUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两点间球面距离(公里)
|
||||
*/
|
||||
public static BigDecimal distanceKm(BigDecimal longitude1, BigDecimal latitude1,
|
||||
BigDecimal longitude2, BigDecimal latitude2) {
|
||||
if (longitude1 == null || latitude1 == null || longitude2 == null || latitude2 == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double lng1 = longitude1.doubleValue();
|
||||
double lat1 = latitude1.doubleValue();
|
||||
double lng2 = longitude2.doubleValue();
|
||||
double lat2 = latitude2.doubleValue();
|
||||
|
||||
double dLat = Math.toRadians(lat2 - lat1);
|
||||
double dLng = Math.toRadians(lng2 - lng1);
|
||||
|
||||
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2)
|
||||
+ Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
|
||||
* Math.sin(dLng / 2) * Math.sin(dLng / 2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
double distance = EARTH_RADIUS_KM * c;
|
||||
|
||||
return BigDecimal.valueOf(distance).setScale(3, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user