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

139 lines
5.8 KiB
C#
Raw Normal View History

2024-02-09 11:32:31 +05:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMapPlan;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using Microsoft.Extensions.DependencyInjection;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
public class ProcessMapPlanDrillingParser : ProcessMapPlanParser<ProcessMapPlanDrillingDto>
{
#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<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";
protected override ValidationResultDto<ProcessMapPlanDrillingDto> ParseRow(IXLRow row)
{
var sectionCaption = row.Cell(columnSection).GetCellValue<string>()?.Trim().ToLower();
var modeName = row.Cell(columnMode).GetCellValue<string>()?.Trim().ToLower();
var depthStart = row.Cell(columnDepthStart).GetCellValue<double>();
var depthEnd = row.Cell(columnDepthEnd).GetCellValue<double>();
var deltaPressurePlan = row.Cell(columnPressurePlan).GetCellValue<double>();
var deltaPressureLimitMax = row.Cell(columnPressureLimitMax).GetCellValue<double>();
var axialLoadPlan = row.Cell(columnAxialLoadPlan).GetCellValue<double>();
var axialLoadLimitMax = row.Cell(columnAxialLoadLimitMax).GetCellValue<double>();
var topDriveTorquePlan = row.Cell(columnTopDriveTorquePlan).GetCellValue<double>();
var topDriveTorqueLimitMax = row.Cell(columnTopDriveTorqueLimitMax).GetCellValue<double>();
var topDriveSpeedPlan = row.Cell(columnTopDriveSpeedPlan).GetCellValue<double>();
var topDriveSpeedLimitMax = row.Cell(columnTopDriveSpeedLimitMax).GetCellValue<double>();
var flowPlan = row.Cell(columnFlowPlan).GetCellValue<double>();
var flowLimitMax = row.Cell(columnFlowLimitMax).GetCellValue<double>();
var ropPlan = row.Cell(columnRopPlan).GetCellValue<double>();
var usageSaub = row.Cell(columnUsageSaub).GetCellValue<double>();
var usageSpin = row.Cell(columnUsageSpin).GetCellValue<double>();
var comment = row.Cell(columnComment).GetCellValue<string>() ?? string.Empty;
var section = sections.FirstOrDefault(s =>
string.Equals(s.Caption.Trim(), sectionCaption?.Trim(), StringComparison.CurrentCultureIgnoreCase));
if (section is null)
{
var message = string.Format(IParserService.MessageTemplate, SheetName, row.RowNumber(), columnSection,
"Указана некорректная секция");
throw new FileFormatException(message);
}
var idMode = GetIdMode(modeName);
if (idMode is null)
{
var message = string.Format(IParserService.MessageTemplate, SheetName, row.RowNumber(), columnSection,
"Указан некорректный режим бурения");
throw new FileFormatException(message);
}
var dto = new ProcessMapPlanDrillingDto
{
IdWellSectionType = section.Id,
Section = section.Caption,
IdMode = idMode.Value,
Mode = modeName,
DepthStart = depthStart,
DepthEnd = depthEnd,
AxialLoadPlan = axialLoadPlan,
AxialLoadLimitMax = axialLoadLimitMax,
DeltaPressurePlan = deltaPressurePlan,
DeltaPressureLimitMax = deltaPressureLimitMax,
TopDriveTorquePlan = topDriveTorquePlan,
TopDriveTorqueLimitMax = topDriveTorqueLimitMax,
TopDriveSpeedPlan = topDriveSpeedPlan,
TopDriveSpeedLimitMax = topDriveSpeedLimitMax,
FlowPlan = flowPlan,
FlowLimitMax = flowLimitMax,
RopPlan = ropPlan,
UsageSaub = usageSaub,
UsageSpin = usageSpin,
Comment = comment
};
var columnNumbers = new Dictionary<string, int>
{
{ 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 }
};
return ValidateRow(row.RowNumber(), columnNumbers, dto);
}
}