fix(go): filter realtime mysql snapshots by business events
This commit is contained in:
@@ -119,7 +119,7 @@ func (w *SnapshotWriter) Update(ctx context.Context, env envelope.FrameEnvelope)
|
||||
if vin == "" {
|
||||
return nil
|
||||
}
|
||||
if !hasRealtimePayload(env) {
|
||||
if !isRealtimeSnapshotEvent(env) {
|
||||
return nil
|
||||
}
|
||||
plate, err := w.plateForEnvelope(ctx, env)
|
||||
@@ -365,16 +365,35 @@ func nullableTime(ms int64) any {
|
||||
return time.UnixMilli(ms)
|
||||
}
|
||||
|
||||
func hasRealtimePayload(env envelope.FrameEnvelope) bool {
|
||||
if len(env.Fields) > 0 {
|
||||
return true
|
||||
func isRealtimeSnapshotEvent(env envelope.FrameEnvelope) bool {
|
||||
switch env.Protocol {
|
||||
case envelope.ProtocolGB32960:
|
||||
return env.MessageID == "0x02" && hasGB32960RealtimeDataUnits(env)
|
||||
case envelope.ProtocolJT808:
|
||||
return env.MessageID == "0x0200" && hasLocationFields(env)
|
||||
case envelope.ProtocolYutongMQTT:
|
||||
return len(env.Fields) > 0
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func hasGB32960RealtimeDataUnits(env envelope.FrameEnvelope) bool {
|
||||
if units, ok := env.Parsed["data_units"].([]any); ok && len(units) > 0 {
|
||||
return true
|
||||
}
|
||||
if units, ok := env.Parsed["data_units"].([]map[string]any); ok && len(units) > 0 {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasLocationFields(env envelope.FrameEnvelope) bool {
|
||||
_, okLat := numberField(env.Fields, envelope.FieldLatitude)
|
||||
_, okLon := numberField(env.Fields, envelope.FieldLongitude)
|
||||
return okLat && okLon
|
||||
}
|
||||
|
||||
const realtimeSnapshotTableSQL = `CREATE TABLE IF NOT EXISTS vehicle_realtime_snapshot (
|
||||
protocol VARCHAR(32) NOT NULL,
|
||||
vin VARCHAR(32) NOT NULL DEFAULT '',
|
||||
|
||||
Reference in New Issue
Block a user