A04.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. package query
  2. import (
  3. "context"
  4. "gd_adm_data/apis"
  5. "gd_adm_data/errors"
  6. "github.com/json-iterator/go"
  7. "git.getensh.com/common/gopkgsv2/database"
  8. )
  9. type a04Request struct {
  10. PlateNo string `json:"plate_no"`
  11. PlateType string `json:"plate_type"`
  12. Vin string `json:"vin"`
  13. }
  14. type a04Response struct {
  15. PlateNo string `json:"plate_no"`
  16. PlateType string `json:"plate_type"`
  17. Owner string `json:"owner"`
  18. Vin string `json:"vin"`
  19. EngineType string `json:"engine_type"`
  20. EngineNo string `json:"engine_no"`
  21. ModelNo string `json:"model_no"`
  22. BrandName string `json:"brand_name"`
  23. InitialRegistrationDate string `json:"initial_registration_date"`
  24. InsuranceFirstDate string `json:"insurance_first_date"`
  25. VehicleType string `json:"vehicle_type"`
  26. UseProperty string `json:"use_property"`
  27. UsePropertyDetail string `json:"use_property_detail"`
  28. VehicleBodyColor string `json:"vehicle_body_color"`
  29. VehicleBodyColorDetail string `json:"vehicle_body_color_detail"`
  30. ApprovedLoad string `json:"approved_load"`
  31. ApprovedNumber string `json:"approved_number"`
  32. AxleWeight string `json:"axle_weight"`
  33. AxleNumber string `json:"axle_number"`
  34. Displacement string `json:"displacement"`
  35. DisplacementL string `json:"displacement_l"`
  36. FrontWheelDistance string `json:"front_wheel_distance"`
  37. BackWheelDistance string `json:"back_wheel_distance"`
  38. FuelType string `json:"fuel_type"`
  39. FuelTypeDetail string `json:"fuel_type_detail"`
  40. GrossMass string `json:"gross_mass"`
  41. RatedPower string `json:"rated_power"`
  42. ReleaseDate string `json:"release_date"`
  43. UnladenMass string `json:"unladen_mass"`
  44. EmissionStandard string `json:"emission_standard"`
  45. Long string `json:"long"`
  46. Wide string `json:"wide"`
  47. High string `json:"high"`
  48. OilWear string `json:"oil_wear"`
  49. TractionMass string `json:"traction_mass"`
  50. TyreSize string `json:"tyre_size"`
  51. WheelBase string `json:"wheel_base"`
  52. CompulsoryScrapTo string `json:"compulsory_scrap_to" description:"强制报废日期"`
  53. InspectionResultEffectiveTo string `json:"inspection_result_effective_to" description:"检验有效期止"`
  54. TyreNumber string `json:"tyre_number"`
  55. VehicleTypeDetail string `json:"vehicle_type_detail"`
  56. }
  57. // 车牌查车信息
  58. func A04(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
  59. reply = &apis.QueryResponse{}
  60. var req a04Request
  61. err = jsoniter.UnmarshalFromString(params, &req)
  62. if err != nil {
  63. return nil, errors.ParamsError
  64. }
  65. if (req.PlateNo == "" || req.PlateType == "") && req.Vin == "" {
  66. return nil, errors.ParamsError
  67. }
  68. a04Rsp := a04Response{}
  69. if req.PlateNo != "" && req.PlateType != "" {
  70. sql := `SELECT
  71. *
  72. FROM
  73. v_gadm_vehicle
  74. WHERE
  75. plate_no = ?
  76. and plate_type = ? LIMIT 1`
  77. err = database.DB().Raw(sql, req.PlateNo, req.PlateType).Find(&a04Rsp).Error
  78. } else {
  79. sql := `SELECT
  80. *
  81. FROM
  82. v_gadm_vin
  83. WHERE
  84. vin = ? LIMIT 1`
  85. err = database.DB().Raw(sql, req.Vin).Find(&a04Rsp).Error
  86. }
  87. //fmt.Println("err:", err)
  88. if err != nil {
  89. return nil, errors.DataNotExistError
  90. }
  91. if req.PlateType == "01" || req.PlateType == "02" {
  92. // 校验本地数据车牌对应关系是否正确
  93. a04PlateType := calcPlateType(a04Rsp.Long, a04Rsp.ApprovedNumber, a04Rsp.GrossMass)
  94. if a04PlateType != "" && a04PlateType != req.PlateType {
  95. return nil, errors.DataNotExistError
  96. }
  97. }
  98. a04Str, _ := jsoniter.MarshalToString(a04Rsp)
  99. a04Map := make(map[string]interface{})
  100. jsoniter.Unmarshal([]byte(a04Str), &a04Map)
  101. reply.Data, _ = jsoniter.MarshalToString(a04Map)
  102. return reply, nil
  103. }