f
This commit is contained in:
67
internal/domains/api/services/processors/qcxg/a8v3_shared.go
Normal file
67
internal/domains/api/services/processors/qcxg/a8v3_shared.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user