Правка по ревью-3

This commit is contained in:
Olga Nemt 2023-11-30 15:08:58 +05:00
parent 8fd9961da7
commit 1acc94fad8
16 changed files with 42 additions and 98 deletions

View File

@ -1,40 +0,0 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services
{
/// <summary>
/// Сервис загрузки и обработки плановой траектории из файла
/// </summary>
public interface IPlannedTrajectoryImportService
{
/// <summary>
/// скачать шаблон для заполнения плановой траектории
/// </summary>
/// <returns></returns>
Stream GetTemplateFile();
/// <summary>
/// Получить имя файла (исходя из названия скважины)
/// </summary>
/// <returns></returns>
Task<string> GetFileNameAsync(int idWell, CancellationToken token);
/// <summary>
/// загрузить текущую плановую траекторию в .xlsx
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<Stream> ExportAsync(int idWell, CancellationToken token);
/// <summary>
/// импортировать из excel плановую траекторию
/// </summary>
/// <param name="idWell"></param>
/// <param name="idUser"></param>
/// <param name="stream"></param>
/// <param name="token"></param>
/// <param name="deleteBeforeImport">Очистить старые координаты перед импортом (если файл проходит валидацию)</param>
Task<int> ImportAsync(int idWell, int idUser, Stream stream, bool deleteBeforeImport, CancellationToken token);
}
}

View File

@ -38,7 +38,7 @@
<EmbeddedResource Include="Services\DrillTestReport\DrillTestReportTemplate.xlsx" /> <EmbeddedResource Include="Services\DrillTestReport\DrillTestReportTemplate.xlsx" />
<EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryFactNnbTemplate.xlsx" /> <EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryFactNnbTemplate.xlsx" />
<EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryFactManualTemplate.xlsx" /> <EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryFactManualTemplate.xlsx" />
<EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryPlannedTemplate.xlsx" /> <EmbeddedResource Include="Services\Trajectory\Templates\TrajectoryPlanTemplate.xlsx" />
<EmbeddedResource Include="Services\WellOperationService\ScheduleReportTemplate.xlsx" /> <EmbeddedResource Include="Services\WellOperationService\ScheduleReportTemplate.xlsx" />
<EmbeddedResource Include="Services\WellOperationImport\Files\WellOperationImportTemplate.xlsx" /> <EmbeddedResource Include="Services\WellOperationImport\Files\WellOperationImportTemplate.xlsx" />
<EmbeddedResource Include="Services\WellOperationImport\Files\Dictionaries\Operations.txt" /> <EmbeddedResource Include="Services\WellOperationImport\Files\Dictionaries\Operations.txt" />

View File

@ -201,10 +201,10 @@ namespace AsbCloudInfrastructure
services.AddTransient<IWellService, WellService>(); services.AddTransient<IWellService, WellService>();
services.AddTransient<IWellOperationImportService, WellOperationImportService>(); services.AddTransient<IWellOperationImportService, WellOperationImportService>();
services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportWellDrillingExportService>(); services.AddTransient<IProcessMapReportWellDrillingExportService, ProcessMapReportWellDrillingExportService>();
services.AddTransient<TrajectoryPlannedExportService>(); services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>(); services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>(); services.AddTransient<TrajectoryFactNnbExportService>();
services.AddTransient<TrajectoryPlannedParserService>(); services.AddTransient<TrajectoryPlanParserService>();
services.AddTransient<TrajectoryFactManualParserService>(); services.AddTransient<TrajectoryFactManualParserService>();
services.AddTransient<IWellOperationRepository, WellOperationRepository>(); services.AddTransient<IWellOperationRepository, WellOperationRepository>();
services.AddTransient<IDailyReportService, DailyReportService>(); services.AddTransient<IDailyReportService, DailyReportService>();
@ -276,9 +276,9 @@ namespace AsbCloudInfrastructure
services.AddTransient<IWellContactService, WellContactService>(); services.AddTransient<IWellContactService, WellContactService>();
services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto, services.AddTransient<ICrudRepository<WellSectionTypeDto>, CrudCacheRepositoryBase<WellSectionTypeDto,
WellSectionType>>(); WellSectionType>>();
services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>(); services.AddTransient<ICrudRepository<SubsystemDto>, CrudCacheRepositoryBase<SubsystemDto, Subsystem>>();
services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>(); services.AddTransient<ICrudRepository<PermissionDto>, CrudCacheRepositoryBase<PermissionDto, Permission>>();
// TelemetryData services // TelemetryData services

View File

@ -18,7 +18,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
private readonly ITrajectoryRepository<T> trajectoryRepository; private readonly ITrajectoryRepository<T> trajectoryRepository;
public abstract string templateFileName { get; } public abstract string templateFileName { get; }
public abstract string usingTemplateFile { get; } public abstract string usingTemplateFile { get; }
public abstract string sheetTrajectory { get; } public abstract string sheetName { get; }
public abstract int headerRowsCount { get; } public abstract int headerRowsCount { get; }
public TrajectoryExportService(IWellService wellService, ITrajectoryRepository<T> trajectoryRepository) public TrajectoryExportService(IWellService wellService, ITrajectoryRepository<T> trajectoryRepository)
@ -65,9 +65,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
{ {
if (trajectories.Any()) if (trajectories.Any())
{ {
var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetTrajectory); var sheet = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName);
if (sheet is null) if (sheet is null)
throw new FileFormatException($"Лист с именем {sheetTrajectory} отсутствует, либо имеет некорректное название"); throw new FileFormatException($"Лист с именем {sheetName} отсутствует, либо имеет некорректное название");
AddTrajecoryToSheet(sheet, trajectories); AddTrajecoryToSheet(sheet, trajectories);
} }
} }

View File

@ -10,7 +10,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
{ {
public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx"; public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates"; public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetTrajectory { get; } = "Фактическая траектория"; public override string sheetName { get; } = "Фактическая траектория";
public override int headerRowsCount { get; } = 2; public override int headerRowsCount { get; } = 2;
public TrajectoryFactManualExportService( public TrajectoryFactManualExportService(

View File

@ -10,7 +10,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Export
{ {
public override string templateFileName { get; } = "TrajectoryFactNnbTemplate.xlsx"; public override string templateFileName { get; } = "TrajectoryFactNnbTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates"; public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetTrajectory { get; } = "Фактическая ннб-траектория"; public override string sheetName { get; } = "Фактическая ннб-траектория";
public override int headerRowsCount { get; } = 2; public override int headerRowsCount { get; } = 2;
public TrajectoryFactNnbExportService( public TrajectoryFactNnbExportService(

View File

@ -5,17 +5,17 @@ using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.Trajectory.Export namespace AsbCloudInfrastructure.Services.Trajectory.Export
{ {
public class TrajectoryPlannedExportService : TrajectoryExportService<TrajectoryGeoPlanDto> public class TrajectoryPlanExportService : TrajectoryExportService<TrajectoryGeoPlanDto>
{ {
/* /*
* password for PlannedTrajectoryTemplate.xlsx is Drill2022 * password for PlannedTrajectoryTemplate.xlsx is Drill2022
*/ */
public override string templateFileName { get; } = "TrajectoryPlannedTemplate.xlsx"; public override string templateFileName { get; } = "TrajectoryPlanTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates"; public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetTrajectory { get; } = "Плановая траектория"; public override string sheetName { get; } = "Плановая траектория";
public override int headerRowsCount { get; } = 2; public override int headerRowsCount { get; } = 2;
public TrajectoryPlannedExportService( public TrajectoryPlanExportService(
IWellService wellService, IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryService) ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryService)
: base(wellService, plannedTrajectoryService) : base(wellService, plannedTrajectoryService)

View File

@ -8,14 +8,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Import
{ {
public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx"; public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates"; public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetNameTrajectory { get; } = "Фактическая траектория"; public override string sheetName { get; } = "Фактическая траектория";
public override int headerRowsCount { get; } = 2; public override int headerRowsCount { get; } = 2;
public TrajectoryFactManualParserService() : base()
{
}
protected override TrajectoryGeoFactDto ParseRow(IXLRow row) protected override TrajectoryGeoFactDto ParseRow(IXLRow row)
{ {
var trajectoryRow = new TrajectoryGeoFactDto var trajectoryRow = new TrajectoryGeoFactDto

View File

@ -1,7 +1,6 @@
using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Data.Trajectory;
using ClosedXML.Excel; using ClosedXML.Excel;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -12,15 +11,12 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Import
{ {
public abstract string templateFileName { get; } public abstract string templateFileName { get; }
public abstract string usingTemplateFile { get; } public abstract string usingTemplateFile { get; }
public abstract string sheetNameTrajectory { get; } public abstract string sheetName { get; }
public abstract int headerRowsCount { get; } public abstract int headerRowsCount { get; }
public TrajectoryParserService()
{
}
protected abstract T ParseRow(IXLRow row); protected abstract T ParseRow(IXLRow row);
public IEnumerable<T> ImportAsync(Stream stream) public IEnumerable<T> Import(Stream stream)
{ {
using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled); using var workbook = new XLWorkbook(stream, XLEventTracking.Disabled);
var trajectoryRows = ParseFileStream(stream); var trajectoryRows = ParseFileStream(stream);
@ -37,9 +33,9 @@ namespace AsbCloudInfrastructure.Services.Trajectory.Import
private IEnumerable<T> ParseWorkbook(IXLWorkbook workbook) private IEnumerable<T> ParseWorkbook(IXLWorkbook workbook)
{ {
var sheetTrajectory = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetNameTrajectory); var sheetTrajectory = workbook.Worksheets.FirstOrDefault(ws => ws.Name == sheetName);
if (sheetTrajectory is null) if (sheetTrajectory is null)
throw new FileFormatException($"Книга excel не содержит листа {sheetNameTrajectory}."); throw new FileFormatException($"Книга excel не содержит листа {sheetName}.");
var trajectoryRows = ParseSheet(sheetTrajectory); var trajectoryRows = ParseSheet(sheetTrajectory);
return trajectoryRows; return trajectoryRows;
} }

View File

@ -4,20 +4,13 @@ using ClosedXML.Excel;
namespace AsbCloudInfrastructure.Services.Trajectory.Import namespace AsbCloudInfrastructure.Services.Trajectory.Import
{ {
public class TrajectoryPlannedParserService : TrajectoryParserService<TrajectoryGeoPlanDto> public class TrajectoryPlanParserService : TrajectoryParserService<TrajectoryGeoPlanDto>
{ {
/* public override string templateFileName { get; } = "TrajectoryPlanTemplate.xlsx";
* password for PlannedTrajectoryTemplate.xlsx is Drill2022
*/
public override string templateFileName { get; } = "TrajectoryPlannedTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates"; public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetNameTrajectory { get; } = "Плановая траектория"; public override string sheetName { get; } = "Плановая траектория";
public override int headerRowsCount { get; } = 2; public override int headerRowsCount { get; } = 2;
public TrajectoryPlannedParserService() : base()
{
}
protected override TrajectoryGeoPlanDto ParseRow(IXLRow row) protected override TrajectoryGeoPlanDto ParseRow(IXLRow row)
{ {
var trajectoryRow = new TrajectoryGeoPlanDto var trajectoryRow = new TrajectoryGeoPlanDto

View File

@ -0,0 +1 @@
password for PlannedTrajectoryTemplate.xlsx is Drill2022

View File

@ -1,6 +1,5 @@
using AsbCloudApp.Data.Trajectory; using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories; using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Export; using AsbCloudInfrastructure.Services.Trajectory.Export;
using NSubstitute; using NSubstitute;
@ -14,8 +13,8 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
public class TrajectoryExportTest public class TrajectoryExportTest
{ {
private IWellService wellService; private IWellService wellService;
private readonly ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryPlannedRepository; private readonly ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryPlanRepository;
private readonly TrajectoryPlannedExportService trajectoryPlannedExportService; private readonly TrajectoryPlanExportService trajectoryPlanExportService;
private readonly ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryFactManualReposirory; private readonly ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryFactManualReposirory;
private readonly TrajectoryFactManualExportService trajectoryFactManualExportService; private readonly TrajectoryFactManualExportService trajectoryFactManualExportService;
@ -25,7 +24,7 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
private readonly int idWell = 4; private readonly int idWell = 4;
private readonly TrajectoryGeoPlanDto[] trajectoryPlannedRows = new TrajectoryGeoPlanDto[2] { private readonly TrajectoryGeoPlanDto[] trajectoryPlanRows = new TrajectoryGeoPlanDto[2] {
new TrajectoryGeoPlanDto() { new TrajectoryGeoPlanDto() {
Id = 1, Id = 1,
AzimuthGeo = 1, AzimuthGeo = 1,
@ -84,8 +83,8 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
public TrajectoryExportTest() public TrajectoryExportTest()
{ {
wellService = Substitute.For<IWellService>(); wellService = Substitute.For<IWellService>();
trajectoryPlannedRepository = Substitute.For<ITrajectoryEditableRepository<TrajectoryGeoPlanDto>>(); trajectoryPlanRepository = Substitute.For<ITrajectoryEditableRepository<TrajectoryGeoPlanDto>>();
trajectoryPlannedExportService = new TrajectoryPlannedExportService(wellService, trajectoryPlannedRepository); trajectoryPlanExportService = new TrajectoryPlanExportService(wellService, trajectoryPlanRepository);
trajectoryFactManualReposirory = Substitute.For<ITrajectoryEditableRepository<TrajectoryGeoFactDto>>(); trajectoryFactManualReposirory = Substitute.For<ITrajectoryEditableRepository<TrajectoryGeoFactDto>>();
trajectoryFactManualExportService = new TrajectoryFactManualExportService(wellService, trajectoryFactManualReposirory); trajectoryFactManualExportService = new TrajectoryFactManualExportService(wellService, trajectoryFactManualReposirory);
@ -97,10 +96,10 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
[Fact] [Fact]
public async Task Export_trajectory_planned() public async Task Export_trajectory_planned()
{ {
trajectoryPlannedRepository.GetAsync(idWell, CancellationToken.None) trajectoryPlanRepository.GetAsync(idWell, CancellationToken.None)
.Returns(trajectoryPlannedRows); .Returns(trajectoryPlanRows);
var stream = await trajectoryPlannedExportService.ExportAsync(idWell, CancellationToken.None); var stream = await trajectoryPlanExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0); Assert.True(stream.Length > 0);
} }

View File

@ -6,14 +6,14 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
{ {
public class TrajectoryImportTest public class TrajectoryImportTest
{ {
private readonly TrajectoryPlannedParserService trajectoryPlannedImportService; private readonly TrajectoryPlanParserService trajectoryPlanImportService;
private readonly TrajectoryFactManualParserService trajectoryFactManualImportService; private readonly TrajectoryFactManualParserService trajectoryFactManualImportService;
private string usingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates"; private string usingTemplateFile = "AsbCloudWebApi.Tests.Services.Trajectory.Templates";
public TrajectoryImportTest() public TrajectoryImportTest()
{ {
trajectoryPlannedImportService = new TrajectoryPlannedParserService(); trajectoryPlanImportService = new TrajectoryPlanParserService();
trajectoryFactManualImportService = new TrajectoryFactManualParserService(); trajectoryFactManualImportService = new TrajectoryFactManualParserService();
} }
@ -21,12 +21,12 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
public void Import_trajectory_planned() public void Import_trajectory_planned()
{ {
var stream = System.Reflection.Assembly.GetExecutingAssembly() var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"{usingTemplateFile}.TrajectoryPlannedTemplate.xlsx"); .GetManifestResourceStream($"{usingTemplateFile}.TrajectoryPlanTemplate.xlsx");
if (stream is null) if (stream is null)
Assert.Fail("Файла для импорта не существует"); Assert.Fail("Файла для импорта не существует");
var trajectoryRows = trajectoryPlannedImportService.ImportAsync(stream); var trajectoryRows = trajectoryPlanImportService.Import(stream);
Assert.Equal(3, trajectoryRows.Count()); Assert.Equal(3, trajectoryRows.Count());
} }
@ -40,7 +40,7 @@ namespace AsbCloudWebApi.Tests.UnitTests.Services.Trajectory
if (stream is null) if (stream is null)
Assert.Fail("Файла для импорта не существует"); Assert.Fail("Файла для импорта не существует");
var trajectoryRows = trajectoryFactManualImportService.ImportAsync(stream); var trajectoryRows = trajectoryFactManualImportService.Import(stream);
Assert.Equal(4, trajectoryRows.Count()); Assert.Equal(4, trajectoryRows.Count());
} }

View File

@ -88,7 +88,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
try try
{ {
var trajectoryRows = trajectoryImportService.ImportAsync(stream); var trajectoryRows = trajectoryImportService.Import(stream);
foreach (var row in trajectoryRows) foreach (var row in trajectoryRows)
{ {
row.IdWell = idWell; row.IdWell = idWell;

View File

@ -15,15 +15,15 @@ namespace AsbCloudWebApi.Controllers.Trajectory
/// <summary> /// <summary>
/// Плановая траектория (загрузка и хранение) /// Плановая траектория (загрузка и хранение)
/// </summary> /// </summary>
[Route("api/well/{idWell}/plannedTrajectory")] [Route("api/well/{idWell}/[controller]")]
[ApiController] [ApiController]
public class TrajectoryPlannedController : TrajectoryEditableController<TrajectoryGeoPlanDto> public class TrajectoryPlanController : TrajectoryEditableController<TrajectoryGeoPlanDto>
{ {
private readonly TrajectoryService trajectoryVisualizationService; private readonly TrajectoryService trajectoryVisualizationService;
public TrajectoryPlannedController(IWellService wellService, public TrajectoryPlanController(IWellService wellService,
TrajectoryPlannedParserService plannedTrajectoryImportService, TrajectoryPlanParserService plannedTrajectoryImportService,
TrajectoryPlannedExportService plannedTrajectoryExportService, TrajectoryPlanExportService plannedTrajectoryExportService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryRepository, ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryRepository,
TrajectoryService trajectoryVisualizationService) TrajectoryService trajectoryVisualizationService)
: base( : base(