f
This commit is contained in:
@@ -4,16 +4,7 @@ import "strings"
|
|||||||
|
|
||||||
const defaultPlateType = "02"
|
const defaultPlateType = "02"
|
||||||
|
|
||||||
// plateTypeToPlateColor 将车牌类型编码转换为 ETC 人车关系核验所需的车牌颜色。
|
// normalizePlateType 归一化车牌类型,空值默认小型汽车(02),供行驶证 V2 使用。
|
||||||
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,11 +13,25 @@ func normalizePlateType(plateType string) string {
|
|||||||
return code
|
return code
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// etcPlateColorParam 将车牌类型转为 ETC 接口的 plateColor。
|
||||||
|
// 第二个返回值表示是否需要传 plateColor;不传时由数据宝按默认蓝牌处理。
|
||||||
|
func etcPlateColorParam(plateType string) (color string, include bool) {
|
||||||
|
code := strings.TrimSpace(plateType)
|
||||||
|
if code == "" || code == "02" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
color, ok := plateTypePlateColorMap[code]
|
||||||
|
if !ok || color == "0" {
|
||||||
|
return "", false
|
||||||
|
}
|
||||||
|
return color, true
|
||||||
|
}
|
||||||
|
|
||||||
// plateTypePlateColorMap 车牌类型 -> ETC 车牌颜色
|
// plateTypePlateColorMap 车牌类型 -> ETC 车牌颜色
|
||||||
// 0蓝 1黄 2黑 3白 4渐变绿 5黄绿双拼 6蓝白渐变 7临时 11绿 12红
|
// 0蓝 1黄 2黑 3白 4渐变绿 5黄绿双拼 6蓝白渐变 7临时 11绿 12红
|
||||||
var plateTypePlateColorMap = map[string]string{
|
var plateTypePlateColorMap = map[string]string{
|
||||||
"01": "1", // 大型汽车 -> 黄色
|
"01": "1", // 大型汽车 -> 黄色
|
||||||
"02": "0", // 小型汽车 -> 蓝色
|
"02": "0", // 小型汽车 -> 蓝色(默认不传 plateColor)
|
||||||
"03": "2", // 使馆汽车 -> 黑色
|
"03": "2", // 使馆汽车 -> 黑色
|
||||||
"04": "2", // 领馆汽车 -> 黑色
|
"04": "2", // 领馆汽车 -> 黑色
|
||||||
"05": "2", // 境外汽车 -> 黑色
|
"05": "2", // 境外汽车 -> 黑色
|
||||||
@@ -47,7 +52,30 @@ var plateTypePlateColorMap = map[string]string{
|
|||||||
"22": "7", // 临时行驶车 -> 临时牌照
|
"22": "7", // 临时行驶车 -> 临时牌照
|
||||||
"23": "3", // 警用汽车 -> 白色
|
"23": "3", // 警用汽车 -> 白色
|
||||||
"24": "3", // 警用摩托 -> 白色
|
"24": "3", // 警用摩托 -> 白色
|
||||||
"38": "0", // 预留 -> 蓝色
|
"38": "0", // 预留 -> 蓝色(等同默认,不传)
|
||||||
"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
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,24 +2,27 @@ package qcxg
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestPlateTypeToPlateColor(t *testing.T) {
|
func TestEtcPlateColorParam(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
plateType string
|
plateType string
|
||||||
want string
|
wantColor string
|
||||||
|
wantInclude bool
|
||||||
}{
|
}{
|
||||||
{"", "0"},
|
{"", "", false},
|
||||||
{"02", "0"},
|
{"02", "", false},
|
||||||
{"01", "1"},
|
{"01", "1", true},
|
||||||
{"52", "11"},
|
{"52", "11", true},
|
||||||
{"51", "5"},
|
{"51", "5", true},
|
||||||
{"23", "3"},
|
{"23", "3", true},
|
||||||
{"22", "7"},
|
{"38", "", false},
|
||||||
{"99", "0"},
|
{"99", "", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
if got := plateTypeToPlateColor(tt.plateType); got != tt.want {
|
color, include := etcPlateColorParam(tt.plateType)
|
||||||
t.Fatalf("plateTypeToPlateColor(%q) = %q, want %q", tt.plateType, got, tt.want)
|
if color != tt.wantColor || include != tt.wantInclude {
|
||||||
|
t.Fatalf("etcPlateColorParam(%q) = (%q, %v), want (%q, %v)",
|
||||||
|
tt.plateType, color, include, tt.wantColor, tt.wantInclude)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,3 +35,15 @@ func TestNormalizePlateType(t *testing.T) {
|
|||||||
t.Fatalf("normalizePlateType trim = %q, want 51", got)
|
t.Fatalf("normalizePlateType trim = %q, want 51", got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildETCShujubaoParams(t *testing.T) {
|
||||||
|
params := buildETCShujubaoParams("桂A12345", "张三", "01")
|
||||||
|
if params["plateColor"] != "1" {
|
||||||
|
t.Fatalf("plateColor = %v, want 1", params["plateColor"])
|
||||||
|
}
|
||||||
|
|
||||||
|
params = buildETCShujubaoParams("桂A12345", "张三", "")
|
||||||
|
if _, ok := params["plateColor"]; ok {
|
||||||
|
t.Fatalf("default should not include plateColor, got %v", params)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -23,12 +23,7 @@ func ProcessQCXG7K2NRequest(ctx context.Context, params []byte, deps *processors
|
|||||||
}
|
}
|
||||||
|
|
||||||
plateType := normalizePlateType(paramsDto.PlateType)
|
plateType := normalizePlateType(paramsDto.PlateType)
|
||||||
etcParams := map[string]interface{}{
|
etcParams := buildETCShujubaoParams(paramsDto.PlateNo, paramsDto.Name, paramsDto.PlateType)
|
||||||
"key": "a2f32fc54b44ebc85b97a2aaff1734ec",
|
|
||||||
"carNo": paramsDto.PlateNo,
|
|
||||||
"name": paramsDto.Name,
|
|
||||||
"plateColor": plateTypeToPlateColor(paramsDto.PlateType),
|
|
||||||
}
|
|
||||||
|
|
||||||
data, err := deps.ShujubaoService.CallAPI(ctx, "/communication/personal/10093", etcParams)
|
data, err := deps.ShujubaoService.CallAPI(ctx, "/communication/personal/10093", etcParams)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user