fix: verify mysql identity and jt808 field aliases
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
lingniu
2026-06-29 18:15:55 +08:00
parent bf09f4e9b2
commit 9dc667f8da
4 changed files with 99 additions and 1 deletions

View File

@@ -22,6 +22,7 @@ import java.io.IOException;
import java.time.Instant;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@RestController
@ConditionalOnProperty(prefix = "lingniu.ingest.event-history", name = "enabled", havingValue = "true")
@@ -30,6 +31,15 @@ import java.util.Locale;
@Tag(name = "telemetry-field-history-controller", description = "遥测字段历史分页查询接口。")
public final class TelemetryFieldHistoryController {
private static final Map<String, String> JT808_FIELD_ALIASES = Map.of(
"location.longitude", "longitude",
"location.latitude", "latitude",
"location.altitude_m", "altitude_m",
"location.speed_kmh", "speed_kmh",
"location.direction_deg", "direction_deg",
"location.alarm_flag", "location_alarm_flag",
"location.status_flag", "location_status_raw");
private final TdengineHistoryReader reader;
public TelemetryFieldHistoryController(TdengineHistoryReader reader) {
@@ -67,7 +77,9 @@ public final class TelemetryFieldHistoryController {
@Parameter(description = "上一页返回的 nextCursor.id。", example = "event-xxx#0")
@RequestParam(required = false) String cursorId) throws IOException {
String normalizedProtocol = require(protocol, "protocol is required for telemetry field query").toUpperCase(Locale.ROOT);
String normalizedFieldKey = require(fieldKey, "fieldKey is required for telemetry field query");
String normalizedFieldKey = normalizeFieldKey(
normalizedProtocol,
require(fieldKey, "fieldKey is required for telemetry field query"));
QueryTimeRange range = QueryTimeRange.parse(dateFrom, dateTo);
TdenginePage<TdengineTelemetryFieldRow> page = reader.queryTelemetryFields(new TdengineTelemetryFieldQuery(
normalizedProtocol,
@@ -81,6 +93,13 @@ public final class TelemetryFieldHistoryController {
return TelemetryFieldPageResponse.from(page);
}
private static String normalizeFieldKey(String protocol, String fieldKey) {
if (!"JT808".equals(protocol)) {
return fieldKey;
}
return JT808_FIELD_ALIASES.getOrDefault(fieldKey, fieldKey);
}
private static String resolveVehicleKey(String protocol, String vehicleKey, String vin, String phone) {
String explicitVehicleKey = trimToNull(vehicleKey);
if (explicitVehicleKey != null) {

View File

@@ -78,6 +78,7 @@ class TelemetryFieldHistoryControllerTest {
null);
assertThat(reader.query.vehicleKey()).isEqualTo("jt808:g7gps");
assertThat(reader.query.fieldKey()).isEqualTo("speed_kmh");
}
@Test