修改问题
This commit is contained in:
parent
e4e61b1627
commit
91bf543e06
|
|
@ -37,7 +37,7 @@ public class HomeController : CloudGamingControllerBase
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[RedisCache(10, 0)]
|
[RedisCache(10, 0)]
|
||||||
public async Task<List<GameListDto>> GetGameRankingList([FromQuery] string gameId)
|
public async Task<List<GameHistoryListDto>> GetGameRankingList()
|
||||||
{
|
{
|
||||||
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
GameBLL gamebll = new GameBLL(this.ServiceProvider);
|
||||||
return await gamebll.GetGameRankingList();
|
return await gamebll.GetGameRankingList();
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ namespace CloudGaming.Code.Game
|
||||||
/// 获取首页排行榜
|
/// 获取首页排行榜
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public async Task<List<GameListDto>> GetGameRankingList()
|
public async Task<List<GameHistoryListDto>> GetGameRankingList()
|
||||||
{
|
{
|
||||||
//后期需要把这个做出一个服务,每隔几分钟去查询一次
|
//后期需要把这个做出一个服务,每隔几分钟去查询一次
|
||||||
var now = DateTime.Now;
|
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)
|
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);
|
.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点,计算得到的游玩总时间
|
//如果开始时间小于凌晨4点,并且结束时间大于凌晨4点,则用结束时间减去凌晨4点,计算得到的游玩总时间
|
||||||
var list1 = await Dao.DaoPhone.Context.T_User_GameList.Where(it => it.CreateTime < startDate && it.UpdateTime > startDate)
|
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();
|
||||||
.Select(it =>
|
var list2 = list1.Select(it =>
|
||||||
new
|
new
|
||||||
{
|
{
|
||||||
it.GameId,
|
it.GameId,
|
||||||
PlayTime = it.UpdateTime.Subtract(startDate).TotalMinutes
|
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();
|
}).GroupBy(it => it.GameId).Select(it => new { it.Key, PlayTime = it.Sum(it => it.PlayTime) }).OrderByDescending(it => it.PlayTime).Take(20).ToList();
|
||||||
//将结果二查出来合并到结果1中
|
//将结果二查出来合并到结果1中
|
||||||
list1.ForEach(item =>
|
list2.ForEach(item =>
|
||||||
{
|
{
|
||||||
if (list.ContainsKey(item.Key))
|
if (list.ContainsKey(item.Key))
|
||||||
{
|
{
|
||||||
|
|
@ -368,13 +368,16 @@ namespace CloudGaming.Code.Game
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var gameCache = Cache.GameEntityCache;
|
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();
|
list = list.OrderByDescending(it => it.Value).Take(20).ToDictionary();
|
||||||
|
|
||||||
foreach (var gameId in list.Keys)
|
foreach (var gameId in list.Keys)
|
||||||
{
|
{
|
||||||
var gameInfo = gameCache[gameId];
|
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;
|
return gameListDtos;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,16 @@ public class GameHistoryListDto : GameListDto
|
||||||
/// <param name="playtime">游玩时间</param>
|
/// <param name="playtime">游玩时间</param>
|
||||||
public GameHistoryListDto(GameInfo gameInfo, int playtime) : base(gameInfo, Epg.EpgEnum.ImageResStyle.小LOGO)
|
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>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user