package query import ( "adm-data/errors" v1 "adm-data/pb/v1" "context" "encoding/json" "fmt" jsoniter "github.com/json-iterator/go" "git.getensh.com/common/gopkgsv2/logger" "go.uber.org/zap" "google.golang.org/grpc/status" "gorm.io/gorm" "git.getensh.com/common/gopkgsv2/database" ) type a03Request struct { ModelNo string `json:"model_no"` } type a03Response struct { ModelNo string `json:"model_no"` VehicleBatch string `json:"vehicle_batch"` BrandName string `json:"brand_name"` VehicleTypeDetail string `json:"vehicle_type_detail"` ApprovedLoad string `json:"approved_load"` GrossMass string `json:"gross_mass"` UnladenMass string `json:"unladen_mass"` FuelTypeDetail string `json:"fuel_type_detail"` AxleNumber string `json:"axle_number"` EmissionStandard string `json:"emission_standard"` Wheelbase string `json:"wheelbase"` AxleWeight string `json:"axle_weight"` NumberOfLeafSprings string `json:"number_of_leaf_springs"` TyreNumber string `json:"tyre_number"` TyreSize string `json:"tyre_size"` ApproachingDepartureAngle string `json:"approaching_departure_angle"` FrontBackSuspention string `json:"front_back_suspention"` FrontWheelDistance string `json:"front_wheel_distance"` BackWheelDistance string `json:"back_wheel_distance"` VinRules string `json:"vin_rules"` Long string `json:"long"` Wide string `json:"wide"` High string `json:"high"` CargoLong string `json:"cargo_long"` CargoWide string `json:"cargo_wide"` CargoHigh string `json:"cargo_high"` TopSpeed string `json:"top_speed"` ApprovedNumber string `json:"approved_number"` NumberOfPassengers string `json:"number_of_passengers"` SteeringMode string `json:"steering_mode"` TractionMass string `json:"traction_mass"` LoadMassCoefficient string `json:"load_mass_coefficient"` SemitrailerSaddleMaxAllowGrossMass string `json:"semitrailer_saddle_max_allow_gross_mass"` CompanyName string `json:"company_name"` CompanyAddress string `json:"company_address"` } func ModelSearch(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 a03Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil && req.ModelNo == "" { return nil, errors.ParamsError } db := database.DB() var res a03Response err = db.Raw("select model_no, vehicle_batch, brand_name, vehicle_type_detail, approved_load, gross_mass, unladen_mass, fuel_type_detail, "+ "axle_number, emission_standard, wheelbase, axle_weight, number_of_leaf_springs, tyre_number, tyre_size, approaching_departure_angle, "+ "front_back_suspention, front_wheel_distance, back_wheel_distance, vin_rules, `long`, wide, high, cargo_long, cargo_wide, cargo_high, top_speed, "+ "approved_number, number_of_passengers, steering_mode, traction_mass, load_mass_coefficient, semitrailer_saddle_max_allow_gross_mass, "+ "company_name, company_address from t_adm_ads19 where model_no = ? ", req.ModelNo).Find(&res).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, errors.DataNotExistError } return reply, errors.SystemError } reply.Data, _ = jsoniter.MarshalToString(res) return reply, nil }