room_list.go 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. package v2
  2. import (
  3. "context"
  4. "fmt"
  5. v2pb "go-common/app/interface/live/app-interface/api/http/v2"
  6. "go-common/app/interface/live/app-interface/dao"
  7. roomV2 "go-common/app/service/live/room/api/liverpc/v2"
  8. "go-common/library/log"
  9. "go-common/library/xstr"
  10. )
  11. type multiModuleInfo struct {
  12. areaName string
  13. parentAreaId int64
  14. areaId int64
  15. }
  16. const _areaModuleLink = "https://live.bilibili.com/app/area?parent_area_id=%d&parent_area_name=%s&area_id=%d&area_name=%s"
  17. func (s *IndexService) getCommonRoomListForIndex(ctx context.Context, build int64, platform string, quality int64) (respCommonRoomList []*v2pb.MRoomBlock) {
  18. respCommonRoomList = make([]*v2pb.MRoomBlock, 0)
  19. moduleInfoMap := s.GetAllModuleInfoMapFromCache(ctx)
  20. roomModuleIDs := make([]int64, 0)
  21. for _, moduleType := range s.commonType {
  22. if _, ok := moduleInfoMap[moduleType]; ok {
  23. for _, moduleInfo := range moduleInfoMap[moduleType] {
  24. respCommonRoomList = append(respCommonRoomList, &v2pb.MRoomBlock{
  25. ModuleInfo: moduleInfo,
  26. })
  27. roomModuleIDs = append(roomModuleIDs, moduleInfo.Id)
  28. }
  29. }
  30. }
  31. s.getCommonRoomList(ctx, roomModuleIDs, respCommonRoomList)
  32. return
  33. }
  34. func (s *IndexService) getCommonRoomList(ctx context.Context, moduleIds []int64, respCommonRoomList []*v2pb.MRoomBlock) (err error) {
  35. if len(moduleIds) <= 0 || len(respCommonRoomList) <= 0 {
  36. return
  37. }
  38. roomListMap := make(map[int64]*roomV2.AppIndexGetRoomListByIdsResp_RoomList)
  39. roomListMap = s.getCommonListFromCache(moduleIds)
  40. if roomListMap == nil {
  41. log.Error("[commonList]GetListByIds error, res:%+v", roomListMap)
  42. return
  43. }
  44. for _, moduleInfo := range respCommonRoomList {
  45. moduleInfo.List = make([]*v2pb.CommonRoomItem, 0)
  46. if _, ok := roomListMap[moduleInfo.ModuleInfo.Id]; ok {
  47. for _, roomList := range roomListMap[moduleInfo.ModuleInfo.Id].List {
  48. if moduleInfo.ModuleInfo.Type == _parentAreaFormType ||
  49. moduleInfo.ModuleInfo.Type == _parentAreaSquareType ||
  50. moduleInfo.ModuleInfo.Type == _yunyingRecSquareType ||
  51. moduleInfo.ModuleInfo.Type == _yunyingRecFormType {
  52. if len(moduleInfo.List) >= 4 {
  53. break
  54. }
  55. }
  56. moduleInfo.List = append(moduleInfo.List, &v2pb.CommonRoomItem{
  57. Roomid: roomList.Roomid,
  58. Title: roomList.Title,
  59. Uname: roomList.Uname,
  60. AreaV2Id: roomList.AreaV2Id,
  61. AreaV2Name: roomList.AreaV2Name,
  62. AreaV2ParentId: roomList.AreaV2ParentId,
  63. AreaV2ParentName: roomList.AreaV2ParentName,
  64. Online: roomList.Online,
  65. Face: roomList.Face,
  66. Cover: roomList.Cover,
  67. BroadcastType: roomList.BroadcastType,
  68. CurrentQuality: roomList.CurrentQuality,
  69. AcceptQuality: roomList.AcceptQuality,
  70. RecType: roomList.RecType,
  71. PendentRu: roomList.PendentRu,
  72. PendentRuColor: roomList.PendentRuColor,
  73. PendentRuPic: roomList.PendentRuPic,
  74. PlayUrl: roomList.PlayUrl,
  75. PlayUrlH265: roomList.PlayUrlH265,
  76. PkId: roomList.PkId,
  77. })
  78. }
  79. }
  80. }
  81. return
  82. }
  83. func (s *IndexService) getCommonRoomListByID(ctx context.Context, moduleID int64, build int64, platform string, quality int64, device string, duplicates []int64) (respCommonRoomList []*v2pb.CommonRoomItem, err error) {
  84. respCommonRoomList = make([]*v2pb.CommonRoomItem, 0)
  85. duplicatesMap := make(map[int64]bool)
  86. for _, roomID := range duplicates {
  87. duplicatesMap[roomID] = true
  88. }
  89. moduleExistIds := make([]int64, 0)
  90. if moduleID == 0 {
  91. return
  92. }
  93. roomListMap, err := s.roomDao.GetListByIds(ctx, []int64{moduleID})
  94. if err != nil {
  95. log.Error("[commonList]GetAllModuleListByIds error, error:%+v", err)
  96. return
  97. }
  98. // 24个对关注去重的item
  99. if _, ok := roomListMap[moduleID]; ok {
  100. list := roomListMap[moduleID].List
  101. for _, info := range list {
  102. if len(respCommonRoomList) >= 24 {
  103. break
  104. }
  105. if _, ok := duplicatesMap[info.Roomid]; !ok {
  106. respCommonRoomList = append(respCommonRoomList, &v2pb.CommonRoomItem{
  107. Roomid: info.Roomid,
  108. Title: info.Title,
  109. Uname: info.Uname,
  110. AreaV2Id: info.AreaV2Id,
  111. AreaV2Name: info.AreaV2Name,
  112. AreaV2ParentId: info.AreaV2ParentId,
  113. AreaV2ParentName: info.AreaV2ParentName,
  114. Online: info.Online,
  115. Face: info.Face,
  116. Cover: info.Cover,
  117. BroadcastType: info.BroadcastType,
  118. CurrentQuality: info.CurrentQuality,
  119. AcceptQuality: info.AcceptQuality,
  120. RecType: info.RecType,
  121. PendentRu: info.PendentRu,
  122. PendentRuColor: info.PendentRuColor,
  123. PendentRuPic: info.PendentRuPic,
  124. PlayUrl: info.PlayUrl,
  125. PlayUrlH265: info.PlayUrlH265,
  126. PkId: info.PkId,
  127. })
  128. moduleExistIds = append(moduleExistIds, info.Roomid)
  129. }
  130. }
  131. filterList := make([]*v2pb.CommonRoomItem, 0)
  132. if device != "pad" {
  133. //投放位覆盖
  134. recPool, recPoolRooms := s.fourTimeRecPoolForYumo(ctx, moduleExistIds, duplicates)
  135. log.Info("[getCommonRoomListByID]投放位 recPool: %+v, moduleExistIds: %+v, otherExistIds:%+v", recPoolRooms, xstr.JoinInts(moduleExistIds), xstr.JoinInts(duplicates))
  136. duplicateMap := make(map[int64]bool)
  137. for _, id := range recPoolRooms {
  138. duplicateMap[id] = true
  139. }
  140. newRecFilterCommonList := make([]*v2pb.CommonRoomItem, 0)
  141. for _, room := range respCommonRoomList {
  142. if _, ok := duplicateMap[room.Roomid]; !ok {
  143. newRecFilterCommonList = append(newRecFilterCommonList, room)
  144. }
  145. }
  146. for i := 0; i < 24; i++ {
  147. position := int64(i) + 1
  148. if item, ok := recPool[position]; ok {
  149. filterList = append(filterList, item)
  150. } else {
  151. if len(newRecFilterCommonList) <= 0 {
  152. continue
  153. }
  154. filterList = append(filterList, newRecFilterCommonList[0:1][0])
  155. newRecFilterCommonList = newRecFilterCommonList[1:]
  156. }
  157. }
  158. respCommonRoomList = filterList
  159. }
  160. //获取playurl
  161. s.getPlayUrl(ctx, respCommonRoomList, quality, build, platform)
  162. }
  163. return
  164. }
  165. func (s *IndexService) getMultiRoomList(ctx context.Context, myTag []*v2pb.MMyTag, platform string, build int64, quality int64) (respMyTagRoomList []*v2pb.MRoomBlock, existAreaMap map[int64]bool) {
  166. // 未登陆
  167. respMyTagRoomList = make([]*v2pb.MRoomBlock, 0)
  168. existAreaMap = make(map[int64]bool) // for duplicate yunying rec
  169. if len(myTag) <= 0 {
  170. log.Warn("[getMultiRoomList]my tag empty!")
  171. return
  172. }
  173. parentName := map[int64]string{
  174. 1: "娱乐",
  175. 2: "游戏",
  176. 3: "手游",
  177. 4: "绘画",
  178. 5: "电台",
  179. }
  180. areaIds := make([]int64, 0)
  181. multiModuleInfos := make([]*multiModuleInfo, 0)
  182. for _, tag := range myTag {
  183. // 默认tag没有list 跳过
  184. if tag.ExtraInfo.IsGray == 0 {
  185. continue
  186. }
  187. for _, item := range tag.List {
  188. if item.AreaV2Id == 0 {
  189. // 过滤异常或全部标签
  190. continue
  191. }
  192. areaIds = append(areaIds, item.AreaV2Id)
  193. multiModuleInfos = append(multiModuleInfos, &multiModuleInfo{
  194. areaId: item.AreaV2Id,
  195. areaName: item.AreaV2Name,
  196. parentAreaId: item.AreaV2ParentId,
  197. })
  198. }
  199. }
  200. if len(areaIds) <= 0 {
  201. log.Info("[getMultiRoomList]no gray tag, so no room list")
  202. return
  203. }
  204. multiRoomListMap, err := s.roomDao.GetMultiRoomList(ctx, xstr.JoinInts(areaIds), platform)
  205. if err != nil {
  206. log.Error("[getMultiRoomList]roomDao.GetMultiRoomList get error:%+v", err)
  207. return
  208. }
  209. moduleInfoMap := s.GetAllModuleInfoMapFromCache(ctx)
  210. myTagRoomListTypeMap, exist := moduleInfoMap[_myAreaTagListType]
  211. if !exist || myTagRoomListTypeMap == nil || len(myTagRoomListTypeMap) <= 0 {
  212. log.Info("[getMultiRoomList]my tag room list module not exist, all: %+v", moduleInfoMap)
  213. return
  214. }
  215. roomIds := make([]int64, 0)
  216. for index, moduleInfo := range myTagRoomListTypeMap {
  217. if len(multiModuleInfos) <= index {
  218. // 后台多配的case,防止溢出
  219. continue
  220. }
  221. mInfo := multiModuleInfos[index]
  222. if mInfo == nil {
  223. continue
  224. }
  225. moduleInfo.Title = mInfo.areaName
  226. moduleInfo.Link = fmt.Sprintf(_areaModuleLink, mInfo.parentAreaId, parentName[mInfo.parentAreaId], mInfo.areaId, mInfo.areaName)
  227. item := &v2pb.MRoomBlock{
  228. ModuleInfo: moduleInfo,
  229. }
  230. l, ok := multiRoomListMap[mInfo.areaId]
  231. if !ok || l == nil {
  232. continue
  233. }
  234. existAreaMap[mInfo.areaId] = true
  235. innerList := make([]*v2pb.CommonRoomItem, 0)
  236. for _, v := range l {
  237. roomIds = append(roomIds, v.Roomid)
  238. innerList = append(innerList, &v2pb.CommonRoomItem{
  239. Roomid: v.Roomid,
  240. Title: v.Title,
  241. Uname: v.Uname,
  242. AreaV2Id: v.AreaV2Id,
  243. AreaV2Name: v.AreaV2Name,
  244. AreaV2ParentId: v.AreaV2ParentId,
  245. AreaV2ParentName: v.AreaV2ParentName,
  246. Online: v.Online,
  247. Face: v.Face,
  248. Cover: v.Cover,
  249. BroadcastType: v.BroadcastType,
  250. CurrentQuality: v.CurrentQuality,
  251. AcceptQuality: v.AcceptQuality,
  252. RecType: v.RecType,
  253. PendentRu: v.PendentRu,
  254. PendentRuColor: v.PendentRuColor,
  255. PendentRuPic: v.PendentRuPic,
  256. PlayUrl: v.PlayUrl,
  257. PlayUrlH265: v.PlayUrlH265,
  258. PkId: v.PkId,
  259. })
  260. }
  261. item.List = innerList
  262. respMyTagRoomList = append(respMyTagRoomList, item)
  263. }
  264. // 拼playurl
  265. changeRoomListPlayURLMap := dao.BvcApi.GetPlayUrlMulti(ctx, roomIds, 0, quality, build, platform)
  266. for _, v := range respMyTagRoomList {
  267. for _, vv := range v.List {
  268. if changeRoomListPlayURLMap[vv.Roomid] != nil {
  269. vv.AcceptQuality = changeRoomListPlayURLMap[vv.Roomid].AcceptQuality
  270. vv.CurrentQuality = changeRoomListPlayURLMap[vv.Roomid].CurrentQuality
  271. vv.PlayUrl = changeRoomListPlayURLMap[vv.Roomid].Url["h264"]
  272. vv.PlayUrlH265 = changeRoomListPlayURLMap[vv.Roomid].Url["h265"]
  273. }
  274. }
  275. }
  276. return
  277. }