DD.WellWorkover.Cloud/AsbCloudInfrastructure/Services/ProcessMapPlan/Parser/ProcessMapPlanDrillingParser.cs

82 lines
3.5 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Repositories;
using AsbCloudInfrastructure.Services.Parser.Data;
using ClosedXML.Excel;
using Microsoft.Extensions.DependencyInjection;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public class ProcessMapPlanDrillingParser : ProcessMapPlanParser<ProcessMapPlanDrillingDto>
{
private readonly IEnumerable<WellSectionTypeDto> sections;
public ProcessMapPlanDrillingParser(IServiceProvider serviceProvider)
: base(serviceProvider)
{
var wellOperationRepository = serviceProvider.GetRequiredService<IWellOperationRepository>();
sections = wellOperationRepository.GetSectionTypes();
}
protected override string SheetName => "План";
protected override string TemplateFileName => "ProcessMapPlanDrillingTemplate.xlsx";
private const int ColumnSection = 1;
private const int ColumnMode = 2;
protected override IDictionary<string, Cell> Cells => new Dictionary<string, Cell>
{
{ nameof(ProcessMapPlanDrillingDto.Section), new Cell(ColumnSection, XLDataType.Text) },
{ nameof(ProcessMapPlanDrillingDto.Mode), new Cell(ColumnMode, XLDataType.Text) },
{ nameof(ProcessMapPlanDrillingDto.DepthStart), new Cell(3, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.DepthEnd), new Cell(4, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressurePlan), new Cell(5, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.DeltaPressureLimitMax), new Cell(6, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadPlan), new Cell(7, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.AxialLoadLimitMax), new Cell(8, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorquePlan), new Cell(9, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveTorqueLimitMax), new Cell(10, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedPlan), new Cell(11, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.TopDriveSpeedLimitMax), new Cell(12, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.FlowPlan), new Cell(13, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.FlowLimitMax), new Cell(14, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.RopPlan), new Cell(15, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.UsageSaub), new Cell(16, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.UsageSpin), new Cell(17, XLDataType.Number) },
{ nameof(ProcessMapPlanDrillingDto.Comment), new Cell(18, XLDataType.Text) }
};
protected override ProcessMapPlanDrillingDto BuildDto(Row row)
{
var dto = base.BuildDto(row);
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, row.Number, ColumnSection,
"Указана некорректная секция");
throw new FileFormatException(message);
}
var idMode = GetIdMode(dto.Mode);
if (idMode is null)
{
var message = string.Format(XLExtentions.ProblemDetailsTemplate, SheetName, row.Number, ColumnSection,
"Указан некорректный режим бурения");
throw new FileFormatException(message);
}
dto.IdWellSectionType = section.Id;
dto.IdMode = idMode.Value;
return dto;
}
}