forked from ddrilling/AsbCloudServer
Рефакторинг парсеров
This commit is contained in:
parent
63638219a2
commit
17454f762c
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user