Правки после ревью

This commit is contained in:
Olga Nemt 2024-02-16 15:21:01 +05:00
parent 30d8632dd7
commit 9b5bc227b0
4 changed files with 54 additions and 37 deletions

View File

@ -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
{
/// <summary>
/// Сервис экспорт РТК
/// </summary>
public interface IProcessMapReportDataSaubStatExportService
{
/// <summary>
/// Сформировать файл с данными
/// </summary>
/// <param name="idWell"></param>
/// <param name="request">параметры запроса</param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<(string Name, Stream File)?> ExportAsync(int idWell, DataSaubStatRequest request, CancellationToken cancellationToken);
}
}

View File

@ -202,7 +202,7 @@ namespace AsbCloudInfrastructure
services.AddScoped<IWellService, WellService>(); services.AddScoped<IWellService, WellService>();
services.AddTransient<IWellOperationImportService, WellOperationImportService>(); services.AddTransient<IWellOperationImportService, WellOperationImportService>();
services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportWellDrillingExportService>(); services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportWellDrillingExportService>();
services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportDataSaubStatExportService>(); services.AddTransient<IProcessMapReportDataSaubStatExportService, ProcessMapReportDataSaubStatExportService>();
services.AddTransient<TrajectoryPlanExportService>(); services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>(); services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>(); services.AddTransient<TrajectoryFactNnbExportService>();

View File

@ -12,7 +12,7 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services.ProcessMaps.Report namespace AsbCloudInfrastructure.Services.ProcessMaps.Report
{ {
public class ProcessMapReportDataSaubStatExportService : IProcessMapReportWellDrillingExportService public class ProcessMapReportDataSaubStatExportService : IProcessMapReportDataSaubStatExportService
{ {
const int firstColumn = 2; const int firstColumn = 2;
const int lastColumn = 35; const int lastColumn = 35;
@ -30,7 +30,7 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report
this.processMapReportDataSaubStatService = processMapReportDataSaubStatService; 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); var well = await wellService.GetOrDefaultAsync(idWell, cancellationToken);
@ -40,7 +40,6 @@ namespace AsbCloudInfrastructure.Services.ProcessMaps.Report
var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName); var stream = Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateName);
using var workbook = new XLWorkbook(stream); using var workbook = new XLWorkbook(stream);
var request = new DataSaubStatRequest();
var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken); var data = await processMapReportDataSaubStatService.GetAsync(idWell, request, cancellationToken);
FillProcessMapToWorkbook(workbook, data); FillProcessMapToWorkbook(workbook, data);

View File

@ -7,24 +7,16 @@ namespace AsbCloudInfrastructure;
public static class XLExtentions public static class XLExtentions
{ {
public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) => public static IXLWorksheet GetWorksheet(this IXLWorkbook workbook, string sheetName) =>
workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase)) workbook.Worksheets.FirstOrDefault(ws => string.Equals(ws.Name.Trim(), sheetName.Trim(), StringComparison.CurrentCultureIgnoreCase))
?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}."); ?? throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
public static IXLCell SetCellValue<T>(this IXLCell cell, T value) public static IXLCell SetCellValue<T>(this IXLCell cell, T value, string? format = null)
{
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<T>(this IXLCell cell, T value, string format)
{ {
if (typeof(T) == typeof(DateTime)) 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); cell.Value = XLCellValue.FromObject(value);
@ -32,25 +24,25 @@ public static class XLExtentions
} }
public static IXLCell SetHyperlink(this IXLCell cell, string link) 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<T>(this IXLCell cell) public static T? GetCellValue<T>(this IXLCell cell)
{ {
try try
{ {
if (cell.IsEmpty() && default(T) == null) if (cell.IsEmpty() && default(T) == null)
return default; return default;
return cell.GetValue<T>(); return cell.GetValue<T>();
} }
catch catch
{ {
throw new FileFormatException( throw new FileFormatException(
$"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце"); $"Лист '{cell.Worksheet.Name}'. {cell.Address.RowNumber} строка содержит некорректное значение в {cell.Address.ColumnNumber} столбце");
} }
} }
} }