DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ProcessMapPlan/Parser/ProcessMapPlanParser.cs
Степанов Дмитрий f2ca89dc8d Парсинг РТК
2024-02-09 09:32:31 +03:00

48 lines
1.3 KiB
C#

using System;
using System.IO;
using System.Reflection;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Requests.ParserOptions;
using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public abstract class ProcessMapPlanParser<TDto> : ParserServiceBase<TDto, IParserOptionsRequest>
where TDto : ProcessMapPlanBaseDto
{
protected ProcessMapPlanParser(IServiceProvider serviceProvider)
: base(serviceProvider)
{
}
private const int HeaderRowsCount = 2;
private const int ColumnCount = 18;
protected abstract string TemplateFileName { get; }
protected abstract ValidationResultDto<TDto> ParseRow(IXLRow row);
public override ParserResultDto<TDto> Parse(Stream file, IParserOptionsRequest options)
{
using var workbook = new XLWorkbook(file);
var sheet = workbook.GetWorksheet(SheetName);
var processMaps = ParseExcelSheet(sheet, ParseRow, ColumnCount, HeaderRowsCount);
return processMaps;
}
public override Stream GetTemplateFile() =>
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateFileName)
?? throw new ArgumentNullException($"Файл '{TemplateFileName}' не найден");
protected static int? GetIdMode(string? modeName) =>
modeName?.Trim().ToLower() switch
{
"ручной" => 0,
"ротор" => 1,
"слайд" => 2,
_ => null
};
}