a02_vin_basic_info.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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/logger"
  11. "go.uber.org/zap"
  12. "google.golang.org/grpc/status"
  13. "git.getensh.com/common/gopkgsv2/database"
  14. )
  15. type a02Req struct {
  16. Vin string `json:"vin"`
  17. PlateType string `json:"plate_type"`
  18. }
  19. type a02Response struct {
  20. PlateNo string `json:"plate_no"`
  21. PlateType string `json:"plate_type"`
  22. Vin string `json:"vin"` //
  23. EngineNo string `json:"engine_no"` //
  24. EngineType string `json:"engine_type"` //
  25. ModelNo string `json:"model_no"` //
  26. BrandName string `json:"brand_name"` //
  27. InitialRegistrationDate string `json:"initial_registration_date"` //16
  28. VehicleType string `json:"vehicle_type"` //18
  29. VehicleTypeDetail string `json:"vehicle_type_detail"` //18
  30. UseProperty string `json:"use_property"` //16
  31. UsePropertyDetail string `json:"use_property_detail"` //15
  32. VehicleBodyColor string `json:"vehicle_body_color"` //16
  33. VehicleBodyColorDetail string `json:"vehicle_body_color_detail"` //
  34. ApprovedLoad string `json:"approved_load"` //
  35. ApprovedNumber string `json:"approved_number"` //
  36. AxleNumber string `json:"axle_number"` //
  37. AxleWeight string `json:"axle_weight"` //
  38. Displacement string `json:"displacement"` //
  39. FrontWheelDistance string `json:"front_wheel_distance"` //
  40. BackWheelDistance string `json:"back_wheel_distance"` //
  41. FuelType string `json:"fuel_type"` //16
  42. FuelTypeDetail string `json:"fuel_type_detail"` //
  43. GrossMass string `json:"gross_mass"` //
  44. RatedPower string `json:"rated_power"` //
  45. ReleaseDate string `json:"release_date"` //
  46. UnladenMass string `json:"unladen_mass"` //
  47. EmissionStandard string `json:"emission_standard"` //
  48. High string `json:"high"` //
  49. Long string `json:"long"` //
  50. Wide string `json:"wide"` //
  51. OilWear string `json:"oil_wear"` //
  52. TractionMass string `json:"traction_mass"` //
  53. TyreSize string `json:"tyre_size"` //
  54. TyreNumber string `json:"tyre_number"` //
  55. WheelBase string `json:"wheel_base"` //
  56. CompulsoryScrapTo string `json:"compulsory_scrap_to"`
  57. InspectionResultEffectiveTo string `json:"inspection_result_effective_to"`
  58. //CertificateNumber string `json:"certificate_number"` //
  59. //CertificateDate string `json:"certificate_date"` //
  60. //VehicleManufacturer string `json:"vehicle_manufacturer"` //
  61. //ChassisModel string `json:"chassis_model"` //
  62. //ChassisId string `json:"chassis_id"` //
  63. //ChassisCertificateNumber string `json:"chassis_certificate_number"` //
  64. //DisplacementL string `json:"displacement_l"` //
  65. //CargoLong string `json:"cargo_long"` //
  66. //CargoWide string `json:"cargo_wide"` //
  67. //CargoHigh string `json:"cargo_high"` //
  68. //NumberOfLeafSprings string `json:"number_of_leaf_springs"` //
  69. //SteeringMode string `json:"steering_mode"` //
  70. //LoadMassCoefficient string `json:"load_mass_coefficient"` //
  71. //SemitrailerSaddleMaxAllowGrossMass string `json:"semitrailer_saddle_max_allow_gross_mass"` //
  72. //NumberOfPassengers string `json:"number_of_passengers"` //
  73. //TopSpeed string `json:"top_speed"` //
  74. }
  75. func VINBasicInfo(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  76. reply = &v1.QueryResponse{}
  77. // 捕获各个task中的异常并返回给调用者
  78. defer func() {
  79. if r := recover(); r != nil {
  80. err = fmt.Errorf("%+v", r)
  81. e := &status.Status{}
  82. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  83. logger.Error("err",
  84. zap.String("system_err", err.Error()),
  85. zap.Stack("stacktrace"))
  86. }
  87. }
  88. }()
  89. var req a02Req
  90. err = jsoniter.UnmarshalFromString(params, &req)
  91. if err != nil || req.Vin == "" {
  92. return nil, errors.ParamsError
  93. }
  94. db := database.DB()
  95. var res a02Response
  96. sql := "select * from v_adm_vin where vin = ? "
  97. err = db.Raw(sql, req.Vin).Find(&res).Error
  98. if err != nil {
  99. if err == gorm.ErrRecordNotFound {
  100. return reply, errors.DataNotExistError
  101. }
  102. logger.Error("mysql",
  103. zap.String("sql", sql),
  104. zap.String("fields", req.Vin),
  105. zap.String("error", err.Error()))
  106. return reply, errors.DataBaseError
  107. }
  108. if res.PlateType == "" {
  109. res.PlateType = calcPlateType(res.Long, res.ApprovedNumber, res.GrossMass)
  110. }
  111. if req.PlateType != ""{
  112. if res.PlateType != "" {
  113. if req.PlateType == "01" || req.PlateType == "51"{
  114. if res.PlateType != "01"{
  115. return reply,errors.DataNotExistError
  116. }
  117. }else if req.PlateType == "02" || req.PlateType == "52"{
  118. if res.PlateType != "02"{
  119. return reply,errors.DataNotExistError
  120. }
  121. }
  122. }
  123. res.PlateType = req.PlateType
  124. }
  125. a02Str, _ := jsoniter.MarshalToString(res)
  126. a02Map := make(map[string]interface{})
  127. jsoniter.Unmarshal([]byte(a02Str), &a02Map)
  128. formatData(a02Map)
  129. reply.Data, _ = jsoniter.MarshalToString(a02Map)
  130. return reply, nil
  131. }