duplicate.go 3.8 KB

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