blacklist.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. )
  9. const (
  10. // select
  11. _blackListByMIDSQL = "SELECT av_id FROM av_black_list WHERE mid = ? AND ctype = ? AND is_delete = 0"
  12. _blackListByAvIDSQL = "SELECT av_id FROM av_black_list WHERE av_id in (%s) AND ctype = ? AND is_delete = 0"
  13. // insert
  14. _inBlackListSQL = "INSERT INTO av_black_list(av_id,mid,ctype,reason,nickname,has_signed,is_delete) VALUES %s ON DUPLICATE KEY UPDATE reason=VALUES(reason),nickname=VALUES(nickname),has_signed=VALUES(has_signed),is_delete=VALUES(is_delete)"
  15. )
  16. // ListAvBlackList list av_blakc_list by av_id
  17. func (d *Dao) ListAvBlackList(c context.Context, avID []int64, ctype int) (avb map[int64]struct{}, err error) {
  18. avb = make(map[int64]struct{})
  19. rows, err := d.db.Query(c, fmt.Sprintf(_blackListByAvIDSQL, xstr.JoinInts(avID)), ctype)
  20. if err != nil {
  21. log.Error("ListAvBlackList d.db.Query error(%v)", err)
  22. return
  23. }
  24. defer rows.Close()
  25. for rows.Next() {
  26. var id int64
  27. err = rows.Scan(&id)
  28. if err != nil {
  29. log.Error("ListAvBlackList rows scan error(%v)", err)
  30. return
  31. }
  32. avb[id] = struct{}{}
  33. }
  34. err = rows.Err()
  35. return
  36. }
  37. // GetAvBlackListByMID list av_blakc_list by av_id
  38. func (d *Dao) GetAvBlackListByMID(c context.Context, mid int64, typ int) (avb map[int64]struct{}, err error) {
  39. avb = make(map[int64]struct{})
  40. rows, err := d.db.Query(c, _blackListByMIDSQL, mid, typ)
  41. if err != nil {
  42. log.Error("GetAvBlackListByMID d.db.Query error(%v)", err)
  43. return
  44. }
  45. defer rows.Close()
  46. for rows.Next() {
  47. var avID int64
  48. err = rows.Scan(&avID)
  49. if err != nil {
  50. log.Error("GetAvBlackListByMID rows scan error(%v)", err)
  51. return
  52. }
  53. avb[avID] = struct{}{}
  54. }
  55. err = rows.Err()
  56. return
  57. }
  58. // TxInsertAvBlackList insert val into av_black_list
  59. func (d *Dao) TxInsertAvBlackList(tx *sql.Tx, val string) (rows int64, err error) {
  60. if val == "" {
  61. return
  62. }
  63. res, err := tx.Exec(fmt.Sprintf(_inBlackListSQL, val))
  64. if err != nil {
  65. log.Error("TxInsertAvBlackList tx.Exec error(%v)", err)
  66. return
  67. }
  68. return res.RowsAffected()
  69. }