更新统计
This commit is contained in:
parent
e0489488e1
commit
bac3041339
|
@ -35,6 +35,9 @@ public class MathUtils {
|
||||||
*/
|
*/
|
||||||
public static BigDecimal subtractDecimal(BigDecimal a, BigDecimal ...values) {
|
public static BigDecimal subtractDecimal(BigDecimal a, BigDecimal ...values) {
|
||||||
BigDecimal result = a;
|
BigDecimal result = a;
|
||||||
|
if (result == null) {
|
||||||
|
result = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
for (BigDecimal value : values) {
|
for (BigDecimal value : values) {
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
result = result.subtract(value);
|
result = result.subtract(value);
|
||||||
|
|
|
@ -34,6 +34,14 @@ public class GpsCoordinateUtils {
|
||||||
return new double[]{retLat, retLon};
|
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
|
* 地球坐标系 WGS-84 to 百度坐标系 BD-09
|
||||||
*
|
*
|
||||||
|
@ -846,7 +854,7 @@ public class GpsCoordinateUtils {
|
||||||
doubles = calWGS84toGCJ02(la.doubleValue(), lo.doubleValue());
|
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) {
|
public static String[] getDecimalPart(BigDecimal number) {
|
||||||
|
|
|
@ -454,8 +454,7 @@ public class DeviceIotServiceImpl implements DeviceIotService {
|
||||||
ServiceUtil.assertion(device == null, "设备不存在");
|
ServiceUtil.assertion(device == null, "设备不存在");
|
||||||
|
|
||||||
// 更新设备信息
|
// 更新设备信息
|
||||||
DeviceUtil.setIotSysInfo(device, dto.getSys(), LocalDateTime.now(), true, false);
|
DeviceUtil.setIotSysInfo(device, dto.getSys(), LocalDateTime.now(), true, DeviceLocationType.PHONE);
|
||||||
device.setLocationType(DeviceLocationType.PHONE.getCode());
|
|
||||||
int rows = this.updateIot(device);
|
int rows = this.updateIot(device);
|
||||||
|
|
||||||
// 创建定位日志
|
// 创建定位日志
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.bst.device.utils;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.ruoyi.bst.device.domain.DeviceVO;
|
import com.ruoyi.bst.device.domain.DeviceVO;
|
||||||
|
@ -16,7 +17,7 @@ import com.ruoyi.iot.util.BatUtil;
|
||||||
public class DeviceUtil {
|
public class DeviceUtil {
|
||||||
|
|
||||||
public static void setIotSysInfo(DeviceVO device, IotDeviceSysInfo sys, LocalDateTime at, boolean setNull) {
|
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 setNull 若定位不正常,是否设置为空
|
||||||
* @param convertLocation 是否转换经纬度坐标系
|
* @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) {
|
if (device == null || sys == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -35,18 +36,21 @@ public class DeviceUtil {
|
||||||
// 转换经纬度坐标系并赋值
|
// 转换经纬度坐标系并赋值
|
||||||
// 只有定位是正常的才认为是有获取到定位
|
// 只有定位是正常的才认为是有获取到定位
|
||||||
if (DeviceUtil.validLocation(sys.getLon(), sys.getLat())) {
|
if (DeviceUtil.validLocation(sys.getLon(), sys.getLat())) {
|
||||||
if (convertLocation) {
|
List<BigDecimal> coordinates = null;
|
||||||
List<BigDecimal> coordinates = GpsCoordinateUtils.coordinateConvert(sys.getLon(), sys.getLat());
|
|
||||||
if (coordinates != null && coordinates.size() >= 2) {
|
// 转换坐标
|
||||||
device.setLongitude(coordinates.get(1));
|
if (locationType == DeviceLocationType.DEVICE) {
|
||||||
device.setLatitude(coordinates.get(0));
|
coordinates = GpsCoordinateUtils.coordinateConvert(sys.getLon(), sys.getLat());
|
||||||
}
|
} else if (locationType == DeviceLocationType.PHONE) {
|
||||||
} else {
|
coordinates = Arrays.asList(sys.getLon(), sys.getLat());
|
||||||
device.setLongitude(sys.getLon());
|
}
|
||||||
device.setLatitude(sys.getLat());
|
|
||||||
|
if (coordinates != null && coordinates.size() >= 2) {
|
||||||
|
device.setLongitude(coordinates.get(0));
|
||||||
|
device.setLatitude(coordinates.get(1));
|
||||||
|
device.setLastLocationTime(at);
|
||||||
|
device.setLocationType(locationType.getCode());
|
||||||
}
|
}
|
||||||
device.setLastLocationTime(at);
|
|
||||||
device.setLocationType(DeviceLocationType.DEVICE.getCode());
|
|
||||||
} else if (setNull) {
|
} else if (setNull) {
|
||||||
device.setLongitude(null);
|
device.setLongitude(null);
|
||||||
device.setLatitude(null);
|
device.setLatitude(null);
|
||||||
|
|
|
@ -493,7 +493,7 @@ public class OrderServiceImpl implements OrderService {
|
||||||
// 转为定位日志
|
// 转为定位日志
|
||||||
LocationLog locationLog = locationLogConverter.toPo(device);
|
LocationLog locationLog = locationLogConverter.toPo(device);
|
||||||
if (locationLog == null) {
|
if (locationLog == null) {
|
||||||
log.error("转换定位日志失败: {}", device.getMac());
|
log.error("通过手机定位转换定位日志失败: {}", device.getMac());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 暂存到Redis缓存
|
// 暂存到Redis缓存
|
||||||
|
|
Loading…
Reference in New Issue
Block a user