实现获取用户角色列表接口

This commit is contained in:
2025-06-19 19:47:34 +08:00
parent cd8ab0f7e8
commit d920cff499
10 changed files with 110 additions and 6 deletions

View File

@ -346,6 +346,42 @@ func (s *gamelifeClient) RequestActivity(ctx context.Context, in *model.QQNetbar
return nil, ecode.Fail.Sub("请求出现异常")
}
return &result, nil
case consts.QueryUserRoleList:
cache, err := s.getOrRefreshCache(ctx, in.PopenId)
if err != nil {
return nil, err
}
cacheKey := fmt.Sprintf(consts.GameLifeUserKey, in.PopenId)
if cache.Params == "" {
// Reconstruct Params with default values
value, err := dao.Games.Ctx(ctx).Where(do.Games{GameId: in.UserRoleParam.Gid}).Fields(dao.Games.Columns().GameCode).Value()
if err != nil {
return nil, ecode.Fail.Sub("获取游戏名称失败")
}
cache.Params, err = s.buildQueryParams(ctx, in.PopenId, cache, value.String(), "", in.BindType, true)
if err != nil {
return nil, err
}
// Update cache with new Params
ttl, err := g.Redis().TTL(ctx, cacheKey)
if err != nil {
return nil, ecode.Fail.Sub("获取缓存过期时间失败")
}
if err := g.Redis().SetEX(ctx, cacheKey, cache, ttl); err != nil {
return nil, ecode.Fail.Sub("更新缓存失败")
}
}
var result model.UserRoleListResponse
resp, err := client.R().
SetContext(ctx).
SetBody(in.UserRoleParam).
SetResult(&result).
Post(fmt.Sprintf("%s%s?%s", taskURL, consts.QueryUserRoleList, cache.Params))
if err != nil || resp.IsError() {
return nil, ecode.Fail.Sub("请求出现异常")
}
return &result.RoleList, nil
default:
return nil, ecode.Fail.Sub(fmt.Sprintf("不支持的任务: %s", in.ServiceName))