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