duplicate.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package service
  2. import (
  3. "context"
  4. "encoding/hex"
  5. "strings"
  6. "go-common/app/job/main/passport-user-compare/model"
  7. "go-common/library/log"
  8. )
  9. func (s *Service) checkTelDuplicateJob() {
  10. log.Info("check tel duplicate job start...")
  11. res, err := s.d.UserTelDuplicate(context.Background())
  12. if err != nil {
  13. log.Error("fail to get UserTelDuplicate, error(%+v)", err)
  14. return
  15. }
  16. var (
  17. asoAccount *model.OriginAccount
  18. userTel *model.UserTel
  19. )
  20. for _, r := range res {
  21. if asoAccount, err = s.d.QueryAccountByMid(context.Background(), r.Mid); err != nil {
  22. log.Error("fail to check tel duplicate mid(%d) error(%+v)", r.Mid, err)
  23. return
  24. }
  25. if userTel, err = s.d.QueryUserTel(context.Background(), r.Mid); err != nil {
  26. log.Error("fail to check tel duplicate mid(%d) error(%+v)", r.Mid, err)
  27. return
  28. }
  29. om := strings.Trim(strings.ToLower(asoAccount.Tel), "")
  30. var telByte []byte
  31. if telByte, err = s.doEncrypt(om); err != nil {
  32. log.Error("checkTelDuplicateJob doEncrypt mail by mid error,mid is %d,err is (%+v)", r.Mid, err)
  33. return
  34. }
  35. originHex := hex.EncodeToString(telByte)
  36. newHex := hex.EncodeToString(userTel.Tel)
  37. if originHex == newHex {
  38. log.Info("check user tel duplicate success, userTelDuplicate(%+v)", r)
  39. if _, err = s.d.UpdateUserTelDuplicateStatus(context.Background(), r.ID); err != nil {
  40. log.Error("fail to update user tel duplicate status, id(%d) error(%+v)", r.ID, err)
  41. }
  42. } else {
  43. log.Info("fail to check user tel duplicate, new(%s) origin(%s) userTelDuplicate(%+v)", newHex, originHex, r)
  44. }
  45. }
  46. log.Info("update tel duplicate job end...")
  47. }
  48. func (s *Service) checkEmailDuplicateJob() {
  49. log.Info("check email duplicate job start...")
  50. res, err := s.d.UserEmailDuplicate(context.Background())
  51. if err != nil {
  52. log.Error("fail to get UserEmailDuplicate, error(%+v)", err)
  53. return
  54. }
  55. var (
  56. asoAccount *model.OriginAccount
  57. userEmail *model.UserEmail
  58. )
  59. for _, r := range res {
  60. if asoAccount, err = s.d.QueryAccountByMid(context.Background(), r.Mid); err != nil {
  61. log.Error("fail to check email duplicate mid(%d) error(%+v)", r.Mid, err)
  62. return
  63. }
  64. if userEmail, err = s.d.QueryUserMail(context.Background(), r.Mid); err != nil {
  65. log.Error("fail to check email duplicate mid(%d) error(%+v)", r.Mid, err)
  66. return
  67. }
  68. om := strings.Trim(strings.ToLower(asoAccount.Email), "")
  69. var emailByte []byte
  70. if emailByte, err = s.doEncrypt(om); err != nil {
  71. log.Error("checkEmailDuplicateJob doEncrypt mail by mid error,mid is %d,err is (%+v)", r.Mid, err)
  72. return
  73. }
  74. originHex := hex.EncodeToString(emailByte)
  75. newHex := hex.EncodeToString(userEmail.Email)
  76. if originHex == newHex {
  77. log.Info("check user email duplicate success, userEmailDuplicate(%+v)", r)
  78. if _, err = s.d.UpdateUserEmailDuplicateStatus(context.Background(), r.ID); err != nil {
  79. log.Error("fail to update user email duplicate status, id(%d) error(%+v)", r.ID, err)
  80. }
  81. } else {
  82. log.Info("fail to check user email duplicate, new(%s) origin(%s) userEmailDuplicate(%+v)", newHex, originHex, r)
  83. }
  84. }
  85. log.Info("update email duplicate job end...")
  86. }