package query import ( "adm-data/errors" "adm-data/pb/v1" "context" "encoding/json" "fmt" "github.com/json-iterator/go" "git.getensh.com/common/gopkgsv2/database" "git.getensh.com/common/gopkgsv2/logger" "go.uber.org/zap" "google.golang.org/grpc/status" ) type a04Request struct { PlateNo string `json:"plate_no"` PlateType string `json:"plate_type"` Vin string `json:"vin"` } type a04Response struct { PlateNo string `json:"plate_no"` PlateType string `json:"plate_type"` Owner string `json:"owner"` Vin string `json:"vin"` EngineType string `json:"engine_type"` EngineNo string `json:"engine_no"` ModelNo string `json:"model_no"` BrandName string `json:"brand_name"` InitialRegistrationDate string `json:"initial_registration_date"` InsuranceFirstDate string `json:"insurance_first_date"` VehicleType string `json:"vehicle_type"` UseProperty string `json:"use_property"` UsePropertyDetail string `json:"use_property_detail"` VehicleBodyColor string `json:"vehicle_body_color"` VehicleBodyColorDetail string `json:"vehicle_body_color_detail"` ApprovedLoad string `json:"approved_load"` ApprovedNumber string `json:"approved_number"` AxleWeight string `json:"axle_weight"` AxleNumber string `json:"axle_number"` Displacement string `json:"displacement"` FrontWheelDistance string `json:"front_wheel_distance"` BackWheelDistance string `json:"back_wheel_distance"` FuelType string `json:"fuel_type"` FuelTypeDetail string `json:"fuel_type_detail"` GrossMass string `json:"gross_mass"` RatedPower string `json:"rated_power"` ReleaseDate string `json:"release_date"` UnladenMass string `json:"unladen_mass"` EmissionStandard string `json:"emission_standard"` Long string `json:"long"` Wide string `json:"wide"` High string `json:"high"` OilWear string `json:"oil_wear"` TractionMass string `json:"traction_mass"` TyreSize string `json:"tyre_size"` WheelBase string `json:"wheel_base"` CompulsoryScrapTo string `json:"compulsory_scrap_to" description:"强制报废日期"` InspectionResultEffectiveTo string `json:"inspection_result_effective_to" description:"检验有效期止"` TyreNumber string `json:"tyre_number"` VehicleTypeDetail string `json:"vehicle_type_detail"` } func a04(ctx context.Context, params string) (reply *v1.QueryResponse, err error) { reply = &v1.QueryResponse{} // 捕获各个task中的异常并返回给调用者 defer func() { if r := recover(); r != nil { err = fmt.Errorf("%+v", r) e := &status.Status{} if er := json.Unmarshal([]byte(err.Error()), e); er != nil { logger.Error("err", zap.String("system_err", err.Error()), zap.Stack("stacktrace")) } } }() var req a04Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil { return nil, errors.ParamsError } if (req.PlateNo == "" || req.PlateType == "") && req.Vin == "" { return nil, errors.ParamsError } a04Rsp := a04Response{} if req.PlateNo != "" && req.PlateType != ""{ sql := `SELECT * FROM v_adm_vehicle WHERE plate_no = ? and plate_type = ? LIMIT 1` err = database.DB().Raw(sql,req.PlateNo,req.PlateType).Find(&a04Rsp).Error }else{ sql := `SELECT * FROM v_adm_vin WHERE vin = ? LIMIT 1` err = database.DB().Raw(sql,req.Vin).Find(&a04Rsp).Error } if err != nil{ return nil, errors.DataNotExistError } a04Str,_ := jsoniter.MarshalToString(a04Rsp) a04Map := make(map[string]interface{}) jsoniter.Unmarshal([]byte(a04Str),&a04Map) formatData(a04Map) reply.Data, _ = jsoniter.MarshalToString(a04Map) return reply, nil }