Add single rank
This commit is contained in:
parent
7b3fae51b7
commit
ef11e98da7
@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Application.Game.Rank;
|
namespace Application.Game.Rank;
|
||||||
|
|
||||||
public record GetGlobalScoreRankQuery() : IRequestWrapper<string>;
|
public record GetGlobalScoreRankQuery(string Param) : IRequestWrapper<string>;
|
||||||
|
|
||||||
public class GetGlobalScoreRankQueryHandler : IRequestHandlerWrapper<GetGlobalScoreRankQuery, string>
|
public class GetGlobalScoreRankQueryHandler : IRequestHandlerWrapper<GetGlobalScoreRankQuery, string>
|
||||||
{
|
{
|
||||||
@ -21,6 +21,59 @@ public class GetGlobalScoreRankQueryHandler : IRequestHandlerWrapper<GetGlobalSc
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ServiceResult<string>> Handle(GetGlobalScoreRankQuery request, CancellationToken cancellationToken)
|
public async Task<ServiceResult<string>> Handle(GetGlobalScoreRankQuery request, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var param = request.Param.DeserializeCardData<RankParam>();
|
||||||
|
if (param.CardId == 0)
|
||||||
|
{
|
||||||
|
return await GetAllRanks(cancellationToken);
|
||||||
|
}
|
||||||
|
return await GetCardRank(param.CardId, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ServiceResult<string>> GetCardRank(long cardId,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var rank = await cardDbContext.GlobalScoreRanks.FirstOrDefaultAsync(scoreRank => scoreRank.CardId == cardId,
|
||||||
|
cancellationToken: cancellationToken);
|
||||||
|
GlobalScoreRankContainer container;
|
||||||
|
if (rank is null)
|
||||||
|
{
|
||||||
|
container = new GlobalScoreRankContainer
|
||||||
|
{
|
||||||
|
Ranks = new List<ScoreRankDto>(),
|
||||||
|
Status = new RankStatus
|
||||||
|
{
|
||||||
|
TableName = "GlobalScoreRank",
|
||||||
|
StartDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
EndDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
Rows = 1,
|
||||||
|
Status = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new ServiceResult<string>(container.SerializeCardData());
|
||||||
|
}
|
||||||
|
|
||||||
|
var dto = rank.ScoreRankToDto();
|
||||||
|
dto.Id = 0;
|
||||||
|
container = new GlobalScoreRankContainer
|
||||||
|
{
|
||||||
|
Ranks = new List<ScoreRankDto>
|
||||||
|
{
|
||||||
|
dto
|
||||||
|
},
|
||||||
|
Status = new RankStatus
|
||||||
|
{
|
||||||
|
TableName = "GlobalScoreRank",
|
||||||
|
StartDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
EndDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
Rows = 1,
|
||||||
|
Status = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new ServiceResult<string>(container.SerializeCardData());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ServiceResult<string>> GetAllRanks(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var ranks = await cardDbContext.GlobalScoreRanks.OrderBy(rank => rank.Rank)
|
var ranks = await cardDbContext.GlobalScoreRanks.OrderBy(rank => rank.Rank)
|
||||||
.Take(30).ToListAsync(cancellationToken: cancellationToken);
|
.Take(30).ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
@ -10,7 +10,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Application.Game.Rank;
|
namespace Application.Game.Rank;
|
||||||
|
|
||||||
public record GetTenpoScoreRankQuery(int TenpoId) : IRequestWrapper<string>;
|
public record GetTenpoScoreRankQuery(int TenpoId, string Param) : IRequestWrapper<string>;
|
||||||
|
|
||||||
public class GetTenpoScoreRankQueryHandler : IRequestHandlerWrapper<GetTenpoScoreRankQuery, string>
|
public class GetTenpoScoreRankQueryHandler : IRequestHandlerWrapper<GetTenpoScoreRankQuery, string>
|
||||||
{
|
{
|
||||||
@ -23,7 +23,60 @@ public class GetTenpoScoreRankQueryHandler : IRequestHandlerWrapper<GetTenpoScor
|
|||||||
|
|
||||||
public async Task<ServiceResult<string>> Handle(GetTenpoScoreRankQuery request, CancellationToken cancellationToken)
|
public async Task<ServiceResult<string>> Handle(GetTenpoScoreRankQuery request, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var ranks = await cardDbContext.GlobalScoreRanks.Where(rank => rank.LastPlayTenpoId == request.TenpoId)
|
var param = request.Param.DeserializeCardData<RankParam>();
|
||||||
|
if (param.CardId == 0)
|
||||||
|
{
|
||||||
|
return await GetAllRanks(request.TenpoId, cancellationToken);
|
||||||
|
}
|
||||||
|
return await GetCardRank(param.CardId, request.TenpoId, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ServiceResult<string>> GetCardRank(long cardId, int tenpoId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var rank = await cardDbContext.GlobalScoreRanks.FirstOrDefaultAsync(scoreRank => scoreRank.CardId == cardId &&
|
||||||
|
scoreRank.LastPlayTenpoId == tenpoId,
|
||||||
|
cancellationToken: cancellationToken);
|
||||||
|
TenpoScoreRankContainer container;
|
||||||
|
if (rank is null)
|
||||||
|
{
|
||||||
|
container = new TenpoScoreRankContainer
|
||||||
|
{
|
||||||
|
Ranks = new List<ScoreRankDto>(),
|
||||||
|
Status = new RankStatus
|
||||||
|
{
|
||||||
|
TableName = "TenpoScoreRank",
|
||||||
|
StartDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
EndDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
Rows = 1,
|
||||||
|
Status = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new ServiceResult<string>(container.SerializeCardData());
|
||||||
|
}
|
||||||
|
|
||||||
|
var dto = rank.ScoreRankToDto();
|
||||||
|
dto.Id = 0;
|
||||||
|
container = new TenpoScoreRankContainer
|
||||||
|
{
|
||||||
|
Ranks = new List<ScoreRankDto>
|
||||||
|
{
|
||||||
|
dto
|
||||||
|
},
|
||||||
|
Status = new RankStatus
|
||||||
|
{
|
||||||
|
TableName = "TenpoScoreRankContainer",
|
||||||
|
StartDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
EndDate = TimeHelper.DateToString(DateTime.Today),
|
||||||
|
Rows = 1,
|
||||||
|
Status = 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return new ServiceResult<string>(container.SerializeCardData());
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<ServiceResult<string>> GetAllRanks(int tenpoId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var ranks = await cardDbContext.GlobalScoreRanks.Where(rank => rank.LastPlayTenpoId == tenpoId)
|
||||||
.OrderByDescending(rank => rank.TotalScore)
|
.OrderByDescending(rank => rank.TotalScore)
|
||||||
.Take(30)
|
.Take(30)
|
||||||
.ToListAsync(cancellationToken: cancellationToken);
|
.ToListAsync(cancellationToken: cancellationToken);
|
||||||
|
11
Application/Game/Rank/RankParam.cs
Normal file
11
Application/Game/Rank/RankParam.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System.ComponentModel;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace Application.Game.Rank;
|
||||||
|
|
||||||
|
public class RankParam
|
||||||
|
{
|
||||||
|
[XmlElement(ElementName = "card_id")]
|
||||||
|
[DefaultValue("0")]
|
||||||
|
public long CardId { get; set; }
|
||||||
|
}
|
@ -22,11 +22,13 @@ public class MaintainTenpoIdJob : IJob
|
|||||||
|
|
||||||
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records",
|
[SuppressMessage("ReSharper.DPA", "DPA0007: Large number of DB records",
|
||||||
Justification = "All details might be read")]
|
Justification = "All details might be read")]
|
||||||
|
[SuppressMessage("ReSharper.DPA", "DPA0006: Large number of DB commands")]
|
||||||
public async Task Execute(IJobExecutionContext context)
|
public async Task Execute(IJobExecutionContext context)
|
||||||
{
|
{
|
||||||
logger.LogInformation("Starting changing null values in card detail table");
|
logger.LogInformation("Starting changing null values in card detail table");
|
||||||
|
|
||||||
var details = await cardDbContext.CardDetails.Where(detail => detail.LastPlayTenpoId == null).ToListAsync();
|
var details = await cardDbContext.CardDetails.Where(detail => detail.LastPlayTenpoId == null ||
|
||||||
|
detail.LastPlayTenpoId == "GC local server").ToListAsync();
|
||||||
details.ForEach(detail => detail.LastPlayTenpoId="1337");
|
details.ForEach(detail => detail.LastPlayTenpoId="1337");
|
||||||
|
|
||||||
cardDbContext.CardDetails.UpdateRange(details);
|
cardDbContext.CardDetails.UpdateRange(details);
|
||||||
|
@ -12,18 +12,19 @@ public class RankingController : BaseController<RankingController>
|
|||||||
{
|
{
|
||||||
[HttpGet("ranking.php")]
|
[HttpGet("ranking.php")]
|
||||||
public async Task<ActionResult<string>> Ranking([FromQuery(Name = "cmd_type")] int rankType,
|
public async Task<ActionResult<string>> Ranking([FromQuery(Name = "cmd_type")] int rankType,
|
||||||
[FromQuery(Name = "tenpo_id")] int tenpoId)
|
[FromQuery(Name = "tenpo_id")] int tenpoId,
|
||||||
|
[FromQuery(Name = "param")] string param)
|
||||||
{
|
{
|
||||||
var type = (RankingCommandType)rankType;
|
var type = (RankingCommandType)rankType;
|
||||||
type.Throw().IfOutOfRange();
|
type.Throw().IfOutOfRange();
|
||||||
|
|
||||||
var result = type switch
|
var result = type switch
|
||||||
{
|
{
|
||||||
RankingCommandType.GlobalRank => await Mediator.Send(new GetGlobalScoreRankQuery()),
|
RankingCommandType.GlobalRank => await Mediator.Send(new GetGlobalScoreRankQuery(param)),
|
||||||
RankingCommandType.PlayNumRank => await Mediator.Send(new GetPlayNumRankQuery()),
|
RankingCommandType.PlayNumRank => await Mediator.Send(new GetPlayNumRankQuery()),
|
||||||
RankingCommandType.EventRank => await Mediator.Send(new GetEventRankQuery()),
|
RankingCommandType.EventRank => await Mediator.Send(new GetEventRankQuery()),
|
||||||
RankingCommandType.MonthlyRank => await Mediator.Send(new GetMonthlyScoreRankQuery()),
|
RankingCommandType.MonthlyRank => await Mediator.Send(new GetMonthlyScoreRankQuery()),
|
||||||
RankingCommandType.ShopRank => await Mediator.Send(new GetTenpoScoreRankQuery(tenpoId)),
|
RankingCommandType.ShopRank => await Mediator.Send(new GetTenpoScoreRankQuery(tenpoId, param)),
|
||||||
_ => throw new ArgumentOutOfRangeException(nameof(type), type, "Should not happen!")
|
_ => throw new ArgumentOutOfRangeException(nameof(type), type, "Should not happen!")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user