A01.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package query
  2. import (
  3. "context"
  4. "gd_adm_data/apis"
  5. "gd_adm_data/errors"
  6. "gd_adm_data/model"
  7. jsoniter "github.com/json-iterator/go"
  8. "git.getensh.com/common/gopkgsv2/database"
  9. )
  10. type a01Request struct {
  11. PlateNo string `json:"plate_no"`
  12. PlateType string `json:"plate_type"`
  13. }
  14. type a01Data struct {
  15. PlateType string `json:"plate_type"`
  16. Vin string `json:"vin"`
  17. UpdatedAt int64 `json:"updated_at"`
  18. }
  19. type a01Response struct {
  20. List []a01Data `json:"list"`
  21. }
  22. // 车牌查vin
  23. func A01(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
  24. reply = &apis.QueryResponse{}
  25. var req a01Request
  26. err = jsoniter.UnmarshalFromString(params, &req)
  27. if err != nil && (req.PlateNo == "" || req.PlateType == "") {
  28. return nil, errors.ParamsError
  29. }
  30. if req.PlateType == "" {
  31. list, err := model.NewDws1Model().List(database.DB().Where("plate_no = ?", req.PlateNo))
  32. if err != nil {
  33. return reply, errors.DataNotExistError
  34. }
  35. res := a01Response{
  36. List: make([]a01Data, 0, len(list)),
  37. }
  38. for _, v := range list {
  39. res.List = append(res.List, a01Data{
  40. PlateType: v.PlateType,
  41. Vin: v.Vin,
  42. UpdatedAt: v.UpdatedAt,
  43. })
  44. }
  45. reply.Data, _ = jsoniter.MarshalToString(res)
  46. return reply, nil
  47. }
  48. list, err := model.NewDws1Model().List(database.DB().Where("plate_no = ? and plate_type = ?", req.PlateNo, req.PlateType))
  49. if err != nil {
  50. return reply, errors.DataNotExistError
  51. }
  52. res := a01Response{
  53. List: make([]a01Data, 0, len(list)),
  54. }
  55. for _, v := range list {
  56. res.List = append(res.List, a01Data{
  57. PlateType: v.PlateType,
  58. Vin: v.Vin,
  59. UpdatedAt: v.UpdatedAt,
  60. })
  61. }
  62. reply.Data, _ = jsoniter.MarshalToString(res)
  63. return reply, nil
  64. }