From 01de3f5e4e7b8e2a11c6d6ec87e5207c7b8caee5 Mon Sep 17 00:00:00 2001 From: hujiebin Date: Thu, 31 Aug 2023 17:01:22 +0800 Subject: [PATCH] =?UTF-8?q?for=E5=BE=AA=E7=8E=AF=E8=8E=B7=E5=8F=96=20userT?= =?UTF-8?q?iny?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/cache/user_c/user.go | 30 ++++++++++++++++++++++++++++++ route/group_r/group_list.go | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/domain/cache/user_c/user.go b/domain/cache/user_c/user.go index 72bba86..db7cc0c 100644 --- a/domain/cache/user_c/user.go +++ b/domain/cache/user_c/user.go @@ -38,6 +38,36 @@ func GetUserTinyById(model *domain.Model, userId mysql.ID) (*user_m.UserTiny, er return userTiny, nil } +// 获取用户简要信息 +// param userId 用户id +func MGetUserTinyById(model *domain.Model, userIds []mysql.ID) []*user_m.UserTiny { + var users []*user_m.UserTiny + for _, userId := range userIds { + if user, _ := GetUserTinyById(model, userId); user != nil { + users = append(users, user) + } + } + return users +} + +// 获取用户externalIds +// return []externalIds map[userId]extId map[userId]code +func GetUserExternalIds(model *domain.Model, userIds []mysql.ID) ([]string, map[uint64]string, map[uint64]string) { + var res []string + var m = make(map[uint64]string) + var c = make(map[uint64]string) + if len(userIds) <= 0 { + return res, m, c + } + users := MGetUserTinyById(model, userIds) + for _, u := range users { + res = append(res, u.ExternalId) + m[u.ID] = u.ExternalId + c[u.ID] = u.Code + } + return res, m, c +} + // 获取用户简要信息By ExternalId func GetUserByExternalId(model *domain.Model, externalId mysql.Str) (*user_m.UserTiny, error) { userId, err := ToUserId(model, externalId) diff --git a/route/group_r/group_list.go b/route/group_r/group_list.go index ca16770..a4d6585 100644 --- a/route/group_r/group_list.go +++ b/route/group_r/group_list.go @@ -1039,7 +1039,7 @@ func GetGroupVisitorsV2(c *gin.Context) (*mycontext.MyContext, error) { beginPos := pageSize * (pageIndex - 1) if uint(beginPos) < result.Total { // 取在线状态 - extIds, userExtIdMap, userCodeMap := user_m.GetUserExternalIds(model, userIds) + extIds, userExtIdMap, userCodeMap := user_c.GetUserExternalIds(model, userIds) statusMap, err := tim_m.GetOnlineStatus(model, extIds) if err != nil { return myContext, err -- 2.22.0