forked from ddrilling/AsbCloudServer
48 lines
1.3 KiB
C#
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
|
|
};
|
|
} |