package query import ( "adm-data/errors" v1 "adm-data/pb/v1" "context" "encoding/json" "fmt" "gorm.io/gorm" jsoniter "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 p11Request struct { Vin string `json:"vin"` } type p11Response struct { Vin string `json:"vin"` SySeriesId string `json:"sy_series_id"` VehicleSeries string `json:"vehicle_series"` SyStyleId string `json:"sy_style_id"` VehicleStyle string `json:"vehicle_style"` VehicleBrand string `json:"vehicle_brand"` VehicleConfigDetail string `json:"vehicle_config_detail"` BodyStruct string `json:"body_struct"` BrandId string `json:"brand_id"` BrandName string `json:"brand_name"` SeriesId string `json:"series_id"` SeriesName string `json:"series_name"` StyleId string `json:"style_id"` StyleName string `json:"style_name"` ModelYear string `json:"model_year"` AutoPrice string `json:"auto_price"` DriveWay string `json:"drive_way"` EngineNo string `json:"engine_no"` EngineType string `json:"engine_type"` BodyColorDetail string `json:"body_color_detail"` ReleaseDate string `json:"release_date"` EmissionStandard string `json:"emission_standard"` ApprovedLoad string `json:"approved_load"` ApprovedNumber string `json:"approved_number"` AxleNumber string `json:"axle_number"` FrontWheelDistance string `json:"front_wheel_distance"` BackWheelDistance string `json:"back_wheel_distance"` Displacement string `json:"displacement"` DisplacementL string `json:"displacement_l"` AirIntakForm string `json:"air_intak_form"` FuelTypeDetail string `json:"fuel_type_detail"` High string `json:"high"` Wide string `json:"wide"` Long string `json:"long"` GrossMass string `json:"gross_mass"` ModelNo string `json:"model_no"` OilWear string `json:"oil_wear"` RatedPower string `json:"rated_power"` TractionMass string `json:"traction_mass"` TyreNumber string `json:"tyre_number"` TyreSize string `json:"tyre_size"` UnladenMass string `json:"unladen_mass"` WheelBase string `json:"wheel_base"` VehicleTypeDetail string `json:"vehicle_type_detail"` } func p11(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 p11Request err = jsoniter.UnmarshalFromString(params, &req) if err != nil || len(req.Vin) == 0 { return nil, errors.ParamsError } sql := "SELECT * FROM v_adm_vin_style WHERE vin = ?" var p11resp p11Response err = database.DB().Raw(sql, req.Vin).Find(&p11resp).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, errors.DataNotExistError } return reply, errors.SystemError } p11str, _ := jsoniter.MarshalToString(p11resp) p11Map := make(map[string]interface{}) jsoniter.Unmarshal([]byte(p11str), &p11Map) formatData(p11Map) reply.Data, _ = jsoniter.MarshalToString(p11Map) /*response := p11Response{} err = jsoniter.UnmarshalFromString(reply.Data, &response) err = insertTable("P11", "VIN唯一定型", "32,35,37,38,51", req, response) if err != nil { return nil, err }*/ return reply, nil }