This commit is contained in:
ngfrolov 2024-03-15 14:33:21 +05:00
commit 271b9d363d
Signed by: ng.frolov
GPG Key ID: E99907A0357B29A7
42 changed files with 609 additions and 338 deletions

View File

@ -17,7 +17,7 @@ public class ProcessMapPlanDrillingDto : ProcessMapPlanBaseDto
/// Название режима бурения
/// </summary>
public string? Mode { get; set; }
/// <summary>
/// Осевая нагрузка, т план
/// </summary>

View File

@ -0,0 +1,8 @@
namespace AsbCloudApp.Requests.ExportOptions;
/// <summary>
/// Параметры экспорта
/// </summary>
public interface IExportOptionsRequest
{
}

View File

@ -0,0 +1,21 @@
namespace AsbCloudApp.Requests.ExportOptions;
/// <summary>
/// Параметры экспорта
/// </summary>
public class WellRelatedExportRequest : IExportOptionsRequest
{
/// <summary>
/// Конструктор
/// </summary>
/// <param name="idWell">Id скважины</param>
public WellRelatedExportRequest(int idWell)
{
IdWell = idWell;
}
/// <summary>
/// Id скважины
/// </summary>
public int IdWell { get; }
}

View File

@ -0,0 +1,21 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests.ExportOptions;
namespace AsbCloudApp.Services;
/// <summary>
/// Экспорт данных
/// </summary>
public interface IExportService<in TOptions>
where TOptions : IExportOptionsRequest
{
/// <summary>
/// Экспортировать данные
/// </summary>
/// <param name="options"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<(string FileName, Stream File)> ExportAsync(TOptions options, CancellationToken token);
}

View File

@ -9,7 +9,7 @@ namespace AsbCloudApp.Services;
/// </summary>
/// <typeparam name="TDto"></typeparam>
/// <typeparam name="TOptions"></typeparam>
public interface IParserService<TDto, in TOptions> : IParserService
public interface IParserService<TDto, in TOptions>
where TDto : class, IId
where TOptions : IParserOptionsRequest
{
@ -26,11 +26,4 @@ public interface IParserService<TDto, in TOptions> : IParserService
/// </summary>
/// <returns></returns>
Stream GetTemplateFile();
}
/// <summary>
/// Сервис парсинга(интерфейс маркер)
/// </summary>
public interface IParserService
{
}

View File

@ -154,13 +154,19 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks
var hasOscillation = EnabledSubsystemsFlags.AutoOscillation.HasEnabledSubsystems(operation.EnabledSubsystems);
var aggregatedValues = CalcAggregate(span);
var dateStart = span[0].DateTime;
var dateEnd = span[^1].DateTime;
var depthStart = span[0].WellDepth;
var depthEnd = span[^1].WellDepth;
var speed = ((depthEnd - depthStart) / (dateEnd - dateStart).TotalHours);
var processMapDrillingCacheItem = new DataSaubStatDto
{
DateStart = operation.DateStart,
DateEnd = operation.DateEnd,
DepthStart = operation.DepthStart,
DepthEnd = operation.DepthEnd,
Speed = (operation.DepthEnd - operation.DepthStart) / ((operation.DateEnd - operation.DateStart).TotalHours),
DateStart = dateStart,
DateEnd = dateEnd,
DepthStart = depthStart,
DepthEnd = depthEnd,
Speed = speed,
BlockSpeedSp = span[0].BlockSpeedSp,
Pressure = aggregatedValues.Pressure,
PressureIdle = span[0].PressureIdle,

View File

@ -45,6 +45,7 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
namespace AsbCloudInfrastructure
{
@ -161,9 +162,6 @@ namespace AsbCloudInfrastructure
services.AddScoped<IWellService, WellService>();
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
services.AddTransient<IProcessMapReportDrillingExportService, ProcessMapReportDataSaubStatExportService>();
services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>();
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
services.AddTransient<IDailyReportService, DailyReportService>();
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
@ -295,7 +293,14 @@ namespace AsbCloudInfrastructure
services.AddTransient<TrajectoryFactManualParser>();
services.AddTransient<ProcessMapPlanDrillingParser>();
services.AddTransient<ProcessMapPlanReamParser>();
services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>();
services.AddTransient<ProcessMapPlanDrillingExportService>();
services.AddTransient<ProcessMapPlanReamExportService>();
return services;
}
}

View File

@ -28,6 +28,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
.Include(e => e.Author)
.Include(e => e.Editor)
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
if (request.IdWellSectionType.HasValue)
@ -56,4 +57,11 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
var offset = TimeSpan.FromHours(timezone.Hours);
return offset;
}
protected override TDto Convert(TEntity entity, TimeSpan offset)
{
var dto = base.Convert(entity, offset);
dto.Section = entity.WellSectionType.Caption;
return dto;
}
}

View File

@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.IO;
using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.Parser;
namespace AsbCloudInfrastructure.Services.ExcelServices;
public class Cell
{

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using ClosedXML.Excel;
using Mapster;
namespace AsbCloudInfrastructure.Services.ExcelServices;
public abstract class ExportExcelService<TDto, TOptions> : IExportService<TOptions>
where TOptions : IExportOptionsRequest
{
protected abstract ITemplateParameters TemplateParameters { get; }
protected abstract Task<string> BuildFileNameAsync(TOptions options, CancellationToken token);
protected abstract Task<IEnumerable<TDto>> GetDtosAsync(TOptions options, CancellationToken token);
public async Task<(string FileName, Stream File)> ExportAsync(TOptions options, CancellationToken token)
{
var dtos = await GetDtosAsync(options, token);
var fileName = await BuildFileNameAsync(options, token);
var file = BuildFile(dtos);
return (fileName, file);
}
private Stream BuildFile(IEnumerable<TDto> dtos)
{
using var template = GetTemplateFile();
using var workbook = new XLWorkbook(template);
AddDtosToWorkbook(workbook, dtos);
var memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
private void AddDtosToWorkbook(XLWorkbook workbook, IEnumerable<TDto> dtos)
{
var dtosToArray = dtos.ToArray();
if (!dtosToArray.Any())
return;
var sheet = workbook.GetWorksheet(TemplateParameters.SheetName);
for (var i = 0; i < dtosToArray.Length; i++)
{
var row = sheet.Row(1 + i + TemplateParameters.HeaderRowsCount);
AddRow(row, dtosToArray[i]);
}
}
private void AddRow(IXLRow xlRow, TDto dto)
{
var properties = dto.Adapt<IDictionary<string, object>>();
foreach (var (name, cellValue) in properties)
{
if (TemplateParameters.Cells.TryGetValue(name, out var cell))
xlRow.Cell(cell.ColumnNumber).SetCellValue(cellValue);
}
}
private Stream GetTemplateFile() =>
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateParameters.FileName)
?? throw new ArgumentNullException($"Файл '{TemplateParameters.FileName}' не найден");
}

View File

@ -7,39 +7,34 @@ using System.Reflection;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using ClosedXML.Excel;
using Mapster;
namespace AsbCloudInfrastructure.Services.Parser;
namespace AsbCloudInfrastructure.Services.ExcelServices;
public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto, TOptions>
where TDto : class, IValidatableObject, IId
where TOptions : IParserOptionsRequest
{
protected abstract string SheetName { get; }
protected abstract ITemplateParameters TemplateParameters { get; }
protected virtual int HeaderRowsCount => 0;
protected abstract string TemplateFileName { get; }
protected abstract IDictionary<string, Cell> Cells { get; }
public virtual ParserResultDto<TDto> Parse(Stream file, TOptions options)
{
using var workbook = new XLWorkbook(file);
var sheet = workbook.GetWorksheet(SheetName);
var sheet = workbook.GetWorksheet(TemplateParameters.SheetName);
var dtos = ParseExcelSheet(sheet);
return dtos;
}
public virtual Stream GetTemplateFile() =>
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateFileName)
?? throw new ArgumentNullException($"Файл '{TemplateFileName}' не найден");
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateParameters.FileName)
?? throw new ArgumentNullException($"Файл '{TemplateParameters.FileName}' не найден");
protected virtual IDictionary<string, object?> ParseRow(IXLRow xlRow)
{
var cells = Cells.ToDictionary(x => x.Key, x =>
var cells = TemplateParameters.Cells.ToDictionary(x => x.Key, x =>
{
var columnNumber = x.Value.ColumnNumber;
var xlCell = xlRow.Cell(columnNumber);
@ -72,7 +67,7 @@ public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto,
return validDto;
}
var columnsDict = Cells.ToDictionary(x => x.Key, x => x.Value.ColumnNumber);
var columnsDict = TemplateParameters.Cells.ToDictionary(x => x.Key, x => x.Value.ColumnNumber);
var invalidDto = new ValidationResultDto<TDto>
{
@ -84,7 +79,10 @@ public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto,
{
var columnNumber = columnsDict[m];
var errorMessage = v.ErrorMessage;
var warningMessage = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, rowNumber, columnNumber,
var warningMessage = string.Format(XLExtentions.ProblemDetailsTemplate,
TemplateParameters.SheetName,
rowNumber,
columnNumber,
errorMessage);
var warning = new ValidationResult(warningMessage, new[] { m });
return warning;
@ -96,7 +94,7 @@ public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto,
protected virtual ParserResultDto<TDto> ParseExcelSheet(IXLWorksheet sheet)
{
var count = sheet.RowsUsed().Count() - HeaderRowsCount;
var count = sheet.RowsUsed().Count() - TemplateParameters.HeaderRowsCount;
if (count <= 0)
return new ParserResultDto<TDto>();
@ -105,7 +103,7 @@ public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto,
for (var i = 0; i < count; i++)
{
var xlRow = sheet.Row(1 + i + HeaderRowsCount);
var xlRow = sheet.Row(1 + i + TemplateParameters.HeaderRowsCount);
var rowNumber = xlRow.RowNumber();
try

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates;
public interface ITemplateParameters
{
string SheetName { get; }
int HeaderRowsCount { get; }
string FileName { get; }
IDictionary<string, Cell> Cells { get; }
}

View File

@ -0,0 +1,35 @@
using System.Collections.Generic;
using AsbCloudApp.Data.ProcessMaps;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
public class ProcessMapPlanDrillingTemplate : ITemplateParameters
{
public string SheetName => "План";
public int HeaderRowsCount => 2;
public string FileName => "ProcessMapPlanDrillingTemplate.xlsx";
public IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(ProcessMapPlanDrillingDto.Section), new Cell(1, typeof(string)) },
{ nameof(ProcessMapPlanDrillingDto.Mode), new Cell(2, typeof(string)) },
{ nameof(ProcessMapPlanDrillingDto.DepthStart), new Cell(3, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DepthEnd), new Cell(4, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressurePlan), new Cell(5, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressureLimitMax), new Cell(6, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadPlan), new Cell(7, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadLimitMax), new Cell(8, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorquePlan), new Cell(9, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorqueLimitMax), new Cell(10, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedPlan), new Cell(11, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedLimitMax), new Cell(12, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.FlowPlan), new Cell(13, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.FlowLimitMax), new Cell(14, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.RopPlan), new Cell(15, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.UsageSaub), new Cell(16, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.UsageSpin), new Cell(17, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.Comment), new Cell(18, typeof(string)) }
};
}

View File

@ -0,0 +1,29 @@
using System.Collections.Generic;
using AsbCloudApp.Data.ProcessMaps;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
public class ProcessMapPlanReamTemplate : ITemplateParameters
{
public string SheetName => "План";
public int HeaderRowsCount => 1;
public string FileName => "ProcessMapPlanReamTemplate.xlsx";
public IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(ProcessMapPlanReamDto.Section), new Cell(1, typeof(string)) },
{ nameof(ProcessMapPlanReamDto.DepthStart), new Cell(2, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.DepthEnd), new Cell(3, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Repeats), new Cell(4, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpinUpward), new Cell(5, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpinDownward), new Cell(6, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpeedUpward), new Cell(7, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpeedDownward), new Cell(8, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SetpointDrag), new Cell(9, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SetpointTight), new Cell(10, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Pressure), new Cell(11, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Torque), new Cell(12, typeof(double)) },
};
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
public class TrajectoryFactManualTemplate : ITemplateParameters
{
public string SheetName => "Фактическая траектория";
public int HeaderRowsCount => 2;
public string FileName => "TrajectoryFactManualTemplate.xlsx";
public IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(TrajectoryGeoFactDto.WellboreDepth), new Cell(1, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.ZenithAngle), new Cell(2, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthGeo), new Cell(3, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthMagnetic), new Cell(4, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.VerticalDepth), new Cell(5, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.Comment), new Cell(6, typeof(string)) }
};
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
public class TrajectoryFactNnbTemplate : ITemplateParameters
{
public string SheetName => "Фактическая ннб-траектория";
public int HeaderRowsCount => 2;
public string FileName => "TrajectoryFactNnbTemplate.xlsx";
public IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(TrajectoryGeoFactDto.WellboreDepth), new Cell(1, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.ZenithAngle), new Cell(2, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthGeo), new Cell(3, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthMagnetic), new Cell(4, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.VerticalDepth), new Cell(5, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.Comment), new Cell(6, typeof(string)) }
};
}

View File

@ -0,0 +1,21 @@
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
namespace AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
public class TrajectoryPlanTemplate : ITemplateParameters
{
public string SheetName => "Плановая траектория";
public int HeaderRowsCount => 2;
public string FileName => "TrajectoryPlanTemplate.xlsx";
public IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(TrajectoryGeoPlanDto.WellboreDepth), new Cell(1, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.ZenithAngle), new Cell(2, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.AzimuthGeo), new Cell(3, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.AzimuthMagnetic), new Cell(4, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.VerticalDepth), new Cell(5, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.Radius), new Cell(6, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.Comment), new Cell(7, typeof(string)) }
};
}

View File

@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanDrillingExportService : ProcessMapPlanExportService<ProcessMapPlanDrillingDto>
{
public ProcessMapPlanDrillingExportService(
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{
}
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanDrillingTemplate();
protected override async Task<string> BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
return $"{caption}_РТК_План_бурение.xlsx";
}
protected override async Task<IEnumerable<ProcessMapPlanDrillingDto>> GetDtosAsync(WellRelatedExportRequest options,
CancellationToken token)
{
var dtos = await base.GetDtosAsync(options, token);
var dtosWithMode = dtos.Select(dto =>
{
dto.Mode = dto.IdMode switch
{
1 => "Ротор",
2 => "Слайд",
_ => throw new ArgumentOutOfRangeException()
};
return dto;
});
return dtosWithMode;
}
}

View File

@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDto, WellRelatedExportRequest>
where TDto : ChangeLogAbstract
{
protected readonly IWellService wellService;
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository;
protected ProcessMapPlanExportService(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
{
this.processMapPlanRepository = processMapPlanRepository;
this.wellService = wellService;
}
protected override async Task<IEnumerable<TDto>> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token)
{
var request = new ProcessMapPlanBaseRequestWithWell(options.IdWell);
var dtos = await processMapPlanRepository.Get(request, token);
return dtos;
}
}

View File

@ -0,0 +1,30 @@
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReamDto>
{
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
public ProcessMapPlanReamExportService(
IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{
}
protected override async Task<string> BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
return $"{caption}_РТК_План_проработка.xlsx";
}
}

View File

@ -2,49 +2,21 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public class ProcessMapPlanDrillingParser : ProcessMapPlanParser<ProcessMapPlanDrillingDto>
{
private readonly IEnumerable<WellSectionTypeDto> sections;
public ProcessMapPlanDrillingParser(IWellOperationRepository wellOperationRepository)
: base(wellOperationRepository)
{
sections = wellOperationRepository.GetSectionTypes();
}
protected override string SheetName => "План";
protected override string TemplateFileName => "ProcessMapPlanDrillingTemplate.xlsx";
private const int ColumnSection = 1;
private const int ColumnMode = 2;
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(ProcessMapPlanDrillingDto.Section), new Cell(ColumnSection, typeof(string)) },
{ nameof(ProcessMapPlanDrillingDto.Mode), new Cell(ColumnMode, typeof(string)) },
{ nameof(ProcessMapPlanDrillingDto.DepthStart), new Cell(3, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DepthEnd), new Cell(4, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressurePlan), new Cell(5, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressureLimitMax), new Cell(6, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadPlan), new Cell(7, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadLimitMax), new Cell(8, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorquePlan), new Cell(9, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorqueLimitMax), new Cell(10, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedPlan), new Cell(11, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedLimitMax), new Cell(12, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.FlowPlan), new Cell(13, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.FlowLimitMax), new Cell(14, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.RopPlan), new Cell(15, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.UsageSaub), new Cell(16, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.UsageSpin), new Cell(17, typeof(double)) },
{ nameof(ProcessMapPlanDrillingDto.Comment), new Cell(18, typeof(string)) }
};
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanDrillingTemplate();
protected override ProcessMapPlanDrillingDto BuildDto(IDictionary<string, object?> row, int rowNumber)
{
@ -55,7 +27,10 @@ public class ProcessMapPlanDrillingParser : ProcessMapPlanParser<ProcessMapPlanD
if (section is null)
{
var message = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, rowNumber, ColumnSection,
var message = string.Format(XLExtentions.ProblemDetailsTemplate,
TemplateParameters.SheetName,
rowNumber,
TemplateParameters.Cells[nameof(ProcessMapPlanDrillingDto.Section)],
"Указана некорректная секция");
throw new FileFormatException(message);
}
@ -64,7 +39,10 @@ public class ProcessMapPlanDrillingParser : ProcessMapPlanParser<ProcessMapPlanD
if (idMode is null)
{
var message = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, rowNumber, ColumnSection,
var message = string.Format(XLExtentions.ProblemDetailsTemplate,
TemplateParameters.SheetName,
rowNumber,
TemplateParameters.Cells[nameof(ProcessMapPlanDrillingDto.Mode)],
"Указан некорректный режим бурения");
throw new FileFormatException(message);
}

View File

@ -1,16 +1,23 @@
using System.Collections.Generic;
using System.IO;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public abstract class ProcessMapPlanParser<TDto> : ParserExcelService<TDto, WellRelatedParserRequest>
where TDto : ProcessMapPlanBaseDto
{
protected override int HeaderRowsCount => 2;
protected readonly IEnumerable<WellSectionTypeDto> sections;
protected ProcessMapPlanParser(IWellOperationRepository wellOperationRepository)
{
sections = wellOperationRepository.GetSectionTypes();
}
public override ParserResultDto<TDto> Parse(Stream file, WellRelatedParserRequest options)
{
var result = base.Parse(file, options);

View File

@ -2,42 +2,21 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public class ProcessMapPlanReamParser : ProcessMapPlanParser<ProcessMapPlanReamDto>
{
private readonly IEnumerable<WellSectionTypeDto> sections;
public ProcessMapPlanReamParser(IWellOperationRepository wellOperationRepository)
: base(wellOperationRepository)
{
sections = wellOperationRepository.GetSectionTypes();
}
protected override string SheetName => "План";
protected override string TemplateFileName => "ProcessMapPlanReamTemplate.xlsx";
private const int ColumnSection = 1;
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(ProcessMapPlanReamDto.Section), new Cell(ColumnSection, typeof(string)) },
{ nameof(ProcessMapPlanReamDto.DepthStart), new Cell(2, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.DepthEnd), new Cell(3, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Repeats), new Cell(4, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpinUpward), new Cell(5, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpinUpward), new Cell(6, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpeedDownward), new Cell(7, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SpeedUpward), new Cell(8, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SetpointDrag), new Cell(9, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.SetpointTight), new Cell(10, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Pressure), new Cell(11, typeof(double)) },
{ nameof(ProcessMapPlanReamDto.Torque), new Cell(12, typeof(double)) },
};
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
protected override ProcessMapPlanReamDto BuildDto(IDictionary<string, object?> row, int rowNumber)
{
@ -48,7 +27,9 @@ public class ProcessMapPlanReamParser : ProcessMapPlanParser<ProcessMapPlanReamD
if (section is null)
{
var message = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, rowNumber, ColumnSection,
var message = string.Format(XLExtentions.ProblemDetailsTemplate,
TemplateParameters.SheetName, rowNumber,
TemplateParameters.Cells[nameof(ProcessMapPlanReamDto.Section)],
"Указана некорректная секция");
throw new FileFormatException(message);
}

View File

@ -1,83 +1,27 @@
using AsbCloudApp.Data.Trajectory;
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public abstract class TrajectoryExportService<TDto> : ExportExcelService<TDto, WellRelatedExportRequest>
where TDto : TrajectoryGeoDto
{
public abstract class TrajectoryExportService<T> where T : TrajectoryGeoDto
{
private readonly IWellService wellService;
protected readonly IWellService wellService;
private readonly ITrajectoryRepository<T> trajectoryRepository;
public abstract string templateFileName { get; }
public abstract string usingTemplateFile { get; }
public abstract string sheetName { get; }
public abstract int headerRowsCount { get; }
private readonly ITrajectoryRepository<TDto> trajectoryRepository;
public TrajectoryExportService(IWellService wellService, ITrajectoryRepository<T> trajectoryRepository)
{
this.wellService = wellService;
this.trajectoryRepository = trajectoryRepository;
}
protected TrajectoryExportService(IWellService wellService, ITrajectoryRepository<TDto> trajectoryRepository)
{
this.wellService = wellService;
this.trajectoryRepository = trajectoryRepository;
}
protected abstract void AddCoordinatesToRow(IXLRow row, T trajectory);
public async Task<Stream> ExportAsync(int idWell, CancellationToken token)
{
var trajectorys = await trajectoryRepository.GetAsync(idWell, token);
return MakeExelFileStream(trajectorys);
}
public async Task<string> GetFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return string.Format("{0}_{1}", caption, templateFileName);
}
public Stream GetTemplateFile()
{
var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"{usingTemplateFile}.{templateFileName}");
if (stream is null)
throw new Exception($"Область {usingTemplateFile} не содержит файла с названием {templateFileName}");
return stream;
}
private Stream MakeExelFileStream(IEnumerable<T> trajectories)
{
using Stream ecxelTemplateStream = GetTemplateFile();
using var workbook = new XLWorkbook(ecxelTemplateStream);
AddTrajecoryToWorkbook(workbook, trajectories);
MemoryStream memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
private void AddTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<T> trajectories)
{
if (trajectories.Any())
{
var sheet = workbook.GetWorksheet(sheetName);
AddTrajecoryToSheet(sheet, trajectories);
}
}
private void AddTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<T> trajectories)
{
var rowList = trajectories.ToList();
for (int i = 0; i < rowList.Count; i++)
{
var row = sheet.Row(1 + i + headerRowsCount);
AddCoordinatesToRow(row, rowList[i]);
}
}
}
}
protected override Task<IEnumerable<TDto>> GetDtosAsync(WellRelatedExportRequest options, CancellationToken token) =>
trajectoryRepository.GetAsync(options.IdWell, token);
}

View File

@ -1,35 +1,28 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryFactManualExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public TrajectoryFactManualExportService(IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public class TrajectoryFactManualExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Фактическая траектория";
public override int headerRowsCount { get; } = 2;
public TrajectoryFactManualExportService(
IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoFactDto> factTrajectoryService)
: base(wellService, factTrajectoryService)
{
}
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Comment);
}
}
}
protected override ITemplateParameters TemplateParameters => new TrajectoryFactManualTemplate();
protected override async Task<string> BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
return $"{caption}_Фактическая_траектория.xlsx";
}
}

View File

@ -1,35 +1,28 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryFactNnbExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public TrajectoryFactNnbExportService(IWellService wellService,
ITrajectoryNnbRepository trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public class TrajectoryFactNnbExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public override string templateFileName { get; } = "TrajectoryFactNnbTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Фактическая ннб-траектория";
public override int headerRowsCount { get; } = 2;
protected override ITemplateParameters TemplateParameters => new TrajectoryFactNnbTemplate();
public TrajectoryFactNnbExportService(
IWellService wellService,
ITrajectoryNnbRepository nnbTrajectoryService)
: base(wellService, nnbTrajectoryService)
{
}
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Comment);
}
}
}
protected override async Task<string> BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
return $"{caption}_Траектория_ННБ.xlsx";
}
}

View File

@ -1,38 +1,28 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryPlanExportService : TrajectoryExportService<TrajectoryGeoPlanDto>
{
public class TrajectoryPlanExportService : TrajectoryExportService<TrajectoryGeoPlanDto>
{
/*
* password for PlannedTrajectoryTemplate.xlsx is Drill2022
*/
public override string templateFileName { get; } = "TrajectoryPlanTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Плановая траектория";
public override int headerRowsCount { get; } = 2;
public TrajectoryPlanExportService(IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public TrajectoryPlanExportService(
IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryPlanService)
: base(wellService, trajectoryPlanService)
{
}
protected override ITemplateParameters TemplateParameters => new TrajectoryPlanTemplate();
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoPlanDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Radius);
row.Cell(7).SetCellValue(trajectory.Comment);
}
}
}
protected override async Task<string> BuildFileNameAsync(WellRelatedExportRequest options, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(options.IdWell, token);
return $"{caption}_Плановая_Траектория.xlsx";
}
}

View File

@ -1,22 +1,10 @@
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.Trajectory;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
public class TrajectoryFactManualParser : TrajectoryParser<TrajectoryGeoFactDto>
{
protected override string SheetName => "Фактическая траектория";
protected override string TemplateFileName => "TrajectoryFactManualTemplate.xlsx";
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(TrajectoryGeoFactDto.WellboreDepth), new Cell(1, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.ZenithAngle), new Cell(2, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthGeo), new Cell(3, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.AzimuthMagnetic), new Cell(4, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.VerticalDepth), new Cell(5, typeof(double)) },
{ nameof(TrajectoryGeoFactDto.Comment), new Cell(6, typeof(string)) }
};
protected override ITemplateParameters TemplateParameters => new TrajectoryFactManualTemplate();
}

View File

@ -2,15 +2,13 @@ using System.IO;
using AsbCloudApp.Data;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
public abstract class TrajectoryParser<TDto> : ParserExcelService<TDto, WellRelatedParserRequest>
where TDto : TrajectoryGeoDto
{
protected override int HeaderRowsCount => 2;
public override ParserResultDto<TDto> Parse(Stream file, WellRelatedParserRequest options)
{
var result = base.Parse(file, options);

View File

@ -1,23 +1,10 @@
using System.Collections.Generic;
using AsbCloudApp.Data.Trajectory;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.Trajectory;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
public class TrajectoryPlanParser : TrajectoryParser<TrajectoryGeoPlanDto>
{
protected override string SheetName => "Плановая траектория";
protected override string TemplateFileName => "TrajectoryPlanTemplate.xlsx";
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(TrajectoryGeoPlanDto.WellboreDepth), new Cell(1, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.ZenithAngle), new Cell(2, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.AzimuthGeo), new Cell(3, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.AzimuthMagnetic), new Cell(4, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.VerticalDepth), new Cell(5, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.Radius), new Cell(6, typeof(double)) },
{ nameof(TrajectoryGeoPlanDto.Comment), new Cell(7, typeof(string)) }
};
protected override ITemplateParameters TemplateParameters => new TrajectoryPlanTemplate();
}

View File

@ -31,7 +31,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
DepthEnd = 1.5,
IdMode = 1,
Mode = "Ротор",
AxialLoadPlan = 2.718281,
AxialLoadLimitMax = 3.1415926,
DeltaPressurePlan = 4,
@ -117,7 +116,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
nameof(ProcessMapPlanDrillingDto.IdState),
nameof(ProcessMapPlanDrillingDto.Author),
nameof(ProcessMapPlanDrillingDto.Creation),
nameof(ProcessMapPlanDrillingDto.Mode),
nameof(ProcessMapPlanDrillingDto.Section)
};
MatchHelper.Match(expected, actual, excludeProps);

View File

@ -6,12 +6,15 @@ using NSubstitute;
using System;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests.ExportOptions;
using Xunit;
namespace AsbCloudWebApi.Tests.Services.Trajectory
{
public class TrajectoryExportTest
{
private const int idWell = 4;
private IWellService wellService;
private readonly ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryPlanRepository;
private readonly TrajectoryPlanExportService trajectoryPlanExportService;
@ -22,8 +25,6 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
private readonly ITrajectoryNnbRepository trajectoryFactNnbRepository;
private readonly TrajectoryFactNnbExportService trajectoryFactNnbExportService;
private readonly int idWell = 4;
private readonly TrajectoryGeoPlanDto[] trajectoryPlanRows = new TrajectoryGeoPlanDto[2] {
new TrajectoryGeoPlanDto() {
Id = 1,
@ -80,6 +81,8 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
},
};
private readonly WellRelatedExportRequest exportOptions = new(idWell);
public TrajectoryExportTest()
{
wellService = Substitute.For<IWellService>();
@ -98,10 +101,9 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
{
trajectoryPlanRepository.GetAsync(idWell, CancellationToken.None)
.Returns(trajectoryPlanRows);
var stream = await trajectoryPlanExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
var stream = await trajectoryPlanExportService.ExportAsync(exportOptions, CancellationToken.None);
Assert.True(stream.File.Length > 0);
}
[Fact]
@ -109,9 +111,9 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
{
trajectoryFactManualReposirory.GetAsync(idWell, CancellationToken.None)
.Returns(trajectoryFactRows);
var stream = await trajectoryFactManualExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
var stream = await trajectoryFactManualExportService.ExportAsync(exportOptions, CancellationToken.None);
Assert.True(stream.File.Length > 0);
}
[Fact]
@ -119,9 +121,9 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
{
trajectoryFactNnbRepository.GetAsync(idWell, CancellationToken.None)
.Returns(trajectoryFactRows);
var stream = await trajectoryFactNnbExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
var stream = await trajectoryFactNnbExportService.ExportAsync(exportOptions, CancellationToken.None);
Assert.True(stream.File.Length > 0);
}
}
}

View File

@ -1,7 +1,6 @@
using System.Linq;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.Trajectory.Parser;
using Xunit;

View File

@ -13,9 +13,9 @@ using AsbCloudApp.Services;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.ProcessMaps;
using System.ComponentModel.DataAnnotations;
using AsbCloudApp.Requests.ExportOptions;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -30,15 +30,18 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
{
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository;
private readonly IWellService wellService;
private readonly ParserExcelService<TDto, WellRelatedParserRequest> parserService;
private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
private readonly IExportService<WellRelatedExportRequest> processMapPlanExportService;
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ParserExcelService<TDto, WellRelatedParserRequest> parserService)
IParserService<TDto, WellRelatedParserRequest> parserService,
IExportService<WellRelatedExportRequest> processMapPlanExportService)
{
this.repository = repository;
this.wellService = wellService;
this.parserService = parserService;
this.processMapPlanExportService = processMapPlanExportService;
}
protected abstract string TemplateFileName { get; }
@ -266,6 +269,22 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
throw new ForbidException("Нет доступа к скважине");
return idUser;
}
/// <summary>
/// Формируем excel файл с текущими строками РТК
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"></param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet("export")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{
var exportOptions = new WellRelatedExportRequest(idWell);
var (fileName, file) = await processMapPlanExportService.ExportAsync(exportOptions, token);
return File(file, "application/octet-stream", fileName);
}
/// <summary>
/// returns user id or throw

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -13,8 +14,9 @@ public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController<Pro
{
public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanDrillingParser parserService)
: base(repository, wellService, parserService)
ProcessMapPlanDrillingParser parserService,
ProcessMapPlanDrillingExportService processMapPlanExportService)
: base(repository, wellService, parserService, processMapPlanExportService)
{
}

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -13,8 +14,9 @@ public class ProcessMapPlanReamController : ProcessMapPlanBaseController<Process
{
public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanReamParser parserService)
: base(repository, wellService, parserService)
ProcessMapPlanReamParser parserService,
ProcessMapPlanReamExportService processMapPlanExportService)
: base(repository, wellService, parserService, processMapPlanExportService)
{
}

View File

@ -1,14 +1,14 @@
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Export;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Requests.ExportOptions;
using AsbCloudInfrastructure.Services.Trajectory.Export;
namespace AsbCloudWebApi.Controllers.Trajectory
{
@ -21,13 +21,13 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public abstract class TrajectoryController<TDto> : ControllerBase
where TDto : TrajectoryGeoDto
{
protected abstract string fileName { get; }
protected abstract string TemplateFileName { get; }
private readonly IWellService wellService;
private readonly TrajectoryExportService<TDto> trajectoryExportService;
private readonly ITrajectoryRepository<TDto> trajectoryRepository;
public TrajectoryController(IWellService wellService,
protected TrajectoryController(IWellService wellService,
TrajectoryExportService<TDto> trajectoryExportService,
ITrajectoryRepository<TDto> trajectoryRepository)
{
@ -50,9 +50,10 @@ namespace AsbCloudWebApi.Controllers.Trajectory
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var stream = await trajectoryExportService.ExportAsync(idWell, token);
var fileName = await trajectoryExportService.GetFileNameAsync(idWell, token);
return File(stream, "application/octet-stream", fileName);
var exportOptions = new WellRelatedExportRequest(idWell);
var (fileName, file) = await trajectoryExportService.ExportAsync(exportOptions, token);
return File(file, "application/octet-stream", fileName);
}
/// <summary>

View File

@ -1,8 +1,6 @@
using System;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Export;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -12,8 +10,7 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.Trajectory.Parser;
using AsbCloudInfrastructure.Services.Trajectory.Export;
namespace AsbCloudWebApi.Controllers.Trajectory
{
@ -26,11 +23,11 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public abstract class TrajectoryEditableController<TDto> : TrajectoryController<TDto>
where TDto : TrajectoryGeoDto
{
private readonly TrajectoryParser<TDto> parserService;
private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
private readonly ITrajectoryEditableRepository<TDto> trajectoryRepository;
protected TrajectoryEditableController(IWellService wellService,
TrajectoryParser<TDto> parserService,
IParserService<TDto, WellRelatedParserRequest> parserService,
TrajectoryExportService<TDto> trajectoryExportService,
ITrajectoryEditableRepository<TDto> trajectoryRepository)
: base(wellService, trajectoryExportService, trajectoryRepository)
@ -50,7 +47,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public IActionResult GetTemplate()
{
var stream = parserService.GetTemplateFile();
return File(stream, "application/octet-stream", fileName);
return File(stream, "application/octet-stream", TemplateFileName);
}
/// <summary>

View File

@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactManualController : TrajectoryEditableController<TrajectoryGeoFactDto>
{
protected override string fileName => "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
public TrajectoryFactManualController(IWellService wellService,
TrajectoryFactManualExportService trajectoryExportService,

View File

@ -15,7 +15,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFactDto>
{
protected override string fileName => "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
public TrajectoryFactNnbController(
ITrajectoryNnbRepository trajectoryNnbRepository,
TrajectoryFactNnbExportService trajectoryExportService,

View File

@ -20,7 +20,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
{
private readonly TrajectoryService trajectoryVisualizationService;
protected override string fileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
public TrajectoryPlanController(IWellService wellService,
TrajectoryPlanParser parserService,

View File

@ -7,10 +7,7 @@ using System.IO;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc;