f
This commit is contained in:
@@ -4,16 +4,6 @@ import "strings"
|
|||||||
|
|
||||||
const defaultPlateType = "02"
|
const defaultPlateType = "02"
|
||||||
|
|
||||||
// plateTypeToPlateColor 将车牌类型编码转换为 ETC 人车关系核验所需的车牌颜色。
|
|
||||||
func plateTypeToPlateColor(plateType string) string {
|
|
||||||
code := normalizePlateType(plateType)
|
|
||||||
if color, ok := plateTypePlateColorMap[code]; ok {
|
|
||||||
return color
|
|
||||||
}
|
|
||||||
return "0"
|
|
||||||
}
|
|
||||||
|
|
||||||
// normalizePlateType 归一化车牌类型,空值默认小型汽车(02)。
|
|
||||||
func normalizePlateType(plateType string) string {
|
func normalizePlateType(plateType string) string {
|
||||||
code := strings.TrimSpace(plateType)
|
code := strings.TrimSpace(plateType)
|
||||||
if code == "" {
|
if code == "" {
|
||||||
@@ -22,8 +12,18 @@ func normalizePlateType(plateType string) string {
|
|||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
// plateTypePlateColorMap 车牌类型 -> ETC 车牌颜色
|
func etcPlateColorParam(plateType string) (color string, include bool) {
|
||||||
// 0蓝 1黄 2黑 3白 4渐变绿 5黄绿双拼 6蓝白渐变 7临时 11绿 12红
|
code := strings.TrimSpace(plateType)
|
||||||
|
if code == "" || code == "02" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
color, ok := plateTypePlateColorMap[code]
|
||||||
|
if !ok || color == "0" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return color, true
|
||||||
|
}
|
||||||
|
|
||||||
var plateTypePlateColorMap = map[string]string{
|
var plateTypePlateColorMap = map[string]string{
|
||||||
"01": "1",
|
"01": "1",
|
||||||
"02": "0",
|
"02": "0",
|
||||||
@@ -51,3 +51,26 @@ var plateTypePlateColorMap = map[string]string{
|
|||||||
"51": "5",
|
"51": "5",
|
||||||
"52": "11",
|
"52": "11",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildETCShujubaoParams(plateNo, name, plateType string) map[string]interface{} {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"key": "a2f32fc54b44ebc85b97a2aaff1734ec",
|
||||||
|
"carNo": plateNo,
|
||||||
|
"name": name,
|
||||||
|
}
|
||||||
|
if color, include := etcPlateColorParam(plateType); include {
|
||||||
|
params["plateColor"] = color
|
||||||
|
}
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildETCTianyuanParams(plateNo, name, plateType string) map[string]string {
|
||||||
|
params := map[string]string{
|
||||||
|
"plate_no": plateNo,
|
||||||
|
"name": name,
|
||||||
|
}
|
||||||
|
if color, include := etcPlateColorParam(plateType); include {
|
||||||
|
params["plate_color"] = color
|
||||||
|
}
|
||||||
|
return params
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,11 +23,7 @@ func ProcessQCXG7K2NRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
|
|
||||||
plateType := normalizePlateType(paramsDto.PlateType)
|
plateType := normalizePlateType(paramsDto.PlateType)
|
||||||
|
|
||||||
etcParams, err := json.Marshal(map[string]string{
|
etcParams, err := json.Marshal(buildETCTianyuanParams(paramsDto.PlateNo, paramsDto.Name, paramsDto.PlateType))
|
||||||
"plate_no": paramsDto.PlateNo,
|
|
||||||
"name": paramsDto.Name,
|
|
||||||
"plate_color": plateTypeToPlateColor(paramsDto.PlateType),
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Join(processors.ErrSystem, err)
|
return nil, errors.Join(processors.ErrSystem, err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user