v02.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 v02Request struct {
  16. IdCard string `json:"id_card"`
  17. Name string `json:"name"`
  18. }
  19. type v02Response struct {
  20. IsMatch int32 `json:"is_match"`
  21. UpdatedAt int64 `json:"updated_at"`
  22. }
  23. type ads20Response struct {
  24. Name string `json:"name"`
  25. UpdatedAt int64 `json:"updated_at"`
  26. }
  27. func V02(ctx context.Context, params string) (reply *v1.QueryResponse, err error) {
  28. reply = &v1.QueryResponse{}
  29. // 捕获各个task中的异常并返回给调用者
  30. defer func() {
  31. if r := recover(); r != nil {
  32. err = fmt.Errorf("%+v", r)
  33. e := &status.Status{}
  34. if er := json.Unmarshal([]byte(err.Error()), e); er != nil {
  35. logger.Error("err",
  36. zap.String("system_err", err.Error()),
  37. zap.Stack("stacktrace"))
  38. }
  39. }
  40. }()
  41. var req v02Request
  42. err = jsoniter.UnmarshalFromString(params, &req)
  43. if err != nil || (req.Name == "" || req.IdCard == "") {
  44. return nil, errors.ParamsError
  45. }
  46. var res v02Response
  47. var ads20 ads20Response
  48. //var name string
  49. //var updatedAt int64
  50. db := database.DB()
  51. err = db.Raw("select name,updated_at from t_adm_ads20 where id_card = ?", req.IdCard).Find(&ads20).Error
  52. if err != nil {
  53. if err == gorm.ErrRecordNotFound {
  54. return reply, errors.DataNotExistError
  55. }
  56. return reply, errors.SystemError
  57. }
  58. res.UpdatedAt = ads20.UpdatedAt
  59. if ads20.Name == "" {
  60. return reply, errors.DataNotExistError
  61. } else {
  62. if ads20.Name == req.Name {
  63. // 姓名匹配为1
  64. res.IsMatch = 1
  65. reply.Data, _ = jsoniter.MarshalToString(res)
  66. } else {
  67. // 姓名不匹配为-1
  68. res.IsMatch = -1
  69. reply.Data, _ = jsoniter.MarshalToString(res)
  70. }
  71. }
  72. return reply, nil
  73. }