p11.go 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package query
  2. import (
  3. "adm-data/errors"
  4. v1 "adm-data/pb/v1"
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "gorm.io/gorm"
  9. jsoniter "github.com/json-iterator/go"
  10. "git.getensh.com/common/gopkgsv2/database"
  11. "git.getensh.com/common/gopkgsv2/logger"
  12. "go.uber.org/zap"
  13. "google.golang.org/grpc/status"
  14. )
  15. type p11Request struct {
  16. Vin string `json:"vin"`
  17. }
  18. type p11Response struct {
  19. Vin string `json:"vin"`
  20. SySeriesId string `json:"sy_series_id"`
  21. VehicleSeries string `json:"vehicle_series"`
  22. SyStyleId string `json:"sy_style_id"`
  23. VehicleStyle string `json:"vehicle_style"`
  24. VehicleBrand string `json:"vehicle_brand"`
  25. VehicleConfigDetail string `json:"vehicle_config_detail"`
  26. BodyStruct string `json:"body_struct"`
  27. BrandId string `json:"brand_id"`
  28. BrandName string `json:"brand_name"`
  29. SeriesId string `json:"series_id"`
  30. SeriesName string `json:"series_name"`
  31. StyleId string `json:"style_id"`
  32. StyleName string `json:"style_name"`
  33. ModelYear string `json:"model_year"`
  34. AutoPrice string `json:"auto_price"`
  35. DriveWay string `json:"drive_way"`
  36. EngineNo string `json:"engine_no"`
  37. EngineType string `json:"engine_type"`
  38. BodyColorDetail string `json:"body_color_detail"`
  39. ReleaseDate string `json:"release_date"`
  40. EmissionStandard string `json:"emission_standard"`
  41. ApprovedLoad string `json:"approved_load"`
  42. ApprovedNumber string `json:"approved_number"`
  43. AxleNumber string `json:"axle_number"`
  44. FrontWheelDistance string `json:"front_wheel_distance"`
  45. BackWheelDistance string `json:"back_wheel_distance"`
  46. Displacement string `json:"displacement"`
  47. DisplacementL string `json:"displacement_l"`
  48. AirIntakForm string `json:"air_intak_form"`
  49. FuelTypeDetail string `json:"fuel_type_detail"`
  50. High string `json:"high"`
  51. Wide string `json:"wide"`
  52. Long string `json:"long"`
  53. GrossMass string `json:"gross_mass"`
  54. ModelNo string `json:"model_no"`
  55. OilWear string `json:"oil_wear"`
  56. RatedPower string `json:"rated_power"`
  57. TractionMass string `json:"traction_mass"`
  58. TyreNumber string `json:"tyre_number"`
  59. TyreSize string `json:"tyre_size"`
  60. UnladenMass string `json:"unladen_mass"`
  61. WheelBase string `json:"wheel_base"`
  62. VehicleTypeDetail string `json:"vehicle_type_detail"`
  63. }
  64. func p11(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  65. reply = &v1.QueryResponse{}
  66. // 捕获各个task中的异常并返回给调用者
  67. defer func() {
  68. if r := recover(); r != nil {
  69. err = fmt.Errorf("%+v", r)
  70. e := &status.Status{}
  71. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  72. logger.Error("err",
  73. zap.String("system_err", err.Error()),
  74. zap.Stack("stacktrace"))
  75. }
  76. }
  77. }()
  78. var req p11Request
  79. err = jsoniter.UnmarshalFromString(params, &req)
  80. if err != nil || len(req.Vin) == 0 {
  81. return nil, errors.ParamsError
  82. }
  83. sql := "SELECT * FROM v_adm_vin_style WHERE vin = ?"
  84. var p11resp p11Response
  85. err = database.DB().Raw(sql, req.Vin).Find(&p11resp).Error
  86. if err != nil {
  87. if err == gorm.ErrRecordNotFound {
  88. return reply, errors.DataNotExistError
  89. }
  90. return reply, errors.SystemError
  91. }
  92. p11str, _ := jsoniter.MarshalToString(p11resp)
  93. p11Map := make(map[string]interface{})
  94. jsoniter.Unmarshal([]byte(p11str), &p11Map)
  95. formatData(p11Map)
  96. reply.Data, _ = jsoniter.MarshalToString(p11Map)
  97. /*response := p11Response{}
  98. err = jsoniter.UnmarshalFromString(reply.Data, &response)
  99. err = insertTable("P11", "VIN唯一定型", "32,35,37,38,51", req, response)
  100. if err != nil {
  101. return nil, err
  102. }*/
  103. return reply, nil
  104. }