fix: expose jt808 location raw archive uri
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.lingniu.ingest.eventhistory;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.lingniu.ingest.tdenginehistory.TdengineHistoryReader;
|
||||
import com.lingniu.ingest.tdenginehistory.TdengineLocationQuery;
|
||||
import com.lingniu.ingest.tdenginehistory.TdengineLocationRow;
|
||||
@@ -29,6 +31,8 @@ import java.util.List;
|
||||
@Tag(name = "jt-808-location-controller", description = "JT808 位置历史分页查询接口。")
|
||||
public final class Jt808LocationHistoryController {
|
||||
|
||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||
|
||||
private final TdengineHistoryReader reader;
|
||||
|
||||
public Jt808LocationHistoryController(TdengineHistoryReader reader) {
|
||||
@@ -142,8 +146,23 @@ public final class Jt808LocationHistoryController {
|
||||
row.alarmFlag(),
|
||||
row.statusFlag(),
|
||||
row.totalMileageKm(),
|
||||
row.rawUri(),
|
||||
rawUri(row),
|
||||
row.metadataJson());
|
||||
}
|
||||
|
||||
private static String rawUri(TdengineLocationRow row) {
|
||||
if (row.rawUri() != null && !row.rawUri().isBlank()) {
|
||||
return row.rawUri();
|
||||
}
|
||||
String metadataJson = row.metadataJson();
|
||||
if (metadataJson == null || metadataJson.isBlank()) {
|
||||
return row.rawUri();
|
||||
}
|
||||
try {
|
||||
return OBJECT_MAPPER.readTree(metadataJson).path("rawArchiveUri").asText(row.rawUri());
|
||||
} catch (JsonProcessingException ignored) {
|
||||
return row.rawUri();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,30 @@ class Jt808LocationHistoryControllerTest {
|
||||
"2026-06-29T05:00:01Z", "fact-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void fallsBackToRawArchiveUriInMetadataWhenLocationRawUriIsBlank() throws Exception {
|
||||
CapturingReader reader = new CapturingReader(new TdenginePage<>(
|
||||
List.of(row(
|
||||
"fact-blank-raw",
|
||||
"2026-06-29T05:00:01Z",
|
||||
"",
|
||||
"{\"rawArchiveUri\":\"archive://jt808/metadata-frame.bin\"}")),
|
||||
Optional.empty()));
|
||||
Jt808LocationHistoryController controller = new Jt808LocationHistoryController(reader);
|
||||
|
||||
Jt808LocationHistoryController.LocationPageResponse response = controller.locations(
|
||||
"g7gps",
|
||||
"2026-06-29T13:00:00+08:00",
|
||||
"2026-06-29T13:10:00+08:00",
|
||||
TdengineQueryOrder.DESC,
|
||||
50,
|
||||
null,
|
||||
null);
|
||||
|
||||
assertThat(response.items().getFirst().rawUri())
|
||||
.isEqualTo("archive://jt808/metadata-frame.bin");
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsBlankPhone() {
|
||||
Jt808LocationHistoryController controller = new Jt808LocationHistoryController(
|
||||
@@ -68,6 +92,10 @@ class Jt808LocationHistoryControllerTest {
|
||||
}
|
||||
|
||||
private static TdengineLocationRow row(String factId, String ts) {
|
||||
return row(factId, ts, "archive://jt808/frame-1.bin", "{\"messageId\":\"512\"}");
|
||||
}
|
||||
|
||||
private static TdengineLocationRow row(String factId, String ts, String rawUri, String metadataJson) {
|
||||
Instant instant = Instant.parse(ts);
|
||||
return new TdengineLocationRow(
|
||||
instant,
|
||||
@@ -82,8 +110,8 @@ class Jt808LocationHistoryControllerTest {
|
||||
1L,
|
||||
3L,
|
||||
null,
|
||||
"archive://jt808/frame-1.bin",
|
||||
"{\"messageId\":\"512\"}",
|
||||
rawUri,
|
||||
metadataJson,
|
||||
"JT808",
|
||||
"jt808:g7gps",
|
||||
"",
|
||||
|
||||
Reference in New Issue
Block a user