90 lines
3.0 KiB
C#
90 lines
3.0 KiB
C#
using System.CommandLine;
|
|
using Gpulse.WCT.DataAnalyzer.Core.Application;
|
|
|
|
namespace Gpulse.WCT.DataAnalyzer.Commands;
|
|
|
|
/// <summary>
|
|
/// 数据导出命令
|
|
/// </summary>
|
|
public class ExportCommand : Command
|
|
{
|
|
public ExportCommand(ExportService exportService)
|
|
: base("export", "Export data to CSV or JSON")
|
|
{
|
|
var formatOption = new Option<string>(
|
|
"--format",
|
|
() => "csv",
|
|
"Export format: csv or json"
|
|
);
|
|
|
|
var outputOption = new Option<string>(
|
|
"--output",
|
|
() => "./data/output",
|
|
"Output directory path"
|
|
);
|
|
|
|
var typeOption = new Option<string>(
|
|
"--type",
|
|
() => "charging-parameters",
|
|
"Data type: charging-parameters, qfod, ploss, or all"
|
|
);
|
|
|
|
AddOption(formatOption);
|
|
AddOption(outputOption);
|
|
AddOption(typeOption);
|
|
|
|
this.SetHandler(async (format, output, type) =>
|
|
{
|
|
format = format.ToLower();
|
|
type = type.ToLower();
|
|
|
|
Console.WriteLine($"Exporting {type} data as {format.ToUpper()} to {output}...");
|
|
|
|
try
|
|
{
|
|
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);
|
|
Console.WriteLine($" Qfod CSV exported: {path}");
|
|
}
|
|
|
|
if (type is "ploss" or "all")
|
|
{
|
|
var path = await exportService.ExportPlossToCsvAsync(output);
|
|
Console.WriteLine($" Ploss CSV exported: {path}");
|
|
}
|
|
}
|
|
else if (format == "json")
|
|
{
|
|
if (type is "qfod" or "all")
|
|
{
|
|
var path = await exportService.ExportQfodToJsonAsync(output);
|
|
Console.WriteLine($" Qfod JSON exported: {path}");
|
|
}
|
|
|
|
if (type is "ploss" or "all")
|
|
{
|
|
var path = await exportService.ExportPlossToJsonAsync(output);
|
|
Console.WriteLine($" Ploss JSON exported: {path}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine($"Unknown format: {format}. Use 'csv' or 'json'.");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"Export failed: {ex.Message}");
|
|
}
|
|
}, formatOption, outputOption, typeOption);
|
|
}
|
|
} |