using System.CommandLine; using Gpulse.WCT.DataAnalyzer.Core.Application; namespace Gpulse.WCT.DataAnalyzer.Commands; /// /// 数据导出命令 /// public class ExportCommand : Command { public ExportCommand(ExportService exportService) : base("export", "Export data to CSV or JSON") { var formatOption = new Option( "--format", () => "csv", "Export format: csv or json" ); var outputOption = new Option( "--output", () => "./data/output", "Output directory path" ); var typeOption = new Option( "--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); } }