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/logger" "go.uber.org/zap" "google.golang.org/grpc/status" "git.getensh.com/common/gopkgsv2/database" ) type a02Req struct { Vin string `json:"vin"` PlateType string `json:"plate_type"` } type a02Response struct { PlateNo string `json:"plate_no"` PlateType string `json:"plate_type"` Vin string `json:"vin"` // EngineNo string `json:"engine_no"` // EngineType string `json:"engine_type"` // ModelNo string `json:"model_no"` // BrandName string `json:"brand_name"` // InitialRegistrationDate string `json:"initial_registration_date"` //16 VehicleType string `json:"vehicle_type"` //18 VehicleTypeDetail string `json:"vehicle_type_detail"` //18 UseProperty string `json:"use_property"` //16 UsePropertyDetail string `json:"use_property_detail"` //15 VehicleBodyColor string `json:"vehicle_body_color"` //16 VehicleBodyColorDetail string `json:"vehicle_body_color_detail"` // ApprovedLoad string `json:"approved_load"` // ApprovedNumber string `json:"approved_number"` // AxleNumber string `json:"axle_number"` // AxleWeight string `json:"axle_weight"` // Displacement string `json:"displacement"` // FrontWheelDistance string `json:"front_wheel_distance"` // BackWheelDistance string `json:"back_wheel_distance"` // FuelType string `json:"fuel_type"` //16 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"` // High string `json:"high"` // Long string `json:"long"` // Wide string `json:"wide"` // OilWear string `json:"oil_wear"` // TractionMass string `json:"traction_mass"` // TyreSize string `json:"tyre_size"` // TyreNumber string `json:"tyre_number"` // WheelBase string `json:"wheel_base"` // CompulsoryScrapTo string `json:"compulsory_scrap_to"` InspectionResultEffectiveTo string `json:"inspection_result_effective_to"` //CertificateNumber string `json:"certificate_number"` // //CertificateDate string `json:"certificate_date"` // //VehicleManufacturer string `json:"vehicle_manufacturer"` // //ChassisModel string `json:"chassis_model"` // //ChassisId string `json:"chassis_id"` // //ChassisCertificateNumber string `json:"chassis_certificate_number"` // //DisplacementL string `json:"displacement_l"` // //CargoLong string `json:"cargo_long"` // //CargoWide string `json:"cargo_wide"` // //CargoHigh string `json:"cargo_high"` // //NumberOfLeafSprings string `json:"number_of_leaf_springs"` // //SteeringMode string `json:"steering_mode"` // //LoadMassCoefficient string `json:"load_mass_coefficient"` // //SemitrailerSaddleMaxAllowGrossMass string `json:"semitrailer_saddle_max_allow_gross_mass"` // //NumberOfPassengers string `json:"number_of_passengers"` // //TopSpeed string `json:"top_speed"` // } func VINBasicInfo(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 a02Req err = jsoniter.UnmarshalFromString(params, &req) if err != nil || req.Vin == "" { return nil, errors.ParamsError } db := database.DB() var res a02Response sql := "select * from v_adm_vin where vin = ? " err = db.Raw(sql, req.Vin).Find(&res).Error if err != nil { if err == gorm.ErrRecordNotFound { return reply, errors.DataNotExistError } logger.Error("mysql", zap.String("sql", sql), zap.String("fields", req.Vin), zap.String("error", err.Error())) return reply, errors.DataBaseError } if res.PlateType == "" { res.PlateType = calcPlateType(res.Long, res.ApprovedNumber, res.GrossMass) } if req.PlateType != ""{ if res.PlateType != "" { if req.PlateType == "01" || req.PlateType == "51"{ if res.PlateType != "01"{ return reply,errors.DataNotExistError } }else if req.PlateType == "02" || req.PlateType == "52"{ if res.PlateType != "02"{ return reply,errors.DataNotExistError } } } res.PlateType = req.PlateType } a02Str, _ := jsoniter.MarshalToString(res) a02Map := make(map[string]interface{}) jsoniter.Unmarshal([]byte(a02Str), &a02Map) formatData(a02Map) reply.Data, _ = jsoniter.MarshalToString(a02Map) return reply, nil }