fix: resolve xinda vehicles by mysql plate binding
This commit is contained in:
@@ -143,9 +143,9 @@ public final class XindaPushEventMapper implements EventMapper<XindaPushMessage>
|
||||
return IdentityResolution.ok(identityResolver.resolve(new VehicleIdentityLookup(
|
||||
ProtocolId.XINDA_PUSH,
|
||||
firstNonBlank(json, "vin"),
|
||||
firstNonBlank(json, "sim", "phone", "mobile"),
|
||||
firstNonBlank(json, "deviceId", "terminalId", "imei"),
|
||||
firstNonBlank(json, "plateNo", "carNo"))));
|
||||
firstNonBlank(json, "sim", "phone", "mobile", "simCode"),
|
||||
firstNonBlank(json, "deviceId", "terminalId", "imei", "tmnKey", "tmnCode"),
|
||||
plateNo(json))));
|
||||
} catch (RuntimeException e) {
|
||||
return new IdentityResolution(
|
||||
new VehicleIdentity("unknown", false, VehicleIdentitySource.UNKNOWN),
|
||||
@@ -172,9 +172,9 @@ public final class XindaPushEventMapper implements EventMapper<XindaPushMessage>
|
||||
out.put("rawJson", message.json());
|
||||
out.put("vin", normalizedVin(identity));
|
||||
out.put("externalVin", firstNonBlank(json, "vin"));
|
||||
out.put("phone", firstNonBlank(json, "sim", "phone", "mobile"));
|
||||
out.put("deviceId", firstNonBlank(json, "deviceId", "terminalId", "imei"));
|
||||
out.put("plateNo", firstNonBlank(json, "plateNo", "carNo"));
|
||||
out.put("phone", firstNonBlank(json, "sim", "phone", "mobile", "simCode"));
|
||||
out.put("deviceId", firstNonBlank(json, "deviceId", "terminalId", "imei", "tmnKey", "tmnCode"));
|
||||
out.put("plateNo", plateNo(json));
|
||||
out.put("identityResolved", Boolean.toString(identity.identity().resolved()));
|
||||
out.put("identitySource", identity.identity().source().name());
|
||||
if (identity.errorMessage() != null) {
|
||||
@@ -243,6 +243,10 @@ public final class XindaPushEventMapper implements EventMapper<XindaPushMessage>
|
||||
return "";
|
||||
}
|
||||
|
||||
private static String plateNo(JSONObject node) {
|
||||
return firstNonBlank(node, "plateNo", "carNo", "carName");
|
||||
}
|
||||
|
||||
private static double asDouble(JSONObject node, String... keys) {
|
||||
Double value = optionalDouble(node, keys);
|
||||
return value == null ? 0.0 : value;
|
||||
|
||||
@@ -113,6 +113,27 @@ class XindaPushEventMapperTest {
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesVehicleIdentityByCarNamePlateFromXindaPayload() {
|
||||
identity.bind(new VehicleIdentityBinding(
|
||||
ProtocolId.XINDA_PUSH, "LNVIN000000000203", "", "", "浙F00780F"));
|
||||
|
||||
List<VehicleEvent> events = mapper.toEvents(new XindaPushMessage("0200",
|
||||
"{\"carName\":\"浙F00780F\",\"tmnKey\":\"13307811342\",\"simCode\":\"8986062582008805648\","
|
||||
+ "\"lng\":121.075223,\"lat\":30.583753}"));
|
||||
|
||||
assertThat(events).singleElement()
|
||||
.satisfies(event -> {
|
||||
assertThat(event.vin()).isEqualTo("LNVIN000000000203");
|
||||
assertThat(event.metadata())
|
||||
.containsEntry("vin", "LNVIN000000000203")
|
||||
.containsEntry("plateNo", "浙F00780F")
|
||||
.containsEntry("phone", "8986062582008805648")
|
||||
.containsEntry("deviceId", "13307811342")
|
||||
.containsEntry("identityResolved", "true");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void identityResolverFailureStillProducesLocationEventWithUnknownVin() {
|
||||
XindaPushEventMapper mapperWithFailingIdentity = new XindaPushEventMapper(lookup -> {
|
||||
|
||||
Reference in New Issue
Block a user