更新统计

This commit is contained in:
磷叶 2025-05-14 09:32:25 +08:00
parent e0489488e1
commit bac3041339
5 changed files with 31 additions and 17 deletions

View File

@ -35,6 +35,9 @@ public class MathUtils {
*/
public static BigDecimal subtractDecimal(BigDecimal a, BigDecimal ...values) {
BigDecimal result = a;
if (result == null) {
result = BigDecimal.ZERO;
}
for (BigDecimal value : values) {
if (value != null) {
result = result.subtract(value);

View File

@ -34,6 +34,14 @@ public class GpsCoordinateUtils {
return new double[]{retLat, retLon};
}
/**
* 地球坐标系 WGS-84 to 火星坐标系 GCJ-02
*/
public static List<BigDecimal> calWGS84toGCJ02(BigDecimal lon, BigDecimal lat) {
double[] gcj = calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
return Arrays.asList(BigDecimal.valueOf(gcj[1]), BigDecimal.valueOf(gcj[0]));
}
/**
* 地球坐标系 WGS-84 to 百度坐标系 BD-09
*
@ -846,7 +854,7 @@ public class GpsCoordinateUtils {
doubles = calWGS84toGCJ02(la.doubleValue(), lo.doubleValue());
}
return Arrays.asList(new BigDecimal(doubles[0]), new BigDecimal(doubles[1]));
return Arrays.asList(new BigDecimal(doubles[1]), new BigDecimal(doubles[0]));
}
public static String[] getDecimalPart(BigDecimal number) {

View File

@ -454,8 +454,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
ServiceUtil.assertion(device == null, "设备不存在");
// 更新设备信息
DeviceUtil.setIotSysInfo(device, dto.getSys(), LocalDateTime.now(), true, false);
device.setLocationType(DeviceLocationType.PHONE.getCode());
DeviceUtil.setIotSysInfo(device, dto.getSys(), LocalDateTime.now(), true, DeviceLocationType.PHONE);
int rows = this.updateIot(device);
// 创建定位日志

View File

@ -2,6 +2,7 @@ package com.ruoyi.bst.device.utils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.List;
import com.ruoyi.bst.device.domain.DeviceVO;
@ -16,7 +17,7 @@ import com.ruoyi.iot.util.BatUtil;
public class DeviceUtil {
public static void setIotSysInfo(DeviceVO device, IotDeviceSysInfo sys, LocalDateTime at, boolean setNull) {
setIotSysInfo(device, sys, at, setNull, true);
setIotSysInfo(device, sys, at, setNull, DeviceLocationType.DEVICE);
}
/**
@ -27,7 +28,7 @@ public class DeviceUtil {
* @param setNull 若定位不正常是否设置为空
* @param convertLocation 是否转换经纬度坐标系
*/
public static void setIotSysInfo(DeviceVO device, IotDeviceSysInfo sys, LocalDateTime at, boolean setNull, boolean convertLocation) {
public static void setIotSysInfo(DeviceVO device, IotDeviceSysInfo sys, LocalDateTime at, boolean setNull, DeviceLocationType locationType) {
if (device == null || sys == null) {
return;
}
@ -35,18 +36,21 @@ public class DeviceUtil {
// 转换经纬度坐标系并赋值
// 只有定位是正常的才认为是有获取到定位
if (DeviceUtil.validLocation(sys.getLon(), sys.getLat())) {
if (convertLocation) {
List<BigDecimal> coordinates = GpsCoordinateUtils.coordinateConvert(sys.getLon(), sys.getLat());
List<BigDecimal> coordinates = null;
// 转换坐标
if (locationType == DeviceLocationType.DEVICE) {
coordinates = GpsCoordinateUtils.coordinateConvert(sys.getLon(), sys.getLat());
} else if (locationType == DeviceLocationType.PHONE) {
coordinates = Arrays.asList(sys.getLon(), sys.getLat());
}
if (coordinates != null && coordinates.size() >= 2) {
device.setLongitude(coordinates.get(1));
device.setLatitude(coordinates.get(0));
}
} else {
device.setLongitude(sys.getLon());
device.setLatitude(sys.getLat());
}
device.setLongitude(coordinates.get(0));
device.setLatitude(coordinates.get(1));
device.setLastLocationTime(at);
device.setLocationType(DeviceLocationType.DEVICE.getCode());
device.setLocationType(locationType.getCode());
}
} else if (setNull) {
device.setLongitude(null);
device.setLatitude(null);

View File

@ -493,7 +493,7 @@ public class OrderServiceImpl implements OrderService {
// 转为定位日志
LocationLog locationLog = locationLogConverter.toPo(device);
if (locationLog == null) {
log.error("转换定位日志失败: {}", device.getMac());
log.error("通过手机定位转换定位日志失败: {}", device.getMac());
return;
}
// 暂存到Redis缓存