From c8b291c2901d36f9cefda8ce7392df0a7b183c3e Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 16 Aug 2023 14:38:03 +0800 Subject: [PATCH] Feature/lobby --- cv/group_cv/group.go | 15 +++++++++++++-- domain/model/group_m/groupGame.go | 17 +++++++++++++++++ route/group_r/group_list.go | 11 ++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 domain/model/group_m/groupGame.go diff --git a/cv/group_cv/group.go b/cv/group_cv/group.go index 13971b1..d715377 100644 --- a/cv/group_cv/group.go +++ b/cv/group_cv/group.go @@ -251,13 +251,24 @@ type CvCountry struct { AreaCodeName *string `json:"areaShortName"` } -func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, groupIds []string, pageSize, pageIndex int) ([]JoinedGroupInfo, int, error) { +func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGroupIds []string, pageSize, pageIndex int) ([]JoinedGroupInfo, int, error) { model := domain.CreateModel(myService.CtxAndDb) - groupInfo, err := group_m.BatchGetGroupInfo(model, groupIds) + groupInfo, err := group_m.BatchGetGroupInfo(model, originGroupIds) if err != nil { return nil, 0, err } + var groupIds []string + for _, groupId := range originGroupIds { + if group, ok := groupInfo[groupId]; ok { + if group.IsGameRoom == 0 { + groupIds = append(groupIds, groupId) + } + } + } + if len(groupIds) <= 0 { + return nil, 0, nil + } // todo: 可以移到后面,减小查询范围,因为roomMicUserMap不影响排序 roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds) diff --git a/domain/model/group_m/groupGame.go b/domain/model/group_m/groupGame.go new file mode 100644 index 0000000..03844d7 --- /dev/null +++ b/domain/model/group_m/groupGame.go @@ -0,0 +1,17 @@ +package group_m + +import "git.hilo.cn/hilo-common/domain" + +// 获取游戏房 +func GetGameGroupsMap(model *domain.Model) map[string]bool { + res := make(map[string]bool) + var rows []GroupInfo + if err := model.DB().Model(GroupInfo{}).Where("is_game_room = 1").Find(&rows).Error; err != nil { + model.Log.Errorf("GetGameGroupsMap fail:%v", err) + return res + } + for _, v := range rows { + res[v.ImGroupId] = true + } + return res +} diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index cebe0a6..0b12842 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -97,6 +97,7 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } + gameGroups := group_m.GetGameGroupsMap(model) model.Log.Infof("GetPopularGroups: page size = %d, page index = %d, banMap %v, hidenMap %v,cost:%v", pageSize, pageIndex, bannedGroups, hiddenGroups, time.Now().Sub(start)) hotGroupList := make([]group_m.GroupInfo, 0) @@ -122,6 +123,10 @@ func GetPopularGroups(c *gin.Context) (*mycontext.MyContext, error) { hiddenCount++ continue } + // 过滤掉游戏房 + if gameGroups[i] { + continue + } groupIds = append(groupIds, i) } model.Log.Infof("GetPopularGroups, micGroupNum: %v, banned %d, hidden %d,cost:%v", micGroupNum, banCount, hiddenCount, time.Now().Sub(start)) @@ -471,9 +476,13 @@ func GetLatestGroups(c *gin.Context) (*mycontext.MyContext, error) { if err != nil { return myContext, err } - + gameGroups := group_m.GetGameGroupsMap(model) gids := make([]string, 0) for i, _ := range micGroupNum { + // 过滤游戏房 + if gameGroups[i] { + continue + } gids = append(gids, i) } // 获取最新群组列表 -- 2.22.0