roomMng.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package v1
  2. import (
  3. "context"
  4. "fmt"
  5. v1pb "go-common/app/admin/live/live-admin/api/http/v1"
  6. "go-common/app/admin/live/live-admin/conf"
  7. "go-common/app/admin/live/live-admin/dao"
  8. relationV1 "go-common/app/service/live/relation/api/liverpc/v1"
  9. liveRPCCli "go-common/app/service/live/room/api/liverpc"
  10. v1liveRPCpb "go-common/app/service/live/room/api/liverpc/v1"
  11. "go-common/library/log"
  12. "go-common/library/sync/errgroup"
  13. "os"
  14. "time"
  15. streamPb "go-common/app/service/video/stream-mng/api/v1"
  16. "go-common/library/ecode"
  17. )
  18. const timeFormat = "2006-01-02 15:04:05"
  19. // RoomMngService struct
  20. type RoomMngService struct {
  21. conf *conf.Config
  22. // optionally add other properties here, such as dao
  23. // dao *dao.Dao
  24. rpcCli *liveRPCCli.Client
  25. streamCli streamPb.StreamClient
  26. dao *dao.Dao
  27. }
  28. //NewRoomMngService init
  29. func NewRoomMngService(c *conf.Config) (s *RoomMngService) {
  30. s = &RoomMngService{
  31. conf: c,
  32. dao: dao.New(c),
  33. }
  34. log.Info("RoomMngLiveRPCClient Init: %+v", s.conf.RoomMngClient)
  35. s.rpcCli = liveRPCCli.New(s.conf.RoomMngClient)
  36. log.Info("Stream Mng Client Init: %+v", s.conf.StreamMngClient)
  37. if svc, err := streamPb.NewClient(s.conf.StreamMngClient); err != nil {
  38. panic(err)
  39. } else {
  40. s.streamCli = svc
  41. }
  42. return s
  43. }
  44. // GetSecondVerifyListWithPics implementation
  45. // 获取带有图片地址的二次审核列表
  46. // `method:"GET" internal:"true" `
  47. func (s *RoomMngService) GetSecondVerifyListWithPics(ctx context.Context, req *v1pb.RoomMngGetSecondVerifyListReq) (resp *v1pb.RoomMngGetSecondVerifyListResp, err error) {
  48. if req.Pagesize == 0 {
  49. req.Pagesize = 30
  50. }
  51. rpcResp, err := s.rpcCli.V1RoomMng.GetSecondVerifyList(ctx, &v1liveRPCpb.RoomMngGetSecondVerifyListReq{
  52. RoomId: req.RoomId,
  53. Area: req.Area,
  54. Page: req.Page,
  55. Pagesize: req.Pagesize,
  56. Biz: req.Biz,
  57. })
  58. if err != nil {
  59. return
  60. }
  61. if rpcResp.Code == 0 {
  62. result, getPicErr := s.getExtraInfo(ctx, rpcResp.Data.Result)
  63. if getPicErr != nil {
  64. err = getPicErr
  65. } else {
  66. resp = &v1pb.RoomMngGetSecondVerifyListResp{
  67. Count: rpcResp.Data.Count,
  68. Page: rpcResp.Data.Page,
  69. Pagesize: rpcResp.Data.Pagesize,
  70. Result: result,
  71. }
  72. }
  73. } else {
  74. err = ecode.Error(ecode.ServerErr, fmt.Sprintf("Room v1 RoomMng LiveRPC 业务错误: { Code: %d ; Msg: %s }", rpcResp.Code, rpcResp.Msg))
  75. }
  76. return
  77. }
  78. func (s *RoomMngService) getExtraInfo(ctx context.Context, list []*v1liveRPCpb.RoomMngGetSecondVerifyListResp_Result) (respList []*v1pb.RoomMngGetSecondVerifyListResp_Result, err error) {
  79. picRes := make([][]string, len(list))
  80. fcRes := make([]int64, len(list))
  81. g, _ := errgroup.WithContext(ctx)
  82. for i := 0; i < len(list); i++ {
  83. x := i
  84. // 获取指定时间内的截图
  85. g.Go(func() error {
  86. picRes[x] = s.getSingleRoomPic(ctx, list[x].RoomId, list[x].BreakTime)
  87. return nil
  88. })
  89. // 获取粉丝计数
  90. g.Go(func() (feedErr error) {
  91. fcRes[x] = s.getUserFC(ctx, list[x].Uid)
  92. return nil
  93. })
  94. }
  95. if err := g.Wait(); err != nil {
  96. log.Error("get ExtraData Error (%+v)", err)
  97. }
  98. respList = make([]*v1pb.RoomMngGetSecondVerifyListResp_Result, len(list))
  99. for index, RPCRespItem := range list {
  100. // 当截图张数大于 0 且有证据图片时,将截图第一张替换为证据图片
  101. if len(picRes[index]) > 0 && RPCRespItem.ProofImg != "" {
  102. picRes[index][0] = RPCRespItem.ProofImg
  103. }
  104. respList[index] = &v1pb.RoomMngGetSecondVerifyListResp_Result{
  105. Id: RPCRespItem.Id,
  106. RecentCutTimes: RPCRespItem.RecentCutTimes,
  107. RecentWarnTimes: RPCRespItem.RecentWarnTimes,
  108. Uname: RPCRespItem.Uname,
  109. RoomId: RPCRespItem.RoomId,
  110. Uid: RPCRespItem.Uid,
  111. Title: RPCRespItem.Title,
  112. AreaV2Name: RPCRespItem.AreaV2Name,
  113. Fc: fcRes[index],
  114. WarnReason: RPCRespItem.WarnReason,
  115. BreakTime: RPCRespItem.BreakTime,
  116. Pics: picRes[index],
  117. WarnTimes: RPCRespItem.WarnTimes,
  118. }
  119. }
  120. return
  121. }
  122. func (s *RoomMngService) getSingleRoomPic(ctx context.Context, roomID int64, breakTime string) (picList []string) {
  123. // uat 环境写死 11891462 房间号
  124. if os.Getenv("DEPLOY_ENV") == "uat" {
  125. roomID = 11891462
  126. }
  127. // 计算结束时间点,规定为 5 分钟后
  128. startTime, _ := time.Parse(timeFormat, breakTime)
  129. endTimeStr := startTime.Add(5 * 60 * 1000 * 1000 * 1000).Format(timeFormat)
  130. RPCResp, err := s.streamCli.GetSingleScreeShot(ctx, &streamPb.GetSingleScreeShotReq{
  131. RoomId: roomID,
  132. StartTime: breakTime,
  133. EndTime: endTimeStr,
  134. })
  135. // log.Info("res: (%+v) err:(%+v) \n", RPCResp, err)
  136. if err != nil {
  137. log.Error("Get Pic Fail: error(%v) roomId(%d) startTime(%s) endTime(%s)", err, roomID, breakTime, endTimeStr)
  138. picList = []string{
  139. "https://static.hdslb.com/error/very_sorry.png",
  140. }
  141. } else {
  142. picList = RPCResp.List
  143. }
  144. return
  145. }
  146. func (s *RoomMngService) getUserFC(ctx context.Context, UID int64) (resp int64) {
  147. feedResp, feedErr := s.dao.Relation.V1Feed.GetUserFc(ctx, &relationV1.FeedGetUserFcReq{Follow: UID})
  148. if feedErr != nil || feedResp.Data == nil {
  149. resp = 0
  150. log.Error("Get FC Error for UID(%d) with Error(%+v)", UID, feedErr)
  151. } else {
  152. resp = feedResp.Data.Fc
  153. }
  154. return
  155. }