a03_model_no_search_ads19.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package query
  2. import (
  3. "adm-data/errors"
  4. v1 "adm-data/pb/v1"
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. jsoniter "github.com/json-iterator/go"
  9. "git.getensh.com/common/gopkgsv2/logger"
  10. "go.uber.org/zap"
  11. "google.golang.org/grpc/status"
  12. "gorm.io/gorm"
  13. "git.getensh.com/common/gopkgsv2/database"
  14. )
  15. type a03Request struct {
  16. ModelNo string `json:"model_no"`
  17. }
  18. type a03Response struct {
  19. ModelNo string `json:"model_no"`
  20. VehicleBatch string `json:"vehicle_batch"`
  21. BrandName string `json:"brand_name"`
  22. VehicleTypeDetail string `json:"vehicle_type_detail"`
  23. ApprovedLoad string `json:"approved_load"`
  24. GrossMass string `json:"gross_mass"`
  25. UnladenMass string `json:"unladen_mass"`
  26. FuelTypeDetail string `json:"fuel_type_detail"`
  27. AxleNumber string `json:"axle_number"`
  28. EmissionStandard string `json:"emission_standard"`
  29. Wheelbase string `json:"wheelbase"`
  30. AxleWeight string `json:"axle_weight"`
  31. NumberOfLeafSprings string `json:"number_of_leaf_springs"`
  32. TyreNumber string `json:"tyre_number"`
  33. TyreSize string `json:"tyre_size"`
  34. ApproachingDepartureAngle string `json:"approaching_departure_angle"`
  35. FrontBackSuspention string `json:"front_back_suspention"`
  36. FrontWheelDistance string `json:"front_wheel_distance"`
  37. BackWheelDistance string `json:"back_wheel_distance"`
  38. VinRules string `json:"vin_rules"`
  39. Long string `json:"long"`
  40. Wide string `json:"wide"`
  41. High string `json:"high"`
  42. CargoLong string `json:"cargo_long"`
  43. CargoWide string `json:"cargo_wide"`
  44. CargoHigh string `json:"cargo_high"`
  45. TopSpeed string `json:"top_speed"`
  46. ApprovedNumber string `json:"approved_number"`
  47. NumberOfPassengers string `json:"number_of_passengers"`
  48. SteeringMode string `json:"steering_mode"`
  49. TractionMass string `json:"traction_mass"`
  50. LoadMassCoefficient string `json:"load_mass_coefficient"`
  51. SemitrailerSaddleMaxAllowGrossMass string `json:"semitrailer_saddle_max_allow_gross_mass"`
  52. CompanyName string `json:"company_name"`
  53. CompanyAddress string `json:"company_address"`
  54. }
  55. func ModelSearch(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  56. reply = &v1.QueryResponse{}
  57. // 捕获各个task中的异常并返回给调用者
  58. defer func() {
  59. if r := recover(); r != nil {
  60. err = fmt.Errorf("%+v", r)
  61. e := &status.Status{}
  62. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  63. logger.Error("err",
  64. zap.String("system_err", err.Error()),
  65. zap.Stack("stacktrace"))
  66. }
  67. }
  68. }()
  69. var req a03Request
  70. err = jsoniter.UnmarshalFromString(params, &req)
  71. if err != nil && req.ModelNo == "" {
  72. return nil, errors.ParamsError
  73. }
  74. db := database.DB()
  75. var res a03Response
  76. err = db.Raw("select model_no, vehicle_batch, brand_name, vehicle_type_detail, approved_load, gross_mass, unladen_mass, fuel_type_detail, "+
  77. "axle_number, emission_standard, wheelbase, axle_weight, number_of_leaf_springs, tyre_number, tyre_size, approaching_departure_angle, "+
  78. "front_back_suspention, front_wheel_distance, back_wheel_distance, vin_rules, `long`, wide, high, cargo_long, cargo_wide, cargo_high, top_speed, "+
  79. "approved_number, number_of_passengers, steering_mode, traction_mass, load_mass_coefficient, semitrailer_saddle_max_allow_gross_mass, "+
  80. "company_name, company_address from t_adm_ads19 where model_no = ? ", req.ModelNo).Find(&res).Error
  81. if err != nil {
  82. if err == gorm.ErrRecordNotFound {
  83. return reply, errors.DataNotExistError
  84. }
  85. return reply, errors.SystemError
  86. }
  87. reply.Data, _ = jsoniter.MarshalToString(res)
  88. return reply, nil
  89. }