fix: expose jt808 mileage metadata

This commit is contained in:
lingniu
2026-07-01 09:55:44 +08:00
parent 0236884f81
commit 136b8a040c
2 changed files with 8 additions and 1 deletions

View File

@@ -285,6 +285,10 @@ public final class Jt808EventMapper implements EventMapper<Jt808Message> {
loc.extensionItems().forEach((id, bytes) -> loc.extensionItems().forEach((id, bytes) ->
copy.put("jt808.extra.0x" + String.format("%02X", id), hex(bytes))); copy.put("jt808.extra.0x" + String.format("%02X", id), hex(bytes)));
copy.putAll(Jt808LocationAdditionalInfo.decode(loc.extensionItems())); copy.putAll(Jt808LocationAdditionalInfo.decode(loc.extensionItems()));
Double totalMileageKm = totalMileageKm(loc);
if (totalMileageKm != null) {
copy.put("total_mileage_km", Double.toString(totalMileageKm));
}
} }
return Map.copyOf(copy); return Map.copyOf(copy);
} }

View File

@@ -137,7 +137,10 @@ class Jt808EventMapperTest {
VehicleEvent.Location event = (VehicleEvent.Location) mapper.toEvents(new Jt808Message(header, body)).getFirst(); VehicleEvent.Location event = (VehicleEvent.Location) mapper.toEvents(new Jt808Message(header, body)).getFirst();
assertThat(event.payload().totalMileageKm()).isEqualTo(1234.5); assertThat(event.payload().totalMileageKm()).isEqualTo(1234.5);
assertThat(event.metadata()).containsEntry("jt808.extra.0x01", "00003039"); assertThat(event.metadata())
.containsEntry("jt808.extra.0x01", "00003039")
.containsEntry("jt808.extra.mileage_km", "1234.5")
.containsEntry("total_mileage_km", "1234.5");
} }
@Test @Test