V02.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package query
  2. import (
  3. "context"
  4. jsoniter "github.com/json-iterator/go"
  5. "gd_adm_data/apis"
  6. "gd_adm_data/errors"
  7. "git.getensh.com/common/gopkgsv2/database"
  8. "gorm.io/gorm"
  9. )
  10. type v02Request struct {
  11. IdCard string `json:"id_card"`
  12. Name string `json:"name"`
  13. }
  14. type v02Response struct {
  15. IsMatch int32 `json:"is_match"`
  16. UpdatedAt int64 `json:"updated_at"`
  17. }
  18. type ads20Response struct {
  19. Name string `json:"name"`
  20. UpdatedAt int64 `json:"updated_at"`
  21. }
  22. // 人名身份证验证
  23. func V02(ctx context.Context, params string) (reply *apis.QueryResponse, err error) {
  24. reply = &apis.QueryResponse{}
  25. var req v02Request
  26. err = jsoniter.UnmarshalFromString(params, &req)
  27. if err != nil || (req.Name == "" || req.IdCard == "") {
  28. return nil, errors.ParamsError
  29. }
  30. var res v02Response
  31. var ads20 ads20Response
  32. //var name string
  33. //var updatedAt int64
  34. db := database.DB()
  35. err = db.Raw("select name,updated_at from t_adm_dws15 where id_card = ?", req.IdCard).Find(&ads20).Error
  36. if err != nil {
  37. if err == gorm.ErrRecordNotFound {
  38. return reply, errors.DataNotExistError
  39. }
  40. return reply, errors.SystemError
  41. }
  42. res.UpdatedAt = ads20.UpdatedAt
  43. if ads20.Name == "" {
  44. return reply, errors.DataNotExistError
  45. } else {
  46. if ads20.Name == req.Name {
  47. // 姓名匹配为1
  48. res.IsMatch = 1
  49. reply.Data, _ = jsoniter.MarshalToString(res)
  50. } else {
  51. // 姓名不匹配为-1
  52. res.IsMatch = -1
  53. reply.Data, _ = jsoniter.MarshalToString(res)
  54. }
  55. }
  56. return reply, nil
  57. }