68 lines
1.5 KiB
Go
68 lines
1.5 KiB
Go
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)
|
|
}
|
|
}
|