refactor: store jt808 mileage as metric diff
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
package com.lingniu.ingest.vehiclestat;
|
||||
|
||||
public enum DailyMileageStrategy {
|
||||
CURRENT_LAST_MINUS_PREVIOUS_LAST,
|
||||
DAY_MAX_MINUS_DAY_MIN
|
||||
JT808_TOTAL_MILEAGE_DIFF;
|
||||
|
||||
public static DailyMileageStrategy fromStorage(String value) {
|
||||
if (value == null || value.isBlank()) {
|
||||
return JT808_TOTAL_MILEAGE_DIFF;
|
||||
}
|
||||
String normalized = value.trim();
|
||||
if ("CURRENT_LAST_MINUS_PREVIOUS_LAST".equals(normalized)) {
|
||||
return JT808_TOTAL_MILEAGE_DIFF;
|
||||
}
|
||||
return DailyMileageStrategy.valueOf(normalized);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public final class JdbcVehicleStatMetricRepository implements VehicleStatReposit
|
||||
rs.getBigDecimal("metric_value") == null
|
||||
? OptionalDouble.empty()
|
||||
: OptionalDouble.of(rs.getBigDecimal("metric_value").doubleValue()),
|
||||
DailyMileageStrategy.valueOf(rs.getString("calculation_method"))),
|
||||
DailyMileageStrategy.fromStorage(rs.getString("calculation_method"))),
|
||||
normalizedVin, Date.valueOf(statDate), DAILY_MILEAGE_KEY);
|
||||
return rows.stream().findFirst();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public record VehicleDailyStatResult(String vin,
|
||||
dailyMileageKm = OptionalDouble.empty();
|
||||
}
|
||||
if (dailyMileageStrategy == null) {
|
||||
dailyMileageStrategy = DailyMileageStrategy.CURRENT_LAST_MINUS_PREVIOUS_LAST;
|
||||
dailyMileageStrategy = DailyMileageStrategy.JT808_TOTAL_MILEAGE_DIFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public final class Jt808DailyMileageState {
|
||||
statVehicleId(),
|
||||
statDate,
|
||||
dailyMileage,
|
||||
DailyMileageStrategy.CURRENT_LAST_MINUS_PREVIOUS_LAST));
|
||||
DailyMileageStrategy.JT808_TOTAL_MILEAGE_DIFF));
|
||||
}
|
||||
|
||||
private void updateOdometer(Jt808LocationPoint point) {
|
||||
|
||||
Reference in New Issue
Block a user