refactor: simplify jt808 daily mileage strategy
This commit is contained in:
@@ -337,23 +337,18 @@ Validation:
|
||||
|
||||
### Daily Mileage
|
||||
|
||||
Preferred:
|
||||
|
||||
```text
|
||||
dailyMileage = today.lastTotalMileage - previousDay.lastTotalMileage
|
||||
```
|
||||
|
||||
Fallback:
|
||||
JT808 daily mileage uses the GPS total mileage reported in location additional
|
||||
information. The first valid sample of the local day is the baseline and the
|
||||
latest valid total mileage rewrites the same metric row.
|
||||
|
||||
```text
|
||||
dailyMileage = today.lastTotalMileage - today.firstTotalMileage
|
||||
calculationMethod = JT808_TOTAL_MILEAGE_DIFF
|
||||
```
|
||||
|
||||
Quality:
|
||||
|
||||
- `PREVIOUS_DAY_BASELINE` when previous day baseline exists;
|
||||
- `INTRADAY_DELTA` when only same-day baseline exists;
|
||||
- `INSUFFICIENT_DATA` when neither is reliable.
|
||||
The result is stored in `vehicle_stat_metric` with
|
||||
`metric_key=daily_mileage_km`. There is no JT808-specific daily mileage table,
|
||||
no Redis mileage state, and no previous-day baseline calculation.
|
||||
|
||||
### Daily Power Consumption
|
||||
|
||||
|
||||
@@ -8,9 +8,6 @@ public enum DailyMileageStrategy {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import java.time.LocalDate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
class JdbcVehicleStatMetricRepositoryTest {
|
||||
|
||||
@@ -147,7 +148,7 @@ class JdbcVehicleStatMetricRepositoryTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void readsLegacyCalculationMethodAsTotalMileageDifference() {
|
||||
void rejectsLegacyPreviousDayCalculationMethod() {
|
||||
JdbcTemplate jdbcTemplate = new JdbcTemplate(new DriverManagerDataSource(
|
||||
"jdbc:h2:mem:vehicle_stat_metric_legacy;MODE=MySQL;DATABASE_TO_LOWER=TRUE;DB_CLOSE_DELAY=-1",
|
||||
"sa",
|
||||
@@ -159,10 +160,8 @@ class JdbcVehicleStatMetricRepositoryTest {
|
||||
VALUES ('VIN001', DATE '2026-06-30', 'daily_mileage_km', 8.5, 'km', 'CURRENT_LAST_MINUS_PREVIOUS_LAST')
|
||||
""");
|
||||
|
||||
assertThat(repository.findDailyStat("VIN001", LocalDate.of(2026, 6, 30)))
|
||||
.isPresent()
|
||||
.get()
|
||||
.extracting(VehicleDailyStatResult::dailyMileageStrategy)
|
||||
.isEqualTo(DailyMileageStrategy.JT808_TOTAL_MILEAGE_DIFF);
|
||||
assertThatThrownBy(() -> repository.findDailyStat("VIN001", LocalDate.of(2026, 6, 30)))
|
||||
.isInstanceOf(IllegalArgumentException.class)
|
||||
.hasMessageContaining("CURRENT_LAST_MINUS_PREVIOUS_LAST");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user