package query import ( "context" "gd_adm_data/apis" "gd_adm_data/errors" "gd_adm_data/model" jsoniter "github.com/json-iterator/go" "git.getensh.com/common/gopkgsv2/database" ) type a01Request struct { PlateNo string `json:"plate_no"` PlateType string `json:"plate_type"` } type a01Data struct { PlateType string `json:"plate_type"` Vin string `json:"vin"` UpdatedAt int64 `json:"updated_at"` } type a01Response struct { List []a01Data `json:"list"` } // 车牌查vin func A01(ctx context.Context, params string) (reply *apis.QueryResponse, err error) { reply = &apis.QueryResponse{} var req a01Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil && (req.PlateNo == "" || req.PlateType == "") { return nil, errors.ParamsError } if req.PlateType == "" { list, err := model.NewDws1Model().List(database.DB().Where("plate_no = ?", req.PlateNo)) if err != nil { return reply, errors.DataNotExistError } res := a01Response{ List: make([]a01Data, 0, len(list)), } for _, v := range list { res.List = append(res.List, a01Data{ PlateType: v.PlateType, Vin: v.Vin, UpdatedAt: v.UpdatedAt, }) } reply.Data, _ = jsoniter.MarshalToString(res) return reply, nil } list, err := model.NewDws1Model().List(database.DB().Where("plate_no = ? and plate_type = ?", req.PlateNo, req.PlateType)) if err != nil { return reply, errors.DataNotExistError } res := a01Response{ List: make([]a01Data, 0, len(list)), } for _, v := range list { res.List = append(res.List, a01Data{ PlateType: v.PlateType, Vin: v.Vin, UpdatedAt: v.UpdatedAt, }) } reply.Data, _ = jsoniter.MarshalToString(res) return reply, nil }