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