forked from ddrilling/AsbCloudServer
122 lines
5.2 KiB
C#
122 lines
5.2 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 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 IDictionary<string, int> PropertyColumnNumbers => 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 }
|
|
};
|
|
|
|
protected override string TemplateFileName => "ProcessMapPlanDrillingTemplate.xlsx";
|
|
|
|
protected override ProcessMapPlanDrillingDto ParseRow(IXLRow row)
|
|
{
|
|
var sectionCaption = row.Cell(columnSection).GetCellValue<string>()?.Trim().ToLower();
|
|
var modeName = row.Cell(columnMode).GetCellValue<string>()?.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<double>(),
|
|
DepthEnd = row.Cell(columnDepthEnd).GetCellValue<double>(),
|
|
AxialLoadPlan = row.Cell(columnAxialLoadPlan).GetCellValue<double>(),
|
|
AxialLoadLimitMax = row.Cell(columnAxialLoadLimitMax).GetCellValue<double>(),
|
|
DeltaPressurePlan = row.Cell(columnPressurePlan).GetCellValue<double>(),
|
|
DeltaPressureLimitMax = row.Cell(columnPressureLimitMax).GetCellValue<double>(),
|
|
TopDriveTorquePlan = row.Cell(columnTopDriveTorquePlan).GetCellValue<double>(),
|
|
TopDriveTorqueLimitMax = row.Cell(columnTopDriveTorqueLimitMax).GetCellValue<double>(),
|
|
TopDriveSpeedPlan = row.Cell(columnTopDriveSpeedPlan).GetCellValue<double>(),
|
|
TopDriveSpeedLimitMax = row.Cell(columnTopDriveSpeedLimitMax).GetCellValue<double>(),
|
|
FlowPlan = row.Cell(columnFlowPlan).GetCellValue<double>(),
|
|
FlowLimitMax = row.Cell(columnFlowLimitMax).GetCellValue<double>(),
|
|
RopPlan = row.Cell(columnRopPlan).GetCellValue<double>(),
|
|
UsageSaub = row.Cell(columnUsageSaub).GetCellValue<double>(),
|
|
UsageSpin = row.Cell(columnUsageSpin).GetCellValue<double>(),
|
|
Comment = row.Cell(columnComment).GetCellValue<string>() ?? string.Empty
|
|
};
|
|
|
|
return dto;
|
|
}
|
|
} |