refactor(core): 重构核心分层结构并添加发布库聚合

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Scottxjw
2026-08-13 15:00:39 +08:00
parent 6e197a0cce
commit a3100c73c5
45 changed files with 501 additions and 77 deletions

View File

@@ -0,0 +1,33 @@
using System.CommandLine;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Commands;
/// <summary>
/// 从本地解析库生成正式发布库。
/// </summary>
public class AggregateCommand : Command
{
public AggregateCommand(AggregationService aggregationService)
: base("aggregate", "Aggregate local log data into the release database")
{
var rebuildOption = new Option<bool>(
"--rebuild",
() => true,
"Rebuild the release table before inserting aggregated records");
AddOption(rebuildOption);
this.SetHandler(async rebuild =>
{
try
{
var report = await aggregationService.AggregateAsync(rebuild);
Console.WriteLine($"Aggregated {report.LocalRecordCount} local Ploss records into {report.ReleaseRecordCount} release records.");
}
catch (Exception ex)
{
Console.WriteLine($"Aggregation failed: {ex.Message}");
}
}, rebuildOption);
}
}

View File

@@ -1,5 +1,5 @@
using System.CommandLine;
using Gpulse.WCT.DataAnalyzer.Core.Services;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Commands;

View File

@@ -1,5 +1,5 @@
using System.CommandLine;
using Gpulse.WCT.DataAnalyzer.Core.Services;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Commands;
@@ -25,8 +25,8 @@ public class ExportCommand : Command
var typeOption = new Option<string>(
"--type",
() => "all",
"Data type to export: qfod, ploss, or all"
() => "charging-parameters",
"Data type: charging-parameters, qfod, ploss, or all"
);
AddOption(formatOption);
@@ -44,6 +44,12 @@ public class ExportCommand : Command
{
if (format == "csv")
{
if (type is "charging-parameters" or "charging" or "all")
{
var path = await exportService.ExportChargingParametersToCsvAsync(output);
Console.WriteLine($" ChargingParameterDatabase CSV exported: {path}");
}
if (type is "qfod" or "all")
{
var path = await exportService.ExportQfodToCsvAsync(output);

View File

@@ -1,5 +1,5 @@
using System.CommandLine;
using Gpulse.WCT.DataAnalyzer.Core.Services;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Commands;

View File

@@ -1,5 +1,5 @@
using System.CommandLine;
using Gpulse.WCT.DataAnalyzer.Core.Services;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer.Commands;

View File

@@ -4,9 +4,9 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Serilog;
using Gpulse.WCT.DataAnalyzer.Commands;
using Gpulse.WCT.DataAnalyzer.Core.Data;
using Gpulse.WCT.DataAnalyzer.Core.Extensions;
using Gpulse.WCT.DataAnalyzer.Core.Services;
using Gpulse.WCT.DataAnalyzer.Core.Infrastructure.LocalData;
using Gpulse.WCT.DataAnalyzer.Core.Infrastructure.Extensions;
using Gpulse.WCT.DataAnalyzer.Core.Application;
namespace Gpulse.WCT.DataAnalyzer;
@@ -19,7 +19,7 @@ public class Program
{
// 1. 构建引导配置(用于 Serilog 初始化)
var bootstrapConfig = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.SetBasePath(AppContext.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false)
.AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("DOTNET_ENVIRONMENT") ?? "Production"}.json", optional: true)
.AddEnvironmentVariables()
@@ -59,6 +59,9 @@ public class Program
var dbContext = scope.ServiceProvider.GetRequiredService<WctMinerDbContext>();
await dbContext.Database.EnsureCreatedAsync();
var releaseContext = scope.ServiceProvider.GetRequiredService<ReleaseDbContext>();
await releaseContext.Database.EnsureCreatedAsync();
// 种子数据
SeedData.Initialize(dbContext);
}
@@ -70,6 +73,7 @@ public class Program
var rootCommand = new RootCommand("Gpulse.WCT.DataAnalyzer - FOD Log Data Parser");
rootCommand.AddCommand(new ParseCommand(provider.GetRequiredService<ParseService>()));
rootCommand.AddCommand(new AggregateCommand(provider.GetRequiredService<AggregationService>()));
rootCommand.AddCommand(new StatsCommand(provider.GetRequiredService<StatsService>()));
rootCommand.AddCommand(new ExportCommand(provider.GetRequiredService<ExportService>()));
rootCommand.AddCommand(new CleanCommand(provider.GetRequiredService<CleanService>()));