修改问题

This commit is contained in:
zpc 2024-11-19 20:05:46 +08:00
parent e4e61b1627
commit 91bf543e06
3 changed files with 25 additions and 13 deletions

View File

@ -37,7 +37,7 @@ public class HomeController : CloudGamingControllerBase
/// <returns></returns>
[HttpGet]
[RedisCache(10, 0)]
public async Task<List<GameListDto>> GetGameRankingList([FromQuery] string gameId)
public async Task<List<GameHistoryListDto>> GetGameRankingList()
{
GameBLL gamebll = new GameBLL(this.ServiceProvider);
return await gamebll.GetGameRankingList();

View File

@ -334,7 +334,7 @@ namespace CloudGaming.Code.Game
/// 获取首页排行榜
/// </summary>
/// <returns></returns>
public async Task<List<GameListDto>> GetGameRankingList()
public async Task<List<GameHistoryListDto>> GetGameRankingList()
{
//后期需要把这个做出一个服务,每隔几分钟去查询一次
var now = DateTime.Now;
@ -348,15 +348,15 @@ namespace CloudGaming.Code.Game
var list = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.CreateTime > startDate)
.GroupBy(it => it.GameId).Select(it => new { it.Key, PlayTime = it.Sum(it => it.PlayTime) }).OrderByDescending(it => it.PlayTime).Take(20).ToDictionaryAsync(it => it.Key, it => it.PlayTime);
//如果开始时间小于凌晨4点并且结束时间大于凌晨4点则用结束时间减去凌晨4点计算得到的游玩总时间
var list1 = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.CreateTime < startDate && it.UpdateTime > startDate)
.Select(it =>
new
{
it.GameId,
PlayTime = it.UpdateTime.Subtract(startDate).TotalMinutes
}).GroupBy(it => it.GameId).Select(it => new { it.Key, PlayTime = it.Sum(it => it.PlayTime) }).OrderByDescending(it => it.PlayTime).Take(20).ToListAsync();
var list1 = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.CreateTime < startDate && it.UpdateTime > startDate).Select(it => new { it.GameId, it.UpdateTime }).ToListAsync();
var list2 = list1.Select(it =>
new
{
it.GameId,
PlayTime = it.UpdateTime.Subtract(startDate).TotalMinutes
}).GroupBy(it => it.GameId).Select(it => new { it.Key, PlayTime = it.Sum(it => it.PlayTime) }).OrderByDescending(it => it.PlayTime).Take(20).ToList();
//将结果二查出来合并到结果1中
list1.ForEach(item =>
list2.ForEach(item =>
{
if (list.ContainsKey(item.Key))
{
@ -368,13 +368,16 @@ namespace CloudGaming.Code.Game
}
});
var gameCache = Cache.GameEntityCache;
List<GameListDto> gameListDtos = new List<GameListDto>();
List<GameHistoryListDto> gameListDtos = new List<GameHistoryListDto>();
list = list.OrderByDescending(it => it.Value).Take(20).ToDictionary();
foreach (var gameId in list.Keys)
{
var gameInfo = gameCache[gameId];
gameListDtos.Add(new GameListDto(gameInfo, ImageResStyle.LOGO));
if (gameInfo != null)
{
gameListDtos.Add(new GameHistoryListDto(gameInfo, list[gameId], ImageResStyle.LOGO));
}
}
return gameListDtos;
}

View File

@ -27,7 +27,16 @@ public class GameHistoryListDto : GameListDto
/// <param name="playtime">游玩时间</param>
public GameHistoryListDto(GameInfo gameInfo, int playtime) : base(gameInfo, Epg.EpgEnum.ImageResStyle.LOGO)
{
this.Playtime = $"{(playtime / 60).ToString("0.##")}小时";
this.Playtime = $"{(playtime / 60.0).ToString("0.##")}小时";
}
/// <summary>
///
/// </summary>
/// <param name="gameInfo">游戏</param>
/// <param name="playtime">游玩时间</param>
public GameHistoryListDto(GameInfo gameInfo, int playtime, Epg.EpgEnum.ImageResStyle imageResStyle) : base(gameInfo, imageResStyle)
{
this.Playtime = $"{(playtime / 60.0).ToString("0.##")}小时";
}
/// <summary>