diff --git a/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs new file mode 100644 index 00000000..2f36fed0 --- /dev/null +++ b/AsbCloudApp/Services/ProcessMaps/WellDrilling/IProcessMapReportDataSaubStatExportService.cs @@ -0,0 +1,26 @@ +using AsbCloudApp.Requests; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services.ProcessMaps.WellDrilling +{ + /// + /// Сервис экспорт РТК + /// + public interface IProcessMapReportDataSaubStatExportService + { + /// + /// Сформировать файл с данными + /// + /// + /// параметры запроса + /// + /// + Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken); + } +} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index f1e3c84d..f4c62479 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -202,7 +202,7 @@ namespace AsbCloudInfrastructure services.AddScoped(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs index 1bee0843..6f9fa9a3 100644 --- a/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs +++ b/AsbCloudInfrastructure/Services/ProcessMaps/Report/ProcessMapReportDataSaubStatExportService.cs @@ -12,7 +12,7 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services.ProcessMaps.Report { - public class ProcessMapReportDataSaubStatExportService : IProcessMapReportWellDrillingExportService + public class ProcessMapReportDataSaubStatExportService : IProcessMapReportDataSaubStatExportService { const int firstColumn = 2; const int lastColumn = 35; @@ -30,7 +30,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; } - public async Task<(string Name, Stream File)?> ExportAsync(int idWell, CancellationToken cancellationToken) + public async Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken) { var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken); @@ -40,7 +40,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); using var workbook = new XLWorkbook(stream); - var request = new DataSaubStatRequest(); var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); FillProcessMapToWorkbook(workbook, data); diff --git a/AsbCloudInfrastructure/XLExtentions.cs b/AsbCloudInfrastructure/XLExtentions.cs index 5b9517e4..b15fa71f 100644 --- a/AsbCloudInfrastructure/XLExtentions.cs +++ b/AsbCloudInfrastructure/XLExtentions.cs @@ -7,24 +7,16 @@ namespace AsbCloudInfrastructure; public static class XLExtentions { - public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) => - workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) - ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); + public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) => + workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) + ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); - public static IXLCell SetCellValue(this IXLCell cell, T value) - { - if (typeof(T) == typeof(DateTime)) - cell.Style.DateFormat.Format = "DD.MM.YYYY HH:MM:SS"; - - cell.Value = XLCellValue.FromObject(value); - - return cell; - } - - public static IXLCell SetCellValue(this IXLCell cell, T value, string format) + public static IXLCell SetCellValue(this IXLCell cell, T value, string? format = null) { if (typeof(T) == typeof(DateTime)) - cell.Style.DateFormat.Format = format; + { + cell.Style.DateFormat.Format = format ?? "DD.MM.YYYY HH:MM:SS"; + } cell.Value = XLCellValue.FromObject(value); @@ -32,25 +24,25 @@ public static class XLExtentions } public static IXLCell SetHyperlink(this IXLCell cell, string link) - { - cell.SetHyperlink(new XLHyperlink(link)); + { + cell.SetHyperlink(new XLHyperlink(link)); - return cell; - } + return cell; + } - public static T? GetCellValue(this IXLCell cell) - { - try - { - if (cell.IsEmpty() && default(T) == null) - return default; + public static T? GetCellValue(this IXLCell cell) + { + try + { + if (cell.IsEmpty() && default(T) == null) + return default; - return cell.GetValue(); - } - catch - { - throw new FileFormatException( - $"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце"); - } - } + return cell.GetValue(); + } + catch + { + throw new FileFormatException( + $"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце"); + } + } } \ No newline at end of file