authority.go 920 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "strings"
  6. "go-common/library/xstr"
  7. )
  8. const (
  9. _addAuthoritySQL = "INSERT INTO up_white_list(mid) VALUES %s ON DUPLICATE KEY UPDATE is_deleted=0"
  10. _rmAuthoritySQL = "UPDATE up_white_list SET is_deleted = 1 WHERE mid IN (%s)"
  11. )
  12. // AddAuthority .
  13. func (d *Dao) AddAuthority(c context.Context, mids []int64) (int64, error) {
  14. if len(mids) == 0 {
  15. return 0, nil
  16. }
  17. s := make([]string, 0)
  18. for _, v := range mids {
  19. s = append(s, fmt.Sprintf("(%d)", v))
  20. }
  21. res, err := d.db.Exec(c, fmt.Sprintf(_addAuthoritySQL, strings.Join(s, ",")))
  22. if err != nil {
  23. return 0, err
  24. }
  25. return res.RowsAffected()
  26. }
  27. // RmAuthority .
  28. func (d *Dao) RmAuthority(c context.Context, mids []int64) (int64, error) {
  29. if len(mids) == 0 {
  30. return 0, nil
  31. }
  32. res, err := d.db.Exec(c, fmt.Sprintf(_rmAuthoritySQL, xstr.JoinInts(mids)))
  33. if err != nil {
  34. return 0, err
  35. }
  36. return res.RowsAffected()
  37. }