app.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package room
  2. import (
  3. "context"
  4. "time"
  5. "github.com/pkg/errors"
  6. "go-common/app/interface/live/app-interface/conf"
  7. cDao "go-common/app/interface/live/app-interface/dao"
  8. roomV2 "go-common/app/service/live/room/api/liverpc/v2"
  9. "go-common/library/log"
  10. rpcCtx "go-common/library/net/rpc/liverpc/context"
  11. )
  12. // 根据moduleId查common房间列表
  13. func (d *Dao) GetListByIds(ctx context.Context, moduleIds []int64) (respModuleList map[int64]*roomV2.AppIndexGetRoomListByIdsResp_RoomList, err error) {
  14. getModuleListByIdsTimeOut := time.Duration(conf.GetTimeout("getModuleListByIds", 100)) * time.Millisecond
  15. moduleList, err := cDao.RoomApi.V2AppIndex.GetRoomListByIds(rpcCtx.WithTimeout(ctx, getModuleListByIdsTimeOut), &roomV2.AppIndexGetRoomListByIdsReq{
  16. Ids: moduleIds,
  17. })
  18. if err != nil {
  19. log.Error("[GetListByIds]get all module ids rpc error, room.v1.AppIndex.GetModuleIds, error:%+v", err)
  20. err = errors.New("GET Module List Rpc error")
  21. return
  22. }
  23. if moduleList.Code != 0 || moduleList.Data == nil {
  24. log.Error("[GetListByIds]get all module ids return data error, code, %d, msg: %s", moduleList.Code, moduleList.Msg)
  25. err = errors.New("GET Module List return error")
  26. return
  27. }
  28. if len(moduleList.Data) <= 0 {
  29. log.Error("[GetListByIds]get all module ids empty error")
  30. err = errors.New("GET Module List empty error")
  31. return
  32. }
  33. respModuleList = moduleList.Data
  34. return
  35. }
  36. // 获取所有模块基础信息
  37. func (d *Dao) GetAllModuleInfo(ctx context.Context, moduleId int64) (moduleInfoList []*roomV2.AppIndexGetBaseMInfoListResp_ModuleInfo, err error) {
  38. moduleInfoList = make([]*roomV2.AppIndexGetBaseMInfoListResp_ModuleInfo, 0)
  39. param := &roomV2.AppIndexGetBaseMInfoListReq{}
  40. if moduleId != 0 {
  41. param.ModuleId = moduleId
  42. }
  43. moduleInfoListOut, err := cDao.RoomApi.V2AppIndex.GetBaseMInfoList(ctx, param)
  44. if err != nil {
  45. log.Error("[GetAllModuleInfo]RoomApi.V2AppIndex.GetBaseMInfoList rpc error, RoomApi.V2AppIndex.GetBaseMInfoList, error:%+v", err)
  46. err = errors.New("RoomApi.V2AppIndex.GetBaseMInfoList rpc error")
  47. return
  48. }
  49. if moduleInfoListOut.Code != 0 || moduleInfoListOut.Data == nil || len(moduleInfoListOut.Data) <= 0 {
  50. log.Error("[GetAllModuleInfo]RoomApi.V2AppIndex.GetBaseMInfoList return data error, code, %d, msg: %s, error:%+v", moduleInfoListOut.Code, moduleInfoListOut.Msg, err)
  51. err = errors.New("RoomApi.V2AppIndex.GetBaseMInfoList return data error")
  52. return
  53. }
  54. moduleInfoList = moduleInfoListOut.Data
  55. return
  56. }
  57. // 根据模块id获取分区入口信息
  58. func (d *Dao) GetAreaEntrance(ctx context.Context, ids []int64) (result map[int64]*roomV2.AppIndexGetPicListByIdsResp_ItemList, err error) {
  59. result = make(map[int64]*roomV2.AppIndexGetPicListByIdsResp_ItemList, 0)
  60. areaEntranceOut, err := cDao.RoomApi.V2AppIndex.GetPicListByIds(ctx, &roomV2.AppIndexGetPicListByIdsReq{Ids: ids})
  61. if err != nil {
  62. log.Error("[GetAreaEntrance]RoomApi.V2AppIndex.GetPicListByIds rpc error:%+v", err)
  63. err = errors.New("RoomApi.V2AppIndex.GetPicListByIds rpc error")
  64. return
  65. }
  66. if areaEntranceOut.Code != 0 || areaEntranceOut.Data == nil {
  67. log.Error("[GetAreaEntrance]RoomApi.V2AppIndex.GetPicListByIds return data error, code, %d, msg: %s, error:%+v", areaEntranceOut.Code, areaEntranceOut.Msg, err)
  68. err = errors.New("RoomApi.V2AppIndex.GetPicListByIds return data error")
  69. return
  70. }
  71. result = areaEntranceOut.Data
  72. return
  73. }
  74. // 根据分区ids获取房间列表
  75. func (d *Dao) GetMultiRoomList(ctx context.Context, areaIds string, platform string) (result map[int64][]*roomV2.AppIndexGetMultiRoomListResp_RoomList, err error) {
  76. result = make(map[int64][]*roomV2.AppIndexGetMultiRoomListResp_RoomList)
  77. multiRoomListOut, err := cDao.RoomApi.V2AppIndex.GetMultiRoomList(ctx, &roomV2.AppIndexGetMultiRoomListReq{
  78. AreaIds: areaIds,
  79. Platform: platform,
  80. })
  81. if err != nil {
  82. log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList rpc error:%+v", err)
  83. err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList rpc error")
  84. return
  85. }
  86. if multiRoomListOut.Code != 0 || multiRoomListOut.Data == nil {
  87. log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList return data error, code, %d, msg: %s", multiRoomListOut.Code, multiRoomListOut.Msg)
  88. err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList return data error")
  89. return
  90. }
  91. if len(multiRoomListOut.Data) <= 0 {
  92. log.Error("[GetMultiRoomList]RoomApi.V2AppIndex.GetMultiRoomList empty error")
  93. err = errors.New("RoomApi.V2AppIndex.GetMultiRoomList empty error")
  94. return
  95. }
  96. for _, item := range multiRoomListOut.Data {
  97. if item != nil {
  98. result[item.Id] = item.List
  99. }
  100. }
  101. return
  102. }