a04.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. package query
  2. import (
  3. "adm-data/errors"
  4. "adm-data/pb/v1"
  5. "context"
  6. "encoding/json"
  7. "fmt"
  8. "github.com/json-iterator/go"
  9. "git.getensh.com/common/gopkgsv2/database"
  10. "git.getensh.com/common/gopkgsv2/logger"
  11. "go.uber.org/zap"
  12. "google.golang.org/grpc/status"
  13. )
  14. type a04Request struct {
  15. PlateNo string `json:"plate_no"`
  16. PlateType string `json:"plate_type"`
  17. Vin string `json:"vin"`
  18. }
  19. type a04Response struct {
  20. PlateNo string `json:"plate_no"`
  21. PlateType string `json:"plate_type"`
  22. Owner string `json:"owner"`
  23. Vin string `json:"vin"`
  24. EngineType string `json:"engine_type"`
  25. EngineNo string `json:"engine_no"`
  26. ModelNo string `json:"model_no"`
  27. BrandName string `json:"brand_name"`
  28. InitialRegistrationDate string `json:"initial_registration_date"`
  29. InsuranceFirstDate string `json:"insurance_first_date"`
  30. VehicleType string `json:"vehicle_type"`
  31. UseProperty string `json:"use_property"`
  32. UsePropertyDetail string `json:"use_property_detail"`
  33. VehicleBodyColor string `json:"vehicle_body_color"`
  34. VehicleBodyColorDetail string `json:"vehicle_body_color_detail"`
  35. ApprovedLoad string `json:"approved_load"`
  36. ApprovedNumber string `json:"approved_number"`
  37. AxleWeight string `json:"axle_weight"`
  38. AxleNumber string `json:"axle_number"`
  39. Displacement string `json:"displacement"`
  40. FrontWheelDistance string `json:"front_wheel_distance"`
  41. BackWheelDistance string `json:"back_wheel_distance"`
  42. FuelType string `json:"fuel_type"`
  43. FuelTypeDetail string `json:"fuel_type_detail"`
  44. GrossMass string `json:"gross_mass"`
  45. RatedPower string `json:"rated_power"`
  46. ReleaseDate string `json:"release_date"`
  47. UnladenMass string `json:"unladen_mass"`
  48. EmissionStandard string `json:"emission_standard"`
  49. Long string `json:"long"`
  50. Wide string `json:"wide"`
  51. High string `json:"high"`
  52. OilWear string `json:"oil_wear"`
  53. TractionMass string `json:"traction_mass"`
  54. TyreSize string `json:"tyre_size"`
  55. WheelBase string `json:"wheel_base"`
  56. CompulsoryScrapTo string `json:"compulsory_scrap_to" description:"强制报废日期"`
  57. InspectionResultEffectiveTo string `json:"inspection_result_effective_to" description:"检验有效期止"`
  58. TyreNumber string `json:"tyre_number"`
  59. VehicleTypeDetail string `json:"vehicle_type_detail"`
  60. }
  61. func a04(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  62. reply = &v1.QueryResponse{}
  63. // 捕获各个task中的异常并返回给调用者
  64. defer func() {
  65. if r := recover(); r != nil {
  66. err = fmt.Errorf("%+v", r)
  67. e := &status.Status{}
  68. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  69. logger.Error("err",
  70. zap.String("system_err", err.Error()),
  71. zap.Stack("stacktrace"))
  72. }
  73. }
  74. }()
  75. var req a04Request
  76. err = jsoniter.UnmarshalFromString(params, &req)
  77. if err != nil {
  78. return nil, errors.ParamsError
  79. }
  80. if (req.PlateNo == "" || req.PlateType == "") && req.Vin == "" {
  81. return nil, errors.ParamsError
  82. }
  83. a04Rsp := a04Response{}
  84. if req.PlateNo != "" && req.PlateType != ""{
  85. sql := `SELECT
  86. *
  87. FROM
  88. v_adm_vehicle
  89. WHERE
  90. plate_no = ?
  91. and plate_type = ? LIMIT 1`
  92. err = database.DB().Raw(sql,req.PlateNo,req.PlateType).Find(&a04Rsp).Error
  93. }else{
  94. sql := `SELECT
  95. *
  96. FROM
  97. v_adm_vin
  98. WHERE
  99. vin = ? LIMIT 1`
  100. err = database.DB().Raw(sql,req.Vin).Find(&a04Rsp).Error
  101. }
  102. if err != nil{
  103. return nil, errors.DataNotExistError
  104. }
  105. a04Str,_ := jsoniter.MarshalToString(a04Rsp)
  106. a04Map := make(map[string]interface{})
  107. jsoniter.Unmarshal([]byte(a04Str),&a04Map)
  108. formatData(a04Map)
  109. reply.Data, _ = jsoniter.MarshalToString(a04Map)
  110. return reply, nil
  111. }