feat(platform): connect mysql production store

This commit is contained in:
lingniu
2026-07-03 21:09:43 +08:00
parent 859bc3e9ee
commit 2de569f104
6 changed files with 273 additions and 6 deletions

View File

@@ -27,14 +27,14 @@ func buildVehicleListSQL(query url.Values) SQLQuery {
}
args = append(args, limit, offset)
return SQLQuery{
Text: `SELECT b.vin, b.plate, b.phone, b.oem, COALESCE(s.protocol, '') AS protocol, ` +
Text: `SELECT s.vin, COALESCE(NULLIF(s.plate, ''), b.plate, '') AS plate, COALESCE(b.phone, '') AS phone, COALESCE(b.oem, '') AS oem, s.protocol, ` +
`CASE WHEN s.updated_at >= DATE_SUB(NOW(), INTERVAL 1 MINUTE) THEN 1 ELSE 0 END AS online, ` +
`COALESCE(DATE_FORMAT(s.updated_at, '%Y-%m-%d %H:%i:%s'), '') AS last_seen, ` +
`COALESCE(CONCAT(l.longitude, ',', l.latitude), '') AS location_text, ` +
`CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 100 ELSE 0 END AS binding_score ` +
`FROM vehicle_identity_binding b ` +
`LEFT JOIN vehicle_realtime_snapshot s ON s.vin = b.vin ` +
`LEFT JOIN vehicle_realtime_location l ON l.vin = b.vin ` +
`CASE WHEN b.vin IS NOT NULL AND b.vin <> '' THEN 100 ELSE 60 END AS binding_score ` +
`FROM vehicle_realtime_snapshot s ` +
`LEFT JOIN vehicle_identity_binding b ON b.vin = s.vin ` +
`LEFT JOIN vehicle_realtime_location l ON l.vin = s.vin AND l.protocol = s.protocol ` +
`WHERE ` + strings.Join(where, " AND ") + ` ORDER BY s.updated_at DESC LIMIT ? OFFSET ?`,
Args: args,
}