/// <summary> /// 获取用户等级信息 /// </summary> /// <param name="userId"></param> /// <param name="periodId"></param> /// <param name="requestAborted"></param> /// <returns></returns> public async Task <ResponseMessage <SearchTopResponse> > SearchUserTitleAsync(string userId, string periodId, CancellationToken requestAborted) { var response = new ResponseMessage <SearchTopResponse>(); var request = new SearchTopRequest { PeriodId = periodId, PageIndex = 0, PageSize = 999999999 }; //直接通过排名里面取得自己的数据,目前使用人员很少,无所谓。 var top = await SearchTopAsync(request, requestAborted); var userTitleInfo = top.Extension.Where(w => w.UserId == userId).FirstOrDefault(); response.Extension = userTitleInfo; return(response); }
public async Task <PagingResponseMessage <SearchTopResponse> > SearchTop(Models.UserInfo user, [FromBody] SearchTopRequest searchTopRequest) { Logger.Trace($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询排行榜,请求参数为:\r\n" + (searchTopRequest != null ? JsonHelper.ToJson(searchTopRequest) : "")); var response = new PagingResponseMessage <SearchTopResponse>(); if (!ModelState.IsValid) { response.Code = ResponseCodeDefines.ArgumentNullError; response.Message = "模型验证失败"; Logger.Warn("查询排行榜模型验证失败:\r\n{0}", response.Message ?? ""); return(response); } try { response = await _searchManager.SearchTopAsync(searchTopRequest, HttpContext.RequestAborted); } catch (Exception e) { response.Code = ResponseCodeDefines.ServiceError; response.Message = e.Message; Logger.Error($"用户{user?.UserName ?? ""}({user?.Id ?? ""})查询排行榜,报错:{e.Message}\r\n{e.StackTrace}"); } return(response); }
/// <summary> /// 查询排行榜 /// </summary> /// <param name="user"></param> /// <param name="searchTopRequest"></param> /// <param name="requestAborted"></param> /// <returns></returns> public async Task <PagingResponseMessage <SearchTopResponse> > SearchTopAsync(SearchTopRequest searchTopRequest, CancellationToken requestAborted) { var response = new PagingResponseMessage <SearchTopResponse>(); //赛季下的所有人员积分信息 var query = _iSearchStore.GetSearchTop(searchTopRequest.PeriodId); response.TotalCount = await query.CountAsync(); query = query.Skip((searchTopRequest.PageIndex) * searchTopRequest.PageSize).Take(searchTopRequest.PageSize); response.PageIndex = searchTopRequest.PageIndex; response.PageSize = searchTopRequest.PageSize; var topList = await query.ToListAsync(); //称号信息 var titleList = await _iSearchStore.GetScoreTitles().Where(w => !w.IsDelete && w.PeriodId == searchTopRequest.PeriodId).ToListAsync(); //所有人员的印象标签及印象标签次数 var labelList = await _iSearchStore.GetUserLabels().GroupBy(g => new { g.UserId, g.Label }).Select(s => new { UserId = s.Key.UserId, Label = s.Key.Label, LabelCount = s.Count() }).ToListAsync(); //循环组合对应人员的名次、称号名称、称号图标、剩余升级积分、印象标签列表 int number = 1;//排名 topList.ForEach(f => { f.TopNumber = number++; f.Score = f.Score ?? 0; f.ConsumableScore = f.ConsumableScore ?? 0; f.ScoreTitle = (titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score)?.Title) ?? "未知称号"; f.Icon = _config["FileUrl"] + titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score)?.Icon; f.Card = _config["FileUrl"] + titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score)?.Card; f.NextScore = titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score)?.EndScore == null ? 0 : titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score).EndScore - f.Score + 1; f.LabelList = labelList.Where(w => w.UserId == f.UserId).Select(s => new LabelList { Label = s.Label, LabelCount = s.LabelCount }).OrderByDescending(o => o.LabelCount).ToList(); f.FontColor = titleList.FirstOrDefault(fi => fi.StartScore <= f.Score && fi.EndScore >= f.Score)?.FontColor; }); response.Extension = topList; return(response); }