f
This commit is contained in:
43
internal/domains/api/services/processors/qcxg/car_plate.go
Normal file
43
internal/domains/api/services/processors/qcxg/car_plate.go
Normal file
@@ -0,0 +1,43 @@
|
||||
package qcxg
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
//go:embed data/car_plate.json
|
||||
var carPlateJSON []byte
|
||||
|
||||
var carPlateCityMap map[string]string
|
||||
|
||||
func init() {
|
||||
carPlateCityMap = make(map[string]string)
|
||||
_ = json.Unmarshal(carPlateJSON, &carPlateCityMap)
|
||||
}
|
||||
|
||||
// lookupCityByPlateNo 根据车牌号前缀(省简称+字母)查城市,未匹配返回 "-"
|
||||
func lookupCityByPlateNo(plateNo string) string {
|
||||
prefix := extractPlatePrefix(plateNo)
|
||||
if prefix == "" {
|
||||
return "-"
|
||||
}
|
||||
if city, ok := carPlateCityMap[prefix]; ok && city != "" {
|
||||
return city
|
||||
}
|
||||
return "-"
|
||||
}
|
||||
|
||||
// extractPlatePrefix 取车牌前两个字符作为字典键,如 "鲁A12345" -> "鲁A"
|
||||
func extractPlatePrefix(plateNo string) string {
|
||||
plateNo = strings.TrimSpace(plateNo)
|
||||
if plateNo == "" {
|
||||
return ""
|
||||
}
|
||||
if utf8.RuneCountInString(plateNo) < 2 {
|
||||
return ""
|
||||
}
|
||||
runes := []rune(plateNo)
|
||||
return string(runes[:2])
|
||||
}
|
||||
Reference in New Issue
Block a user