From 91bf543e060bd32b41525efc6e09f97cb6f75f80 Mon Sep 17 00:00:00 2001 From: zpc Date: Tue, 19 Nov 2024 20:05:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/HomeController.cs | 2 +- .../Code/CloudGaming.Code/Game/GameBLL.cs | 25 +++++++++++-------- .../Game/GameHistoryListDto.cs | 11 +++++++- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/CloudGaming/Api/CloudGaming.Api/Controllers/HomeController.cs b/src/CloudGaming/Api/CloudGaming.Api/Controllers/HomeController.cs index c22d5b8..20935e0 100644 --- a/src/CloudGaming/Api/CloudGaming.Api/Controllers/HomeController.cs +++ b/src/CloudGaming/Api/CloudGaming.Api/Controllers/HomeController.cs @@ -37,7 +37,7 @@ public class HomeController : CloudGamingControllerBase /// [HttpGet] [RedisCache(10, 0)] - public async Task> GetGameRankingList([FromQuery] string gameId) + public async Task> GetGameRankingList() { GameBLL gamebll = new GameBLL(this.ServiceProvider); return await gamebll.GetGameRankingList(); diff --git a/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs index 77a51d9..7db356b 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Game/GameBLL.cs @@ -334,7 +334,7 @@ namespace CloudGaming.Code.Game /// 获取首页排行榜 /// /// - public async Task> GetGameRankingList() + public async Task> 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 gameListDtos = new List(); + List gameListDtos = new List(); 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; } diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/Game/GameHistoryListDto.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/Game/GameHistoryListDto.cs index b78e929..81bb6bd 100644 --- a/src/CloudGaming/Model/CloudGaming.DtoModel/Game/GameHistoryListDto.cs +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/Game/GameHistoryListDto.cs @@ -27,7 +27,16 @@ public class GameHistoryListDto : GameListDto /// 游玩时间 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.##")}小时"; + } + /// + /// + /// + /// 游戏 + /// 游玩时间 + public GameHistoryListDto(GameInfo gameInfo, int playtime, Epg.EpgEnum.ImageResStyle imageResStyle) : base(gameInfo, imageResStyle) + { + this.Playtime = $"{(playtime / 60.0).ToString("0.##")}小时"; } ///