roomAdmin.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package dao
  2. import (
  3. "context"
  4. v1pb "go-common/app/interface/live/web-room/api/http/v1"
  5. "go-common/app/service/live/xuser/api/grpc/v1"
  6. account "go-common/app/service/main/account/model"
  7. "go-common/library/log"
  8. "math"
  9. )
  10. // GetByRoomIDPage get roomadmin list by roomid.
  11. func (d *Dao) GetByRoomIDPage(c context.Context, roomID int64, page int64, pageSize int64) (resp *v1pb.RoomAdminGetByRoomResp, err error) {
  12. resp = &v1pb.RoomAdminGetByRoomResp{}
  13. resp.Page = &v1pb.RoomAdminGetByRoomResp_Page{
  14. Page: page,
  15. PageSize: pageSize,
  16. TotalPage: 1,
  17. TotalCount: 0,
  18. }
  19. ret, err := d.RoomAdminAPI.GetByRoom(c, &v1.RoomAdminGetByRoomReq{
  20. Roomid: roomID,
  21. })
  22. log.Info("call GetByAnchor mid(%v) page (%v) ret(%v)", roomID, page, ret)
  23. if err != nil {
  24. log.Error("call GetByAnchor mid(%v) page (%v) error(%v)", roomID, page, err)
  25. return
  26. }
  27. if ret == nil || ret.Data == nil {
  28. return
  29. }
  30. mids, _ := d.getUidsFromAdmins(c, ret.Data)
  31. dataLen := int64(len(mids))
  32. d.setPager(dataLen, pageSize, page, resp.Page)
  33. begin, end := d.getRange(pageSize, page, dataLen)
  34. args := &account.ArgMids{Mids: mids[begin:end]}
  35. accData, err := d.acc.Infos3(c, args)
  36. if err != nil {
  37. log.Error("call account.Infos3(%v) error(%v)", args, err)
  38. return resp, err
  39. }
  40. for _, v := range ret.Data[begin:end] {
  41. item := &v1pb.RoomAdminGetByRoomResp_Data{
  42. Uid: v.Uid,
  43. Ctime: v.Ctime,
  44. }
  45. if _, ok := accData[item.Uid]; ok {
  46. item.Face = accData[item.Uid].Face
  47. item.Uname = accData[item.Uid].Name
  48. } else {
  49. log.Error("没有这个人的用户信息 uid(%v) data(%v)", item.Uid, accData)
  50. }
  51. resp.Data = append(resp.Data, item)
  52. }
  53. return
  54. }
  55. // getAnchorUidsFromAdmins .
  56. // 根据批量房管获取对应主播的房间号和UID
  57. func (d *Dao) getUidsFromAdmins(c context.Context, admins []*v1.RoomAdminGetByRoomResp_Data) (uids []int64, err error) {
  58. if len(admins) == 0 {
  59. return
  60. }
  61. for _, r := range admins {
  62. uids = append(uids, r.Uid)
  63. }
  64. return
  65. }
  66. // pageSize, page, dataLen
  67. func (d *Dao) getRange(pageSize int64, page int64, dataLen int64) (begin int64, end int64) {
  68. begin = (page - 1) * pageSize
  69. end = page * pageSize
  70. if end > dataLen {
  71. end = dataLen
  72. }
  73. if begin > end {
  74. begin = end
  75. }
  76. return
  77. }
  78. func (d *Dao) setPager(dataLen int64, pageSize int64, page int64, pager *v1pb.RoomAdminGetByRoomResp_Page) {
  79. pager.Page = page
  80. pager.TotalCount = dataLen
  81. pager.TotalPage = int64(math.Ceil(float64(dataLen) / float64(pageSize)))
  82. pager.PageSize = pageSize
  83. }