user_fan.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package dao
  2. import (
  3. "context"
  4. xsql "database/sql"
  5. "go-common/app/service/bbq/user/internal/model"
  6. "go-common/library/database/sql"
  7. "go-common/library/time"
  8. )
  9. const (
  10. _addUserFan = "insert into %s (`mid`,`fan_mid`) values (?,?) on duplicate key update state=0"
  11. _cancelUserFan = "update %s set state=1 where mid = ? and fan_mid = ?"
  12. _getUserPartFans = "select fan_mid, mtime from user_fan_%02d where mid=? and state=0 and mtime<=? order by mtime desc, fan_mid desc limit %d"
  13. _isFan = "select fan_mid from user_fan_%02d where mid = ? and state=0 and fan_mid in (%s)"
  14. )
  15. //TxAddUserFan .
  16. func (d *Dao) TxAddUserFan(tx *sql.Tx, mid, fanMid int64) (num int64, err error) {
  17. var res xsql.Result
  18. if res, err = tx.Exec(d.userFanSQL(mid, _addUserFan), mid, fanMid); err != nil {
  19. return
  20. }
  21. return res.LastInsertId()
  22. }
  23. //TxCancelUserFan .
  24. func (d *Dao) TxCancelUserFan(tx *sql.Tx, mid, fanMid int64) (num int64, err error) {
  25. var res xsql.Result
  26. if res, err = tx.Exec(d.userFanSQL(mid, _cancelUserFan), mid, fanMid); err != nil {
  27. return
  28. }
  29. return res.RowsAffected()
  30. }
  31. // IsFan 获取mid的粉丝
  32. func (d *Dao) IsFan(c context.Context, mid int64, candidateMIDs []int64) (MIDMap map[int64]bool) {
  33. if len(candidateMIDs) == 0 {
  34. return
  35. }
  36. MIDMap = d.isMidIn(c, mid, candidateMIDs, _isFan)
  37. return
  38. }
  39. // FetchPartFanList 获取mid的粉丝列表
  40. func (d *Dao) FetchPartFanList(c context.Context, mid int64, cursor model.CursorValue, size int) (
  41. MID2IDMap map[int64]time.Time, followedMIDs []int64, err error) {
  42. MID2IDMap, followedMIDs, err = d.fetchPartRelationUserList(c, mid, cursor, _getUserPartFans)
  43. return
  44. }