common.go 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. package v2
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/live/app-interface/dao"
  6. "go-common/app/interface/live/app-interface/model"
  7. "go-common/app/service/main/account/api"
  8. v2pb "go-common/app/interface/live/app-interface/api/http/v2"
  9. "go-common/app/interface/live/app-interface/conf"
  10. roomV1 "go-common/app/service/live/room/api/liverpc/v1"
  11. roomV2 "go-common/app/service/live/room/api/liverpc/v2"
  12. "go-common/library/log"
  13. "go-common/library/sync/errgroup"
  14. )
  15. // 统一cover获取方式
  16. func (s *IndexService) getCover(userCover string, systemCover string) (cover string) {
  17. if userCover != "" {
  18. cover = userCover
  19. } else {
  20. cover = systemCover
  21. }
  22. return
  23. }
  24. func (s *IndexService) ifHitSkyHorse(mid int64, device string) (hit bool) {
  25. if mid == 0 {
  26. return false
  27. }
  28. if device == "pad" {
  29. return false
  30. }
  31. lastMid := strconv.Itoa(int(mid % 100))
  32. if len(lastMid) < 2 {
  33. lastMid = "0" + lastMid
  34. }
  35. _, isSkyHorseGray := s.conf.SkyHorseGray[lastMid]
  36. return isSkyHorseGray && conf.Conf.SkyHorseStatus
  37. }
  38. func (s *IndexService) ifHitLiveRec(mid int64, device string) (hit bool) {
  39. if mid == 0 {
  40. return false
  41. }
  42. if device == "pad" {
  43. return false
  44. }
  45. lastMid := strconv.Itoa(int(mid % 100))
  46. if len(lastMid) < 2 {
  47. lastMid = "0" + lastMid
  48. }
  49. _, isLiveRec := s.conf.LiveGray[lastMid]
  50. return isLiveRec
  51. }
  52. func (s *IndexService) getRecRoomList(ctx context.Context, roomIds []int64, recPoolRoomListResp map[int64]*v2pb.CommonRoomItem, build int64, platform string, idolDuplicateMap map[int64]bool, recType int64, quality int64) (respRecRoomList []*v2pb.CommonRoomItem, err error) {
  53. wg, wgCtx := errgroup.WithContext(ctx)
  54. multiRoomListResp := make(map[int64]*roomV2.RoomGetByIdsResp_RoomInfo)
  55. wg.Go(func() error {
  56. // 天马房间基础信息,有错误cancel其他没必要执行
  57. fields := []string{
  58. "roomid",
  59. "title",
  60. "uname",
  61. "online",
  62. "cover",
  63. "user_cover",
  64. "link",
  65. "face",
  66. "area_v2_parent_id",
  67. "area_v2_parent_name",
  68. "area_v2_id",
  69. "area_v2_name",
  70. "broadcast_type",
  71. "uid",
  72. }
  73. multiRoomList, err := s.roomDao.GetRoomInfoByIds(wgCtx, roomIds, fields, "app-interface-skyHorseRec")
  74. if err != nil {
  75. log.Error("[getRecRoomList]getByIds error:%+v", err)
  76. }
  77. multiRoomListResp = multiRoomList
  78. return err
  79. })
  80. pendantRoomListResp := make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
  81. wg.Go(func() error {
  82. pendantRoomList, err := s.roomDao.GetRoomPendant(wgCtx, roomIds, "mobile_index_badge", 2)
  83. if err != nil {
  84. log.Error("[getRecRoomList]getPendantByIds error:%+v", err)
  85. }
  86. pendantRoomListResp = pendantRoomList
  87. return nil
  88. })
  89. err = wg.Wait()
  90. if err != nil {
  91. log.Error("[getRecRoomList]wait error(%+v)", err)
  92. return
  93. }
  94. respSlice := make([]*roomV2.RoomGetByIdsResp_RoomInfo, 0)
  95. for _, roomBaseInfo := range multiRoomListResp {
  96. respSlice = append(respSlice, roomBaseInfo)
  97. }
  98. respRecRoomList = make([]*v2pb.CommonRoomItem, 0)
  99. for i := 0; i < 6; i++ {
  100. if recInfo, ok := recPoolRoomListResp[int64(i+1)]; ok {
  101. if _, ok := idolDuplicateMap[recInfo.Roomid]; !ok {
  102. respRecRoomList = append(respRecRoomList, recInfo)
  103. continue
  104. }
  105. }
  106. if len(respSlice) <= 0 {
  107. continue
  108. }
  109. tmpItem := respSlice[0:1][0]
  110. respSlice = respSlice[1:]
  111. pendantValue, pendantBgPic, pendantBgColor := s.getPendant(tmpItem.Roomid, pendantRoomListResp)
  112. // 统一cover产品逻辑
  113. cover := s.getCover(tmpItem.UserCover, tmpItem.Cover)
  114. respRecRoomList = append(respRecRoomList, &v2pb.CommonRoomItem{
  115. Roomid: tmpItem.Roomid,
  116. Title: tmpItem.Title,
  117. Uname: tmpItem.Uname,
  118. Online: tmpItem.Online,
  119. Cover: cover,
  120. Link: "/" + strconv.Itoa(int(tmpItem.Roomid)),
  121. Face: tmpItem.Face,
  122. AreaV2ParentId: tmpItem.AreaV2ParentId,
  123. AreaV2ParentName: tmpItem.AreaV2ParentName,
  124. AreaV2Id: tmpItem.AreaV2Id,
  125. AreaV2Name: tmpItem.AreaV2Name,
  126. BroadcastType: tmpItem.BroadcastType,
  127. PendentRu: pendantValue,
  128. PendentRuPic: pendantBgPic,
  129. PendentRuColor: pendantBgColor,
  130. RecType: recType,
  131. })
  132. }
  133. s.getPlayUrl(ctx, respRecRoomList, quality, build, platform)
  134. return
  135. }
  136. func (s *IndexService) getExtraDataForRoom(ctx context.Context, roomIds []int64, uids []int64, roomIdToUid map[int64]int64) (extraInfo map[int64]*model.ExtraRecInfo) {
  137. wg, wgCtx := errgroup.WithContext(ctx)
  138. extraInfo = make(map[int64]*model.ExtraRecInfo)
  139. userInfos := make(map[int64]*api.Info)
  140. wg.Go(func() error {
  141. userResult, err := s.accountDao.GetUserInfos(wgCtx, uids)
  142. if err != nil {
  143. log.Error("[getExtraDataForRoom]getByIds error:%+v", err)
  144. }
  145. userInfos = userResult
  146. return err
  147. })
  148. pendantRoomListResp := make(map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result)
  149. wg.Go(func() error {
  150. pendantRoomList, err := s.roomDao.GetRoomPendant(wgCtx, roomIds, "mobile_index_badge", 2)
  151. if err != nil {
  152. log.Error("[getExtraDataForRoom]getPendantByIds error:%+v", err)
  153. }
  154. pendantRoomListResp = pendantRoomList
  155. return nil
  156. })
  157. err := wg.Wait()
  158. if err != nil {
  159. log.Error("[getExtraDataForRoom]getExtraDataForRoom_waitError:%+v", err)
  160. return
  161. }
  162. for _, roomId := range roomIds {
  163. pendantValue, pendantBgPic, pendantBgColor := s.getPendant(roomId, pendantRoomListResp)
  164. if _, ok := extraInfo[roomId]; !ok {
  165. extraInfo[roomId] = &model.ExtraRecInfo{}
  166. }
  167. extraInfo[roomId].PendentRu = pendantValue
  168. extraInfo[roomId].PendentRuPic = pendantBgPic
  169. extraInfo[roomId].PendentRuColor = pendantBgColor
  170. if uid, ok := roomIdToUid[roomId]; ok {
  171. if _, ok := userInfos[uid]; ok {
  172. extraInfo[roomId].UName = userInfos[uid].Name
  173. extraInfo[roomId].Face = userInfos[uid].Face
  174. }
  175. }
  176. }
  177. return
  178. }
  179. func (s *IndexService) getPendant(roomId int64, pendantRoomListResp map[int64]*roomV1.RoomPendantGetPendantByIdsResp_Result) (pendantValue, pendantBgPic, pendantBgColor string) {
  180. if pendantRoomListResp != nil {
  181. if _, ok := pendantRoomListResp[roomId]; ok {
  182. // 移动端取value, web取name
  183. pendantValue = pendantRoomListResp[roomId].Value
  184. pendantBgPic = pendantRoomListResp[roomId].BgPic
  185. if pendantRoomListResp[roomId].BgColor != "" {
  186. pendantBgColor = pendantRoomListResp[roomId].BgColor
  187. } else {
  188. pendantBgColor = _mobileIndexBadgeColorDefault
  189. }
  190. }
  191. }
  192. return
  193. }
  194. func (s *IndexService) getPlayUrl(ctx context.Context, roomList []*v2pb.CommonRoomItem, quality, build int64, platform string) {
  195. roomIdsForPlayUrl := make([]int64, 0)
  196. for _, commRoomBlock := range roomList {
  197. roomIdsForPlayUrl = append(roomIdsForPlayUrl, commRoomBlock.Roomid)
  198. }
  199. changeRoomListPlayURLMap := dao.BvcApi.GetPlayUrlMulti(ctx, roomIdsForPlayUrl, 0, quality, build, platform)
  200. for _, vv := range roomList {
  201. if changeRoomListPlayURLMap[vv.Roomid] != nil {
  202. vv.AcceptQuality = changeRoomListPlayURLMap[vv.Roomid].AcceptQuality
  203. vv.CurrentQuality = changeRoomListPlayURLMap[vv.Roomid].CurrentQuality
  204. vv.PlayUrl = changeRoomListPlayURLMap[vv.Roomid].Url["h264"]
  205. vv.PlayUrlH265 = changeRoomListPlayURLMap[vv.Roomid].Url["h265"]
  206. }
  207. }
  208. }