diff --git a/NEW/src/JdeScoping.ExcelIO/ExcelExportService.cs b/NEW/src/JdeScoping.ExcelIO/ExcelExportService.cs index 8f3bff6..f85eb4e 100644 --- a/NEW/src/JdeScoping.ExcelIO/ExcelExportService.cs +++ b/NEW/src/JdeScoping.ExcelIO/ExcelExportService.cs @@ -1,14 +1,16 @@ -using System.Reflection; using ClosedXML.Excel; using JdeScoping.Core.Interfaces; -using JdeScoping.ExcelIO.Attributes; +using JdeScoping.Core.Models.SearchResults; using JdeScoping.ExcelIO.Options; using JdeScoping.ExcelIO.Formatting; using JdeScoping.ExcelIO.Generators; -using JdeScoping.ExcelIO.Models.Reporting; +using JdeScoping.ExcelIO.Mapping; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +// Use ExcelIO's SearchModel which contains criteria filter properties for CriteriaSheetGenerator +using ExcelSearchModel = JdeScoping.ExcelIO.Models.Reporting.SearchModel; + namespace JdeScoping.ExcelIO; /// @@ -19,7 +21,8 @@ public class ExcelExportService : IExcelExportService private readonly ILogger _logger; private readonly IOptions _options; private readonly CriteriaSheetGenerator _criteriaGenerator; - private readonly AttributeTableWriter _tableWriter; + private readonly FluentTableWriter _tableWriter; + private readonly ExcelMapRegistry _registry; /// /// Initializes a new instance of the ExcelExportService class. @@ -27,25 +30,28 @@ public class ExcelExportService : IExcelExportService /// Logger instance. /// Excel export options. /// Criteria sheet generator. - /// Attribute table writer. + /// Fluent table writer. + /// Excel map registry. public ExcelExportService( ILogger logger, IOptions options, CriteriaSheetGenerator criteriaGenerator, - AttributeTableWriter tableWriter) + FluentTableWriter tableWriter, + ExcelMapRegistry registry) { _logger = logger; _options = options; _criteriaGenerator = criteriaGenerator; _tableWriter = tableWriter; + _registry = registry; } /// public async Task GenerateAsync(object search, CancellationToken cancellationToken = default) { - if (search is not SearchModel searchModel) + if (search is not ExcelSearchModel searchModel) { - throw new ArgumentException($"Expected {nameof(SearchModel)} but received {search.GetType().Name}", nameof(search)); + throw new ArgumentException($"Expected {nameof(ExcelSearchModel)} but received {search.GetType().Name}", nameof(search)); } return await GenerateAsync(searchModel, cancellationToken); @@ -57,7 +63,7 @@ public class ExcelExportService : IExcelExportService /// Search model with criteria and results. /// Cancellation token. /// Excel file as byte array. - public async Task GenerateAsync(SearchModel search, CancellationToken cancellationToken = default) + public async Task GenerateAsync(ExcelSearchModel search, CancellationToken cancellationToken = default) { using var scope = _logger.BeginScope(new Dictionary { @@ -128,8 +134,8 @@ public class ExcelExportService : IExcelExportService private void GenerateResultsSheet(XLWorkbook workbook, List results) { - var tableAttr = typeof(SearchResult).GetCustomAttribute(); - var tabName = tableAttr?.TabName ?? "Search Results"; + var map = _registry.GetMap(); + var tabName = map.TabName ?? "Search Results"; var worksheet = workbook.Worksheets.Add(tabName); var table = _tableWriter.WriteTable(worksheet, 1, 1, results); @@ -147,8 +153,8 @@ public class ExcelExportService : IExcelExportService private void GenerateMisInfoSheet(XLWorkbook workbook, List misResults) { - var tableAttr = typeof(MisSearchResult).GetCustomAttribute(); - var tabName = tableAttr?.TabName ?? "MIS Info"; + var map = _registry.GetMap(); + var tabName = map.TabName ?? "MIS Info"; var worksheet = workbook.Worksheets.Add(tabName); var table = _tableWriter.WriteTable(worksheet, 1, 1, misResults); @@ -166,8 +172,8 @@ public class ExcelExportService : IExcelExportService private void GenerateInvestigationSheet(XLWorkbook workbook, List misNonMatchResults) { - var tableAttr = typeof(MisNonMatchSearchResult).GetCustomAttribute(); - var tabName = tableAttr?.TabName ?? "Investigation"; + var map = _registry.GetMap(); + var tabName = map.TabName ?? "Investigation"; var worksheet = workbook.Worksheets.Add(tabName); var table = _tableWriter.WriteTable(worksheet, 1, 1, misNonMatchResults); diff --git a/NEW/src/JdeScoping.ExcelIO/Models/Reporting/SearchModel.cs b/NEW/src/JdeScoping.ExcelIO/Models/Reporting/SearchModel.cs index cb599ac..9071cc3 100644 --- a/NEW/src/JdeScoping.ExcelIO/Models/Reporting/SearchModel.cs +++ b/NEW/src/JdeScoping.ExcelIO/Models/Reporting/SearchModel.cs @@ -1,3 +1,7 @@ +using CoreSearchResult = JdeScoping.Core.Models.SearchResults.SearchResult; +using CoreMisSearchResult = JdeScoping.Core.Models.SearchResults.MisSearchResult; +using CoreMisNonMatchSearchResult = JdeScoping.Core.Models.SearchResults.MisNonMatchSearchResult; + namespace JdeScoping.ExcelIO.Models.Reporting; /// @@ -128,15 +132,15 @@ public class SearchModel /// /// Work order search results. /// - public List Results { get; set; } = []; + public List Results { get; set; } = []; /// /// MIS results. /// - public List? MisResults { get; set; } + public List? MisResults { get; set; } /// /// MIS no match found results. /// - public List? MisNonMatchResults { get; set; } + public List? MisNonMatchResults { get; set; } }