using System; using System.Collections.Generic; using System.IO; using System.Linq; using AsbCloudApp.Data; using AsbCloudApp.Data.ProcessMapPlan; using AsbCloudApp.Repositories; using ClosedXML.Excel; using Microsoft.Extensions.DependencyInjection; namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser; public class ProcessMapPlanDrillingParser : ProcessMapPlanParser { #region Columns private const int columnSection = 1; private const int columnMode = 2; private const int columnDepthStart = 3; private const int columnDepthEnd = 4; private const int columnPressurePlan = 5; private const int columnPressureLimitMax = 6; private const int columnAxialLoadPlan = 7; private const int columnAxialLoadLimitMax = 8; private const int columnTopDriveTorquePlan = 9; private const int columnTopDriveTorqueLimitMax = 10; private const int columnTopDriveSpeedPlan = 11; private const int columnTopDriveSpeedLimitMax = 12; private const int columnFlowPlan = 13; private const int columnFlowLimitMax = 14; private const int columnRopPlan = 15; private const int columnUsageSaub = 16; private const int columnUsageSpin = 17; private const int columnComment = 18; #endregion private readonly IEnumerable sections; public ProcessMapPlanDrillingParser(IServiceProvider serviceProvider) : base(serviceProvider) { var wellOperationRepository = serviceProvider.GetRequiredService(); sections = wellOperationRepository.GetSectionTypes(); } protected override string SheetName => "План"; protected override IDictionary PropertyColumnNumbers => new Dictionary { { nameof(ProcessMapPlanDrillingDto.DepthStart), columnDepthStart }, { nameof(ProcessMapPlanDrillingDto.DepthEnd), columnDepthEnd }, { nameof(ProcessMapPlanDrillingDto.DeltaPressurePlan), columnPressurePlan }, { nameof(ProcessMapPlanDrillingDto.DeltaPressureLimitMax), columnPressureLimitMax }, { nameof(ProcessMapPlanDrillingDto.AxialLoadPlan), columnAxialLoadPlan }, { nameof(ProcessMapPlanDrillingDto.AxialLoadLimitMax), columnAxialLoadLimitMax }, { nameof(ProcessMapPlanDrillingDto.TopDriveTorquePlan), columnTopDriveTorquePlan }, { nameof(ProcessMapPlanDrillingDto.TopDriveTorqueLimitMax), columnTopDriveTorqueLimitMax }, { nameof(ProcessMapPlanDrillingDto.TopDriveSpeedPlan), columnTopDriveSpeedPlan }, { nameof(ProcessMapPlanDrillingDto.TopDriveSpeedLimitMax), columnTopDriveSpeedLimitMax }, { nameof(ProcessMapPlanDrillingDto.FlowPlan), columnFlowPlan }, { nameof(ProcessMapPlanDrillingDto.FlowLimitMax), columnFlowLimitMax }, { nameof(ProcessMapPlanDrillingDto.RopPlan), columnRopPlan }, { nameof(ProcessMapPlanDrillingDto.UsageSaub), columnUsageSaub }, { nameof(ProcessMapPlanDrillingDto.UsageSpin), columnUsageSpin }, { nameof(ProcessMapPlanDrillingDto.Comment), columnComment } }; protected override string TemplateFileName => "ProcessMapPlanDrillingTemplate.xlsx"; protected override ProcessMapPlanDrillingDto ParseRow(IXLRow row) { var sectionCaption = row.Cell(columnSection).GetCellValue()?.Trim().ToLower(); var modeName = row.Cell(columnMode).GetCellValue()?.Trim().ToLower(); var section = sections.FirstOrDefault(s => string.Equals(s.Caption.Trim(), sectionCaption?.Trim(), StringComparison.CurrentCultureIgnoreCase)); if (section is null) { var message = string.Format(XLMessageTemplates.ProblemDetailsTemplate, SheetName, row.RowNumber(), columnSection, "Указана некорректная секция"); throw new FileFormatException(message); } var idMode = GetIdMode(modeName); if (idMode is null) { var message = string.Format(XLMessageTemplates.ProblemDetailsTemplate, SheetName, row.RowNumber(), columnSection, "Указан некорректный режим бурения"); throw new FileFormatException(message); } var dto = new ProcessMapPlanDrillingDto { IdWellSectionType = section.Id, Section = section.Caption, IdMode = idMode.Value, Mode = modeName, DepthStart = row.Cell(columnDepthStart).GetCellValue(), DepthEnd = row.Cell(columnDepthEnd).GetCellValue(), AxialLoadPlan = row.Cell(columnAxialLoadPlan).GetCellValue(), AxialLoadLimitMax = row.Cell(columnAxialLoadLimitMax).GetCellValue(), DeltaPressurePlan = row.Cell(columnPressurePlan).GetCellValue(), DeltaPressureLimitMax = row.Cell(columnPressureLimitMax).GetCellValue(), TopDriveTorquePlan = row.Cell(columnTopDriveTorquePlan).GetCellValue(), TopDriveTorqueLimitMax = row.Cell(columnTopDriveTorqueLimitMax).GetCellValue(), TopDriveSpeedPlan = row.Cell(columnTopDriveSpeedPlan).GetCellValue(), TopDriveSpeedLimitMax = row.Cell(columnTopDriveSpeedLimitMax).GetCellValue(), FlowPlan = row.Cell(columnFlowPlan).GetCellValue(), FlowLimitMax = row.Cell(columnFlowLimitMax).GetCellValue(), RopPlan = row.Cell(columnRopPlan).GetCellValue(), UsageSaub = row.Cell(columnUsageSaub).GetCellValue(), UsageSpin = row.Cell(columnUsageSpin).GetCellValue(), Comment = row.Cell(columnComment).GetCellValue() ?? string.Empty }; return dto; } }