From 9d58e71e0699fffad95bc8358355d505070a2819 Mon Sep 17 00:00:00 2001
From: asesidaa <1061472754@qq.com>
Date: Wed, 15 Feb 2023 02:14:19 +0800
Subject: [PATCH] Basically finish migration for server, implement play number
rank, wait for testing
---
Application/Application.csproj | 5 +-
.../Extensions/XmlSerializationExtensions.cs | 14 ++
Application/Common/Helpers/TimeHelper.cs | 5 +
Application/DependencyInjection.cs | 23 ++
Application/Dto/PlayNumRankDto.cs | 33 +++
.../Game/Card/CardRequestHandlerBase.cs | 3 -
Application/Game/Card/Read/ReadCardQuery.cs | 3 +-
.../Game/Card/Write/WriteCardBDataCommand.cs | 2 +-
.../Game/Card/Write/WriteCardDetailCommand.cs | 2 +-
Application/Game/Rank/GetEventRankQuery.cs | 43 ++++
.../Game/Rank/GetGlobalScoreRankQuery.cs | 43 ++++
.../Game/Rank/GetMonthlyScoreRankQuery.cs | 43 ++++
Application/Game/Rank/GetPlayNumRankQuery.cs | 68 ++++++
.../Game/Rank/GetTenpoScoreRankQuery.cs | 43 ++++
Application/Game/Rank/RankStatus.cs | 21 ++
Application/Game/Server/CertifyCommand.cs | 2 +-
Application/Interfaces/ICardDbContext.cs | 2 +
Application/Jobs/UpdatePlayNumRankJob.cs | 65 ++++++
Application/Mappers/PlayNumRankMapper.cs | 13 ++
Domain/Entities/PlayNumRank.cs | 19 ++
.../20230214162154_AddPlayNumRank.Designer.cs | 215 ++++++++++++++++++
.../20230214162154_AddPlayNumRank.cs | 39 ++++
.../Migrations/CardDbContextModelSnapshot.cs | 33 +++
Infrastructure/Persistence/CardDbContext.cs | 19 ++
.../Controllers/Game/RankingController.cs | 37 +--
.../Filters/ApiExceptionFilterAttributes.cs | 2 +-
MainServer/Program.cs | 5 +-
27 files changed, 774 insertions(+), 28 deletions(-)
create mode 100644 Application/Dto/PlayNumRankDto.cs
create mode 100644 Application/Game/Rank/GetEventRankQuery.cs
create mode 100644 Application/Game/Rank/GetGlobalScoreRankQuery.cs
create mode 100644 Application/Game/Rank/GetMonthlyScoreRankQuery.cs
create mode 100644 Application/Game/Rank/GetPlayNumRankQuery.cs
create mode 100644 Application/Game/Rank/GetTenpoScoreRankQuery.cs
create mode 100644 Application/Game/Rank/RankStatus.cs
create mode 100644 Application/Jobs/UpdatePlayNumRankJob.cs
create mode 100644 Application/Mappers/PlayNumRankMapper.cs
create mode 100644 Domain/Entities/PlayNumRank.cs
create mode 100644 Infrastructure/Migrations/20230214162154_AddPlayNumRank.Designer.cs
create mode 100644 Infrastructure/Migrations/20230214162154_AddPlayNumRank.cs
diff --git a/Application/Application.csproj b/Application/Application.csproj
index 0322e9c..a8f1596 100644
--- a/Application/Application.csproj
+++ b/Application/Application.csproj
@@ -18,12 +18,9 @@
+
-
-
-
-
diff --git a/Application/Common/Extensions/XmlSerializationExtensions.cs b/Application/Common/Extensions/XmlSerializationExtensions.cs
index 7a39b30..ceada69 100644
--- a/Application/Common/Extensions/XmlSerializationExtensions.cs
+++ b/Application/Common/Extensions/XmlSerializationExtensions.cs
@@ -28,6 +28,20 @@ public static class XmlSerializationExtensions
}
return buffer.ToString();
}
+
+ public static string SerializeCardData(this T source) where T : class
+ {
+ var buffer = new StringBuilder();
+ using (var writer = new ChoXmlWriter(buffer).UseXmlSerialization())
+ {
+ writer.Configuration.OmitXmlDeclaration = false;
+ writer.Configuration.DoNotEmitXmlNamespace = true;
+ writer.Configuration.IgnoreRootName = true;
+ writer.Write(source);
+ }
+ return buffer.ToString();
+ }
+
public static string SerializeCardDataList(this IEnumerable source, string xpath) where T : class
{
var buffer = new StringBuilder();
diff --git a/Application/Common/Helpers/TimeHelper.cs b/Application/Common/Helpers/TimeHelper.cs
index 0f81959..b5d31bf 100644
--- a/Application/Common/Helpers/TimeHelper.cs
+++ b/Application/Common/Helpers/TimeHelper.cs
@@ -6,4 +6,9 @@ public static class TimeHelper
{
return DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
+
+ public static string DateToString(DateTime time)
+ {
+ return time.ToString("yyyy-MM-dd");
+ }
}
\ No newline at end of file
diff --git a/Application/DependencyInjection.cs b/Application/DependencyInjection.cs
index 6e630d0..242bb3b 100644
--- a/Application/DependencyInjection.cs
+++ b/Application/DependencyInjection.cs
@@ -2,8 +2,10 @@
using Application.Common.Behaviours;
using Application.Game.Card;
using Application.Interfaces;
+using Application.Jobs;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
+using Quartz;
namespace Application;
@@ -15,6 +17,27 @@ public static class DependencyInjection
services.AddScoped();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
+ services.AddQuartz(q =>
+ {
+ q.UseMicrosoftDependencyInjectionJobFactory();
+ var jobKey = new JobKey("UpdatePlayNumRankJob");
+ q.AddJob(options => options.WithIdentity(jobKey));
+
+ q.AddTrigger(options =>
+ {
+ options.ForJob(jobKey)
+ .WithIdentity("UpdatePlayNumRankJob-trigger")
+ .StartNow()
+ .WithSimpleSchedule(x =>
+ {
+ x.WithIntervalInHours(24).RepeatForever();
+ });
+ });
+ });
+ services.AddQuartzHostedService(options =>
+ {
+ options.WaitForJobsToComplete = true;
+ });
return services;
}
}
\ No newline at end of file
diff --git a/Application/Dto/PlayNumRankDto.cs b/Application/Dto/PlayNumRankDto.cs
new file mode 100644
index 0000000..4170897
--- /dev/null
+++ b/Application/Dto/PlayNumRankDto.cs
@@ -0,0 +1,33 @@
+using System.Xml.Serialization;
+
+namespace Application.Dto;
+
+public class PlayNumRankDto
+{
+ [XmlAttribute(AttributeName = "id")]
+ public int Id { get; set; }
+
+ [XmlElement("rank")]
+ public int Rank { get; set; }
+
+ [XmlElement("rank2")]
+ public int Rank2 { get; set; }
+
+ [XmlElement("prev_rank")]
+ public int PrevRank { get; set; }
+
+ [XmlElement("prev_rank2")]
+ public int PrevRank2 { get; set; }
+
+ [XmlElement("pcol1")]
+ public int Pcol1 { get; set; }
+
+ [XmlElement("score_bi1")]
+ public int ScoreBi1 { get; set; }
+
+ [XmlElement("title")]
+ public string Title { get; set; } = string.Empty;
+
+ [XmlElement("artist")]
+ public string Artist { get; set; } = string.Empty;
+}
\ No newline at end of file
diff --git a/Application/Game/Card/CardRequestHandlerBase.cs b/Application/Game/Card/CardRequestHandlerBase.cs
index b8f1bcb..c5f7912 100644
--- a/Application/Game/Card/CardRequestHandlerBase.cs
+++ b/Application/Game/Card/CardRequestHandlerBase.cs
@@ -1,9 +1,6 @@
using Application.Common.Models;
using Application.Interfaces;
using Domain.Config;
-using MediatR;
-using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
namespace Application.Game.Card;
diff --git a/Application/Game/Card/Read/ReadCardQuery.cs b/Application/Game/Card/Read/ReadCardQuery.cs
index 8a67286..661ab51 100644
--- a/Application/Game/Card/Read/ReadCardQuery.cs
+++ b/Application/Game/Card/Read/ReadCardQuery.cs
@@ -1,6 +1,7 @@
using Application.Common.Extensions;
using Application.Common.Models;
using Application.Interfaces;
+using Application.Mappers;
using Domain.Enums;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
@@ -26,7 +27,7 @@ public class ReadCardQueryHandler : CardRequestHandlerBase(new ServiceError($"Card id: {request.CardId} does not exist!", (int)CardReturnCode.CardNotRegistered));
}
- var result = card.SerializeCardData("/root/card");
+ var result = card.CardMainToCardDto().SerializeCardData("/root/card");
return new ServiceResult(result);
}
diff --git a/Application/Game/Card/Write/WriteCardBDataCommand.cs b/Application/Game/Card/Write/WriteCardBDataCommand.cs
index 7005108..9d7f078 100644
--- a/Application/Game/Card/Write/WriteCardBDataCommand.cs
+++ b/Application/Game/Card/Write/WriteCardBDataCommand.cs
@@ -33,7 +33,7 @@ public class WriteCardBDataCommandHandler : CardRequestHandlerBase();
var data = dto.DtoToCardBDatum();
data.CardId = request.CardId;
- CardDbContext.CardBdata.Upsert(data);
+ await CardDbContext.CardBdata.Upsert(data).RunAsync(cancellationToken);
await CardDbContext.SaveChangesAsync(cancellationToken);
diff --git a/Application/Game/Card/Write/WriteCardDetailCommand.cs b/Application/Game/Card/Write/WriteCardDetailCommand.cs
index 6f90d08..f71ac4b 100644
--- a/Application/Game/Card/Write/WriteCardDetailCommand.cs
+++ b/Application/Game/Card/Write/WriteCardDetailCommand.cs
@@ -34,7 +34,7 @@ public class WriteCardDetailCommandHandler : CardRequestHandlerBase;
+
+public class GetEventRankQueryHandler : IRequestHandlerWrapper
+{
+ public Task> Handle(GetEventRankQuery request, CancellationToken cancellationToken)
+ {
+ var container = new EventRankContainer
+ {
+ Ranks = new List