refactor: centralize telemetry metadata formatting
This commit is contained in:
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.lingniu.ingest.api.ProtocolId;
|
||||
import com.lingniu.ingest.api.event.LocationPayload;
|
||||
import com.lingniu.ingest.api.event.RealtimePayload;
|
||||
import com.lingniu.ingest.api.event.TelemetryMetadataValues;
|
||||
import com.lingniu.ingest.api.event.VehicleEvent;
|
||||
import com.lingniu.ingest.api.spi.EventMapper;
|
||||
import com.lingniu.ingest.identity.VehicleIdentity;
|
||||
@@ -16,7 +17,6 @@ import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -99,7 +99,7 @@ public final class YutongEventMapper implements EventMapper<MqttPayload> {
|
||||
0, 0);
|
||||
Map<String, String> locationMeta = mileage == null
|
||||
? meta
|
||||
: withMeta(meta, "total_mileage_km", formatDouble(mileage));
|
||||
: withMeta(meta, "total_mileage_km", TelemetryMetadataValues.doubleValue(mileage));
|
||||
out.add(new VehicleEvent.Location(
|
||||
UUID.randomUUID().toString(),
|
||||
vin, ProtocolId.MQTT_YUTONG, payload.deviceTime(), ingestTime,
|
||||
@@ -237,13 +237,6 @@ public final class YutongEventMapper implements EventMapper<MqttPayload> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatDouble(double value) {
|
||||
String formatted = String.format(Locale.ROOT, "%.6f", value);
|
||||
return formatted.indexOf('.') < 0
|
||||
? formatted
|
||||
: formatted.replaceAll("0+$", "").replaceAll("\\.$", "");
|
||||
}
|
||||
|
||||
private record IdentityResolution(VehicleIdentity identity, String errorMessage) {
|
||||
private static IdentityResolution ok(VehicleIdentity identity) {
|
||||
return new IdentityResolution(identity, null);
|
||||
|
||||
Reference in New Issue
Block a user