a05.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/database"
  10. "git.getensh.com/common/gopkgsv2/logger"
  11. "go.uber.org/zap"
  12. "google.golang.org/grpc/status"
  13. )
  14. type a05Request struct {
  15. Vin string `json:"vin"`
  16. PlateNo string `json:"plate_no"`
  17. PlateType string `json:"plate_type"`
  18. }
  19. type a05Response struct {
  20. PlateNo string `json:"plate_no"`
  21. PlateNoPrex string `json:"plate_no_prex"`
  22. PlateType string `json:"plate_type"`
  23. Vin string `json:"vin"`
  24. SaleTime string `json:"sale_time"`
  25. Province string `json:"province"`
  26. City string `json:"city"`
  27. District string `json:"district"`
  28. UsePropertyDetail string `json:"use_property_detail"`
  29. BrandName string `json:"brand_name"`
  30. EngineNo string `json:"engine_no"`
  31. EngineType string `json:"engine_type"`
  32. Displacement string `json:"displacement"`
  33. DisplacementL string `json:"displacement_l"`
  34. ReleaseDate string `json:"release_date"`
  35. VehicleBodyColorDetail string `json:"vehicle_body_color_detail"`
  36. VehicleBodyColor string `json:"vehicle_body_color"`
  37. LastCompulsoryInsuranceDate string `json:"last_compulsory_insurance_date"`
  38. }
  39. func a05(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  40. reply = &v1.QueryResponse{}
  41. // 捕获各个task中的异常并返回给调用者
  42. defer func() {
  43. if r := recover(); r != nil {
  44. err = fmt.Errorf("%+v", r)
  45. e := &status.Status{}
  46. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  47. logger.Error("err",
  48. zap.String("system_err", err.Error()),
  49. zap.Stack("stacktrace"))
  50. }
  51. }
  52. }()
  53. var req a05Request
  54. err = jsoniter.UnmarshalFromString(params, &req)
  55. if err != nil {
  56. return nil, errors.ParamsError
  57. }
  58. if req.Vin == "" {
  59. return nil, errors.ParamsError
  60. }
  61. a05Rsp := a05Response{}
  62. sql := `SELECT
  63. *
  64. FROM
  65. v_adm_vehicle_destination
  66. WHERE
  67. vin = ?`
  68. err = database.DB().Raw(sql, req.Vin).Find(&a05Rsp).Error
  69. if err != nil {
  70. return nil, errors.DataNotExistError
  71. }
  72. sql1 := `SELECT insurance_date as last_compulsory_insurance_date FROM t_adm_ads17 WHERE vin = ? ORDER BY insurance_date desc LIMIT 1`
  73. err = database.DB().Raw(sql1, req.Vin).Find(&a05Rsp).Error
  74. a05Str, _ := jsoniter.MarshalToString(a05Rsp)
  75. a05Map := make(map[string]interface{})
  76. jsoniter.Unmarshal([]byte(a05Str), &a05Map)
  77. formatData(a05Map)
  78. reply.Data, _ = jsoniter.MarshalToString(a05Map)
  79. return reply, nil
  80. }