This commit is contained in:
2026-07-21 14:23:05 +08:00
parent 4794be896c
commit b966c2ec4b
9 changed files with 672 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
package qcxg
import (
"context"
"encoding/json"
"errors"
"fmt"
"hyapi-server/internal/domains/api/dto"
"hyapi-server/internal/domains/api/services/processors"
)
// a8v3RawResult QCXGA8V3 上游原始字段
type a8v3RawResult struct {
Usage string
RegisterDate string
InsuranceMonth string
VehicleModel string
Brand string
PlateNo string
EngineNo string
Vin string
}
func callA8V3ByVin(ctx context.Context, vinCode string, deps *processors.ProcessorDependencies) (*a8v3RawResult, error) {
params, err := json.Marshal(dto.QCXGA8V3Req{VinCode: vinCode})
if err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
respBytes, err := ProcessQCXGA8V3Request(ctx, params, deps)
if err != nil {
return nil, err
}
return parseA8V3Result(respBytes)
}
func parseA8V3Result(respBytes []byte) (*a8v3RawResult, error) {
var raw map[string]interface{}
if err := json.Unmarshal(respBytes, &raw); err != nil {
return nil, errors.Join(processors.ErrSystem, err)
}
return &a8v3RawResult{
Usage: asString(raw["usage"]),
RegisterDate: asString(raw["registerDate"]),
InsuranceMonth: asString(raw["insuranceMonth"]),
VehicleModel: asString(raw["clxh"]),
Brand: asString(raw["brand"]),
PlateNo: asString(raw["cph"]),
EngineNo: asString(raw["fdjh"]),
Vin: asString(raw["vin"]),
}, nil
}
func asString(v interface{}) string {
if v == nil {
return ""
}
switch t := v.(type) {
case string:
return t
default:
return fmt.Sprint(t)
}
}