duplicate.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/app/job/main/passport-user-compare/model"
  6. xsql "go-common/library/database/sql"
  7. "go-common/library/log"
  8. )
  9. const (
  10. _getUserTelDuplicateSQL = "SELECT id,mid,tel,cid,tel_bind_time,status,ts FROM user_tel_duplicate WHERE status = 0 order by ts"
  11. _getUserEmailDuplicateSQL = "SELECT id,mid,email,verified,email_bind_time,status,ts FROM user_email_duplicate WHERE status = 0 order by ts"
  12. _updateTelDuplicateStatusSQL = "UPDATE user_tel_duplicate SET status = 1 WHERE id = ?"
  13. _updateEmailDuplicateStatusSQL = "UPDATE user_email_duplicate SET status = 1 WHERE id = ?"
  14. )
  15. // UserTelDuplicate get user tel duplicate.
  16. func (d *Dao) UserTelDuplicate(c context.Context) (res []*model.UserTelDuplicate, err error) {
  17. var rows *xsql.Rows
  18. if rows, err = d.userDB.Query(c, _getUserTelDuplicateSQL); err != nil {
  19. log.Error("fail to get UserTelDuplicate, dao.userDB.Query(%s) error(%v)", _getUserTelDuplicateSQL, err)
  20. return
  21. }
  22. defer rows.Close()
  23. for rows.Next() {
  24. r := new(model.UserTelDuplicate)
  25. if err = rows.Scan(&r.ID, &r.Mid, &r.Tel, &r.Cid, &r.TelBindTime, &r.Status, &r.Timestamp); err != nil {
  26. log.Error("row.Scan() error(%v)", err)
  27. res = nil
  28. return
  29. }
  30. res = append(res, r)
  31. }
  32. return
  33. }
  34. // UserEmailDuplicate get user email duplicate.
  35. func (d *Dao) UserEmailDuplicate(c context.Context) (res []*model.UserEmailDuplicate, err error) {
  36. var rows *xsql.Rows
  37. if rows, err = d.userDB.Query(c, _getUserEmailDuplicateSQL); err != nil {
  38. log.Error("fail to get UserEmailDuplicate, dao.userDB.Query(%s) error(%v)", _getUserEmailDuplicateSQL, err)
  39. return
  40. }
  41. defer rows.Close()
  42. for rows.Next() {
  43. r := new(model.UserEmailDuplicate)
  44. if err = rows.Scan(&r.ID, &r.Mid, &r.Email, &r.Verified, &r.EmailBindTime, &r.Status, &r.Timestamp); err != nil {
  45. log.Error("row.Scan() error(%v)", err)
  46. res = nil
  47. return
  48. }
  49. res = append(res, r)
  50. }
  51. return
  52. }
  53. // UpdateUserTelDuplicateStatus update user tel duplicate status.
  54. func (d *Dao) UpdateUserTelDuplicateStatus(c context.Context, id int64) (affected int64, err error) {
  55. var res sql.Result
  56. if res, err = d.userDB.Exec(c, _updateTelDuplicateStatusSQL, id); err != nil {
  57. log.Error("fail to update tel duplicate status, id(%d) dao.userDB.Exec() error(%+v)", id, err)
  58. return
  59. }
  60. return res.RowsAffected()
  61. }
  62. // UpdateUserEmailDuplicateStatus update user email duplicate status.
  63. func (d *Dao) UpdateUserEmailDuplicateStatus(c context.Context, id int64) (affected int64, err error) {
  64. var res sql.Result
  65. if res, err = d.userDB.Exec(c, _updateEmailDuplicateStatusSQL, id); err != nil {
  66. log.Error("fail to update email duplicate status, id(%d) dao.userDB.Exec() error(%+v)", id, err)
  67. return
  68. }
  69. return res.RowsAffected()
  70. }