更新优化,设备定位BUG

This commit is contained in:
磷叶 2025-04-24 17:41:41 +08:00
parent 5599f89863
commit 3d8a6aeb91
2 changed files with 9 additions and 1 deletions

View File

@ -154,4 +154,12 @@ public class MathUtils {
}
return a.equals(b);
}
// 判断a和b的值是否一致精度为precision
public static boolean equalsFixed(BigDecimal a, BigDecimal b, int precision) {
if (a == null || b == null) {
return false;
}
return equals(a.setScale(precision, BigDecimal.ROUND_HALF_UP), b.setScale(precision, BigDecimal.ROUND_HALF_UP));
}
}

View File

@ -148,7 +148,7 @@ public class IotReceiveServiceImpl implements IotReceiveService {
// 需要在设备未启动的时候做否则可能有安全问题
if (!isOpen) {
// 若当前数据点的上报时间和设备内上次上报的时间不一样但是定位一样则重启设备
if (at.isAfter(device.getLastLocationTime()) && MathUtils.equals(device.getLongitude(), sys.getLon()) && MathUtils.equals(device.getLatitude(), sys.getLat())) {
if (at.isAfter(device.getLastLocationTime()) && MathUtils.equalsFixed(device.getLongitude(), sys.getLon(), 8) && MathUtils.equalsFixed(device.getLatitude(), sys.getLat(), 8)) {
String reason = String.format("设备不同时间的两次定位一样,重启设备。定位:%s,%s", sys.getLon(), sys.getLat());
deviceIotService.reboot(device, reason, true);
return 1;