using System; using System.Collections.Generic; using System.IO; using System.Linq; using AsbCloudApp.Data; using AsbCloudApp.Data.ProcessMaps; using AsbCloudApp.Repositories; using AsbCloudInfrastructure.Services.Parser; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; public class ProcessMapPlanReamParser : ProcessMapPlanParser { private readonly IEnumerable sections; public ProcessMapPlanReamParser(IWellOperationRepository wellOperationRepository) { sections = wellOperationRepository.GetSectionTypes(); } protected override string SheetName => "План"; protected override string TemplateFileName => "ProcessMapPlanReamTemplate.xlsx"; private const int ColumnSection = 1; protected override IDictionary Cells => new Dictionary { { 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)) }, { nameof(ProcessMapPlanReamDto.SpeedDownward), new Cell(7, typeof(double)) }, { nameof(ProcessMapPlanReamDto.SpeedUpward), new Cell(8, typeof(double)) }, { nameof(ProcessMapPlanReamDto.SetpointDrag), new Cell(9, typeof(double)) }, { nameof(ProcessMapPlanReamDto.SetpointTight), new Cell(10, typeof(double)) }, { nameof(ProcessMapPlanReamDto.Pressure), new Cell(11, typeof(double)) }, { nameof(ProcessMapPlanReamDto.Torque), new Cell(12, typeof(double)) }, }; protected override ProcessMapPlanReamDto BuildDto(IDictionary row, int rowNumber) { var dto = base.BuildDto(row, rowNumber); var section = sections.FirstOrDefault(s => string.Equals(s.Caption.Trim(), dto.Section?.Trim(), StringComparison.CurrentCultureIgnoreCase)); if (section is null) { var message = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, rowNumber, ColumnSection, "Указана некорректная секция"); throw new FileFormatException(message); } dto.IdWellSectionType = section.Id; return dto; } }