forked from ddrilling/AsbCloudServer
Merge branch 'dev' into feature/#27942032-well-composite-operations
This commit is contained in:
commit
7d1fdb7774
@ -0,0 +1,21 @@
|
||||
namespace AsbCloudApp.Requests.ParserOptions;
|
||||
|
||||
/// <summary>
|
||||
/// Параметры парсинга
|
||||
/// </summary>
|
||||
public class WellRelatedParserRequest : IParserOptionsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="idWell">Id скважины</param>
|
||||
public WellRelatedParserRequest(int idWell)
|
||||
{
|
||||
IdWell = idWell;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Id скважины
|
||||
/// </summary>
|
||||
public int IdWell { get; }
|
||||
}
|
@ -8,8 +8,10 @@ namespace AsbCloudApp.Services;
|
||||
/// Сервис парсинга
|
||||
/// </summary>
|
||||
/// <typeparam name="TDto"></typeparam>
|
||||
public interface IParserService<TDto> : IParserService
|
||||
/// <typeparam name="TOptions"></typeparam>
|
||||
public interface IParserService<TDto, in TOptions> : IParserService
|
||||
where TDto : class, IId
|
||||
where TOptions : IParserOptionsRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Распарсить файл
|
||||
@ -17,8 +19,7 @@ public interface IParserService<TDto> : IParserService
|
||||
/// <param name="file"></param>
|
||||
/// <param name="options"></param>
|
||||
/// <returns></returns>
|
||||
ParserResultDto<TDto> Parse<TOptions>(Stream file, TOptions options)
|
||||
where TOptions : IParserOptionsRequest;
|
||||
ParserResultDto<TDto> Parse(Stream file, TOptions options);
|
||||
|
||||
/// <summary>
|
||||
/// Получение шаблона для заполнения
|
||||
|
@ -12,8 +12,9 @@ using Mapster;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Parser;
|
||||
|
||||
public abstract class ParserExcelService<TDto> : IParserService<TDto>
|
||||
public abstract class ParserExcelService<TDto, TOptions> : IParserService<TDto, TOptions>
|
||||
where TDto : class, IValidatableObject, IId
|
||||
where TOptions : IParserOptionsRequest
|
||||
{
|
||||
protected abstract string SheetName { get; }
|
||||
|
||||
@ -22,9 +23,8 @@ public abstract class ParserExcelService<TDto> : IParserService<TDto>
|
||||
protected abstract string TemplateFileName { get; }
|
||||
|
||||
protected abstract IDictionary<string, Cell> Cells { get; }
|
||||
|
||||
public virtual ParserResultDto<TDto> Parse<TOptions>(Stream file, TOptions options)
|
||||
where TOptions : IParserOptionsRequest
|
||||
|
||||
public virtual ParserResultDto<TDto> Parse(Stream file, TOptions options)
|
||||
{
|
||||
using var workbook = new XLWorkbook(file);
|
||||
var sheet = workbook.GetWorksheet(SheetName);
|
||||
|
@ -6,7 +6,6 @@ using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudInfrastructure.Services.Parser;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
|
||||
|
||||
|
@ -1,14 +1,26 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMaps;
|
||||
using AsbCloudApp.Requests.ParserOptions;
|
||||
using AsbCloudInfrastructure.Services.Parser;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
|
||||
|
||||
public abstract class ProcessMapPlanParser<TDto> : ParserExcelService<TDto>
|
||||
public abstract class ProcessMapPlanParser<TDto> : ParserExcelService<TDto, WellRelatedParserRequest>
|
||||
where TDto : ProcessMapPlanBaseDto
|
||||
{
|
||||
protected override int HeaderRowsCount => 2;
|
||||
|
||||
public override ParserResultDto<TDto> Parse(Stream file, WellRelatedParserRequest options)
|
||||
{
|
||||
var result = base.Parse(file, options);
|
||||
|
||||
foreach (var item in result.Item)
|
||||
item.Item.IdWell = options.IdWell;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected static int? GetIdMode(string? modeName) =>
|
||||
modeName?.Trim().ToLower() switch
|
||||
{
|
||||
|
@ -22,14 +22,12 @@ public class ProcessMapPlanReamParser : ProcessMapPlanParser<ProcessMapPlanReamD
|
||||
protected override string TemplateFileName => "ProcessMapPlanReamTemplate.xlsx";
|
||||
|
||||
private const int ColumnSection = 1;
|
||||
private const int ColumnMode = 2;
|
||||
|
||||
|
||||
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)) },
|
||||
|
@ -4,12 +4,10 @@ using AsbCloudInfrastructure.Services.Parser;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
|
||||
|
||||
public class TrajectoryFactManualParser : ParserExcelService<TrajectoryGeoFactDto>
|
||||
public class TrajectoryFactManualParser : TrajectoryParser<TrajectoryGeoFactDto>
|
||||
{
|
||||
protected override string SheetName => "Фактическая траектория";
|
||||
|
||||
protected override int HeaderRowsCount => 2;
|
||||
|
||||
|
||||
protected override string TemplateFileName => "TrajectoryFactManualTemplate.xlsx";
|
||||
|
||||
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
|
||||
|
@ -0,0 +1,23 @@
|
||||
using System.IO;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.Trajectory;
|
||||
using AsbCloudApp.Requests.ParserOptions;
|
||||
using AsbCloudInfrastructure.Services.Parser;
|
||||
|
||||
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);
|
||||
|
||||
foreach (var item in result.Item)
|
||||
item.Item.IdWell = options.IdWell;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -4,12 +4,10 @@ using AsbCloudInfrastructure.Services.Parser;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services.Trajectory.Parser;
|
||||
|
||||
public class TrajectoryPlanParser : ParserExcelService<TrajectoryGeoPlanDto>
|
||||
public class TrajectoryPlanParser : TrajectoryParser<TrajectoryGeoPlanDto>
|
||||
{
|
||||
protected override string SheetName => "Плановая траектория";
|
||||
|
||||
protected override int HeaderRowsCount => 2;
|
||||
|
||||
|
||||
protected override string TemplateFileName => "TrajectoryPlanTemplate.xlsx";
|
||||
|
||||
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
|
||||
|
@ -35,5 +35,5 @@ public interface IProcessMapPlanDrillingClient
|
||||
|
||||
[Multipart]
|
||||
[Post(BaseRoute + "/parse")]
|
||||
Task<IApiResponse<ParserResultDto<ProcessMapPlanDrillingDto>>> Parse(int idWell, [AliasAs("files")] IEnumerable<StreamPart> streams);
|
||||
Task<IApiResponse<ParserResultDto<ProcessMapPlanDrillingDto>>> Parse(int idWell, [AliasAs("file")] StreamPart stream);
|
||||
}
|
||||
|
@ -571,10 +571,10 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
|
||||
//arrange
|
||||
const string fileName = "ProcessMapPlanDrillingValid.xlsx";
|
||||
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
|
||||
|
||||
//act
|
||||
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
||||
var response = await client.Parse(Defaults.Wells[0].Id, new[] { streamPart });
|
||||
|
||||
//act
|
||||
var response = await client.Parse(Defaults.Wells[0].Id, streamPart);
|
||||
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
@ -589,9 +589,8 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
|
||||
var dtoActual = row.Item;
|
||||
|
||||
Assert.True(row.IsValid);
|
||||
|
||||
var excludeProps = new[] { nameof(ProcessMapPlanDrillingDto.IdWell) };
|
||||
MatchHelper.Match(dto, dtoActual, excludeProps);
|
||||
|
||||
MatchHelper.Match(dto, dtoActual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -600,11 +599,12 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
|
||||
//arrange
|
||||
const string fileName = "ProcessMapPlanDrillingInvalid.xlsx";
|
||||
var stream = Assembly.GetExecutingAssembly().GetFileCopyStream(fileName);
|
||||
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
||||
|
||||
//act
|
||||
var streamPart = new StreamPart(stream, fileName, "application/octet-stream");
|
||||
var response = await client.Parse(Defaults.Wells[0].Id, new[] { streamPart });
|
||||
var response = await client.Parse(Defaults.Wells[0].Id, streamPart);
|
||||
|
||||
//assert
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
|
||||
var parserResult = response.Content;
|
||||
|
@ -11,9 +11,11 @@ public class TrajectoryParserTest
|
||||
{
|
||||
private const string UsingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates";
|
||||
|
||||
private readonly WellRelatedParserRequest options = new(1);
|
||||
|
||||
private readonly TrajectoryPlanParser trajectoryPlanParser = new();
|
||||
private readonly TrajectoryFactManualParser trajectoryFactManualParser = new();
|
||||
|
||||
|
||||
[Fact]
|
||||
public void Parse_trajectory_plan()
|
||||
{
|
||||
@ -22,8 +24,8 @@ public class TrajectoryParserTest
|
||||
|
||||
if (stream is null)
|
||||
Assert.Fail("Файла для импорта не существует");
|
||||
|
||||
var trajectoryRows = trajectoryPlanParser.Parse(stream, IParserOptionsRequest.Empty());
|
||||
|
||||
var trajectoryRows = trajectoryPlanParser.Parse(stream, options);
|
||||
|
||||
Assert.Equal(3, trajectoryRows.Item.Count());
|
||||
}
|
||||
@ -37,7 +39,7 @@ public class TrajectoryParserTest
|
||||
if (stream is null)
|
||||
Assert.Fail("Файла для импорта не существует");
|
||||
|
||||
var trajectoryRows = trajectoryFactManualParser.Parse(stream, IParserOptionsRequest.Empty());
|
||||
var trajectoryRows = trajectoryFactManualParser.Parse(stream, options);
|
||||
|
||||
Assert.Equal(4, trajectoryRows.Item.Count());
|
||||
}
|
||||
|
@ -30,11 +30,11 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
||||
{
|
||||
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository;
|
||||
private readonly IWellService wellService;
|
||||
private readonly ParserExcelService<TDto> parserService;
|
||||
private readonly ParserExcelService<TDto, WellRelatedParserRequest> parserService;
|
||||
|
||||
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository,
|
||||
IWellService wellService,
|
||||
ParserExcelService<TDto> parserService)
|
||||
ParserExcelService<TDto, WellRelatedParserRequest> parserService)
|
||||
{
|
||||
this.repository = repository;
|
||||
this.wellService = wellService;
|
||||
@ -213,7 +213,7 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
||||
public async Task<ActionResult<ParserResultDto<TDto>>> Parse(int idWell,
|
||||
[Required] IFormFile file,
|
||||
[Required] IFormFile file,
|
||||
CancellationToken token)
|
||||
{
|
||||
await AssertUserHasAccessToWell(idWell, token);
|
||||
@ -222,9 +222,8 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
|
||||
|
||||
try
|
||||
{
|
||||
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
||||
foreach (var item in dto.Item)
|
||||
item.Item.IdWell = idWell;
|
||||
var options = new WellRelatedParserRequest(idWell);
|
||||
var dto = parserService.Parse(stream, options);
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ using System.Threading.Tasks;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests.ParserOptions;
|
||||
using AsbCloudInfrastructure.Services.Parser;
|
||||
using AsbCloudInfrastructure.Services.Trajectory.Parser;
|
||||
|
||||
namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
{
|
||||
@ -25,11 +26,11 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
public abstract class TrajectoryEditableController<TDto> : TrajectoryController<TDto>
|
||||
where TDto : TrajectoryGeoDto
|
||||
{
|
||||
private readonly ParserExcelService<TDto> parserService;
|
||||
private readonly TrajectoryParser<TDto> parserService;
|
||||
private readonly ITrajectoryEditableRepository<TDto> trajectoryRepository;
|
||||
|
||||
protected TrajectoryEditableController(IWellService wellService,
|
||||
ParserExcelService<TDto> parserService,
|
||||
TrajectoryParser<TDto> parserService,
|
||||
TrajectoryExportService<TDto> trajectoryExportService,
|
||||
ITrajectoryEditableRepository<TDto> trajectoryRepository)
|
||||
: base(wellService, trajectoryExportService, trajectoryRepository)
|
||||
@ -78,7 +79,9 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
||||
|
||||
try
|
||||
{
|
||||
var dto = parserService.Parse(stream, IParserOptionsRequest.Empty());
|
||||
var options = new WellRelatedParserRequest(idWell);
|
||||
var dto = parserService.Parse(stream, options);
|
||||
|
||||
return Ok(dto);
|
||||
}
|
||||
catch (FileFormatException ex)
|
||||
|
Loading…
Reference in New Issue
Block a user