v01_plate_owner_verify.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package query
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. jsoniter "github.com/json-iterator/go"
  7. "adm-data/errors"
  8. v1 "adm-data/pb/v1"
  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. "gorm.io/gorm"
  14. )
  15. type v01Request struct {
  16. PlateNo string `json:"plate_no"`
  17. PlateType string `json:"plate_type"`
  18. Owner string `json:"owner"`
  19. }
  20. type v01Response struct {
  21. IsMatch int32 `json:"is_match"`
  22. UpdatedAt int64 `json:"updated_at"`
  23. }
  24. type ads3Response struct {
  25. Owner string `json:"owner"`
  26. UpdatedAt int64 `json:"updated_at"`
  27. }
  28. func PlateOwner(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  29. reply = &v1.QueryResponse{}
  30. // 捕获各个task中的异常并返回给调用者
  31. defer func() {
  32. if r := recover(); r != nil {
  33. err = fmt.Errorf("%+v", r)
  34. e := &status.Status{}
  35. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  36. logger.Error("err",
  37. zap.String("system_err", err.Error()),
  38. zap.Stack("stacktrace"))
  39. }
  40. }
  41. }()
  42. var req v01Request
  43. err = jsoniter.UnmarshalFromString(params, &req)
  44. if err != nil || (req.PlateNo == "" || req.PlateType == "" || req.Owner == "") {
  45. return nil, errors.ParamsError
  46. }
  47. var res v01Response
  48. //var owner string
  49. var ads3 ads3Response
  50. //var updatedAt int64
  51. db := database.DB()
  52. err = db.Raw("select owner,updated_at from t_adm_ads3 where plate_no = ? and plate_type = ?", req.PlateNo, req.PlateType).Find(&ads3).Error
  53. if err != nil {
  54. if err == gorm.ErrRecordNotFound {
  55. return reply, errors.DataNotExistError
  56. }
  57. return reply, errors.SystemError
  58. }
  59. res.UpdatedAt = ads3.UpdatedAt
  60. if ads3.Owner == "" {
  61. return reply, errors.DataNotExistError
  62. // 无记录为0
  63. /*res.IsMatch = 0
  64. reply.Data, _ = jsoniter.MarshalToString(res)*/
  65. } else {
  66. if ads3.Owner == req.Owner {
  67. // 姓名匹配为1
  68. res.IsMatch = 1
  69. reply.Data, _ = jsoniter.MarshalToString(res)
  70. } else {
  71. // 姓名不匹配为-1
  72. res.IsMatch = -1
  73. reply.Data, _ = jsoniter.MarshalToString(res)
  74. }
  75. }
  76. return reply, nil
  77. }