Экспорт РТК и траекторий

This commit is contained in:
Степанов Дмитрий 2024-03-14 08:30:25 +03:00
parent a08c9c0d8b
commit 95ddd97ace
25 changed files with 345 additions and 200 deletions

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System;
using System.ComponentModel.DataAnnotations;
namespace AsbCloudApp.Data.ProcessMaps;
@ -16,7 +17,12 @@ public class ProcessMapPlanDrillingDto : ProcessMapPlanBaseDto
/// <summary>
/// Название режима бурения
/// </summary>
public string? Mode { get; set; }
public string Mode => IdMode switch
{
1 => "Ротор",
2 => "Слайд",
_ => throw new ArgumentOutOfRangeException()
};
/// <summary>
/// Осевая нагрузка, т план

View File

@ -0,0 +1,19 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services;
/// <summary>
/// Экспорт РТК
/// </summary>
public interface IProcessMapPlanExportService
{
/// <summary>
/// Экспортировать РТК по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<(string FileName, Stream File)> ExportAsync(int idWell, CancellationToken token);
}

View File

@ -0,0 +1,19 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudApp.Services;
/// <summary>
/// Экспорт траекторий
/// </summary>
public interface ITrajectoryExportService
{
/// <summary>
/// Экспортировать траектории по скважине
/// </summary>
/// <param name="idWell"></param>
/// <param name="token"></param>
/// <returns></returns>
Task<(string FileName, Stream File)> ExportAsync(int idWell, CancellationToken token);
}

View File

@ -45,6 +45,7 @@ using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
namespace AsbCloudInfrastructure
{
@ -161,9 +162,6 @@ namespace AsbCloudInfrastructure
services.AddScoped<IWellService, WellService>();
services.AddTransient<IWellOperationImportService, WellOperationImportService>();
services.AddTransient<IProcessMapReportDrillingExportService, ProcessMapReportDataSaubStatExportService>();
services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>();
services.AddTransient<IWellOperationRepository, WellOperationRepository>();
services.AddTransient<IDailyReportService, DailyReportService>();
services.AddTransient<IDetectedOperationService, DetectedOperationService>();
@ -294,7 +292,14 @@ namespace AsbCloudInfrastructure
services.AddTransient<TrajectoryFactManualParser>();
services.AddTransient<ProcessMapPlanDrillingParser>();
services.AddTransient<ProcessMapPlanReamParser>();
services.AddTransient<TrajectoryPlanExportService>();
services.AddTransient<TrajectoryFactManualExportService>();
services.AddTransient<TrajectoryFactNnbExportService>();
services.AddTransient<ProcessMapPlanDrillingExportService>();
services.AddTransient<ProcessMapPlanReamExportService>();
return services;
}
}

View File

@ -28,6 +28,7 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
.Include(e => e.Author)
.Include(e => e.Editor)
.Include(e => e.Well)
.Include(e => e.WellSectionType)
.Where(e => e.IdWell == request.IdWell);
if (request.IdWellSectionType.HasValue)
@ -56,4 +57,11 @@ public class ProcessMapPlanBaseRepository<TDto, TEntity> : ChangeLogRepositoryAb
var offset = TimeSpan.FromHours(timezone.Hours);
return offset;
}
protected override TDto Convert(TEntity entity, TimeSpan offset)
{
var dto = base.Convert(entity, offset);
dto.Section = entity.WellSectionType.Caption;
return dto;
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using ClosedXML.Excel;
using Mapster;
namespace AsbCloudInfrastructure.Services.ExcelServices;
public abstract class ExportExcelService<TDto>
{
protected abstract ITemplateParameters TemplateParameters { get; }
protected Stream Export(IEnumerable<TDto> dtos)
{
using var template = GetTemplateFile();
using var workbook = new XLWorkbook(template);
AddDtosToWorkbook(workbook, dtos);
var memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
private void AddDtosToWorkbook(XLWorkbook workbook, IEnumerable<TDto> dtos)
{
var dtosToArray = dtos.ToArray();
if (!dtosToArray.Any())
return;
var sheet = workbook.GetWorksheet(TemplateParameters.SheetName);
for (var i = 0; i < dtosToArray.Length; i++)
{
var row = sheet.Row(1 + i + TemplateParameters.HeaderRowsCount);
AddRow(row, dtosToArray[i]);
}
}
private void AddRow(IXLRow xlRow, TDto dto)
{
var properties = dto.Adapt<IDictionary<string, object>>();
foreach (var (name, cellValue) in properties)
{
if (TemplateParameters.Cells.TryGetValue(name, out var cell))
xlRow.Cell(cell.ColumnNumber).SetCellValue(cellValue);
}
}
private Stream GetTemplateFile() =>
Assembly.GetExecutingAssembly().GetTemplateCopyStream(TemplateParameters.FileName)
?? throw new ArgumentNullException($"Файл '{TemplateParameters.FileName}' не найден");
}

View File

@ -7,7 +7,7 @@ public class ProcessMapPlanReamTemplate : ITemplateParameters
{
public string SheetName => "План";
public int HeaderRowsCount => 2;
public int HeaderRowsCount => 1;
public string FileName => "ProcessMapPlanReamTemplate.xlsx";

View File

@ -0,0 +1,29 @@
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanDrillingExportService : ProcessMapPlanExportService<ProcessMapPlanDrillingDto>
{
public ProcessMapPlanDrillingExportService(
IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{
}
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanDrillingTemplate();
protected override async Task<string> BuildFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return $"{caption}_РТК_План_бурение.xlsx";
}
}

View File

@ -0,0 +1,38 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public abstract class ProcessMapPlanExportService<TDto> : ExportExcelService<TDto>,
IProcessMapPlanExportService
where TDto : ChangeLogAbstract
{
protected readonly IWellService wellService;
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository;
protected ProcessMapPlanExportService(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
{
this.processMapPlanRepository = processMapPlanRepository;
this.wellService = wellService;
}
public async Task<(string FileName, Stream File)> ExportAsync(int idWell, CancellationToken token)
{
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
var dtos = await processMapPlanRepository.Get(request, token);
var fileName = await BuildFileNameAsync(idWell, token);
var file = Export(dtos);
return (fileName, file);
}
protected abstract Task<string> BuildFileNameAsync(int idWell, CancellationToken token);
}

View File

@ -0,0 +1,29 @@
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.ProcessMaps;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.ProcessMapPlanTemplates;
namespace AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
public class ProcessMapPlanReamExportService : ProcessMapPlanExportService<ProcessMapPlanReamDto>
{
protected override ITemplateParameters TemplateParameters => new ProcessMapPlanReamTemplate();
public ProcessMapPlanReamExportService(
IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> processMapPlanRepository,
IWellService wellService)
: base(processMapPlanRepository, wellService)
{
}
protected override async Task<string> BuildFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return $"{caption}_РТК_План_проработка.xlsx";
}
}

View File

@ -1,83 +1,35 @@
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudInfrastructure.Services.ExcelServices;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public abstract class TrajectoryExportService<TDto> : ExportExcelService<TDto>,
ITrajectoryExportService
where TDto : TrajectoryGeoDto
{
public abstract class TrajectoryExportService<T> where T : TrajectoryGeoDto
{
private readonly IWellService wellService;
protected readonly IWellService wellService;
private readonly ITrajectoryRepository<T> trajectoryRepository;
public abstract string templateFileName { get; }
public abstract string usingTemplateFile { get; }
public abstract string sheetName { get; }
public abstract int headerRowsCount { get; }
private readonly ITrajectoryRepository<TDto> trajectoryRepository;
public TrajectoryExportService(IWellService wellService, ITrajectoryRepository<T> trajectoryRepository)
{
this.wellService = wellService;
this.trajectoryRepository = trajectoryRepository;
}
protected TrajectoryExportService(IWellService wellService, ITrajectoryRepository<TDto> trajectoryRepository)
{
this.wellService = wellService;
this.trajectoryRepository = trajectoryRepository;
}
protected abstract void AddCoordinatesToRow(IXLRow row, T trajectory);
public async Task<(string FileName, Stream File)> ExportAsync(int idWell, CancellationToken token)
{
var dtos = await trajectoryRepository.GetAsync(idWell, token);
public async Task<Stream> ExportAsync(int idWell, CancellationToken token)
{
var trajectorys = await trajectoryRepository.GetAsync(idWell, token);
return MakeExelFileStream(trajectorys);
}
var fileName = await BuildFileNameAsync(idWell, token);
var file = Export(dtos);
return (fileName, file);
}
public async Task<string> GetFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return string.Format("{0}_{1}", caption, templateFileName);
}
public Stream GetTemplateFile()
{
var stream = System.Reflection.Assembly.GetExecutingAssembly()
.GetManifestResourceStream($"{usingTemplateFile}.{templateFileName}");
if (stream is null)
throw new Exception($"Область {usingTemplateFile} не содержит файла с названием {templateFileName}");
return stream;
}
private Stream MakeExelFileStream(IEnumerable<T> trajectories)
{
using Stream ecxelTemplateStream = GetTemplateFile();
using var workbook = new XLWorkbook(ecxelTemplateStream);
AddTrajecoryToWorkbook(workbook, trajectories);
MemoryStream memoryStream = new MemoryStream();
workbook.SaveAs(memoryStream, new SaveOptions { });
memoryStream.Seek(0, SeekOrigin.Begin);
return memoryStream;
}
private void AddTrajecoryToWorkbook(XLWorkbook workbook, IEnumerable<T> trajectories)
{
if (trajectories.Any())
{
var sheet = workbook.GetWorksheet(sheetName);
AddTrajecoryToSheet(sheet, trajectories);
}
}
private void AddTrajecoryToSheet(IXLWorksheet sheet, IEnumerable<T> trajectories)
{
var rowList = trajectories.ToList();
for (int i = 0; i < rowList.Count; i++)
{
var row = sheet.Row(1 + i + headerRowsCount);
AddCoordinatesToRow(row, rowList[i]);
}
}
}
}
protected abstract Task<string> BuildFileNameAsync(int idWell, CancellationToken token);
}

View File

@ -1,35 +1,27 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryFactManualExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public TrajectoryFactManualExportService(IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public class TrajectoryFactManualExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public override string templateFileName { get; } = "TrajectoryFactManualTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Фактическая траектория";
public override int headerRowsCount { get; } = 2;
protected override ITemplateParameters TemplateParameters => new TrajectoryFactManualTemplate();
public TrajectoryFactManualExportService(
IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoFactDto> factTrajectoryService)
: base(wellService, factTrajectoryService)
{
}
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Comment);
}
}
}
protected override async Task<string> BuildFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return $"{caption}_Фактическая_траектория.xlsx";
}
}

View File

@ -1,35 +1,27 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryFactNnbExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public TrajectoryFactNnbExportService(IWellService wellService,
ITrajectoryNnbRepository trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public class TrajectoryFactNnbExportService : TrajectoryExportService<TrajectoryGeoFactDto>
{
public override string templateFileName { get; } = "TrajectoryFactNnbTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Фактическая ннб-траектория";
public override int headerRowsCount { get; } = 2;
protected override ITemplateParameters TemplateParameters => new TrajectoryFactNnbTemplate();
public TrajectoryFactNnbExportService(
IWellService wellService,
ITrajectoryNnbRepository nnbTrajectoryService)
: base(wellService, nnbTrajectoryService)
{
}
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoFactDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Comment);
}
}
}
protected override async Task<string> BuildFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return $"{caption}_Траектория_ННБ.xlsx";
}
}

View File

@ -1,38 +1,27 @@
using AsbCloudApp.Data.Trajectory;
using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using ClosedXML.Excel;
using AsbCloudInfrastructure.Services.ExcelServices.Templates;
using AsbCloudInfrastructure.Services.ExcelServices.Templates.TrajectoryTemplates;
namespace AsbCloudInfrastructure.Services.Trajectory.Export
namespace AsbCloudInfrastructure.Services.Trajectory.Export;
public class TrajectoryPlanExportService : TrajectoryExportService<TrajectoryGeoPlanDto>
{
public class TrajectoryPlanExportService : TrajectoryExportService<TrajectoryGeoPlanDto>
{
/*
* password for PlannedTrajectoryTemplate.xlsx is Drill2022
*/
public override string templateFileName { get; } = "TrajectoryPlanTemplate.xlsx";
public override string usingTemplateFile { get; } = "AsbCloudInfrastructure.Services.Trajectory.Templates";
public override string sheetName { get; } = "Плановая траектория";
public override int headerRowsCount { get; } = 2;
public TrajectoryPlanExportService(IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryRepository)
: base(wellService, trajectoryRepository)
{
}
public TrajectoryPlanExportService(
IWellService wellService,
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> trajectoryPlanService)
: base(wellService, trajectoryPlanService)
{
}
protected override void AddCoordinatesToRow(IXLRow row, TrajectoryGeoPlanDto trajectory)
{
row.Cell(1).SetCellValue(trajectory.WellboreDepth);
row.Cell(2).SetCellValue(trajectory.ZenithAngle);
row.Cell(3).SetCellValue(trajectory.AzimuthGeo);
row.Cell(4).SetCellValue(trajectory.AzimuthMagnetic);
row.Cell(5).SetCellValue(trajectory.VerticalDepth);
row.Cell(6).SetCellValue(trajectory.Radius);
row.Cell(7).SetCellValue(trajectory.Comment);
}
}
}
protected override ITemplateParameters TemplateParameters => new TrajectoryPlanTemplate();
protected override async Task<string> BuildFileNameAsync(int idWell, CancellationToken token)
{
var caption = await wellService.GetWellCaptionByIdAsync(idWell, token);
return $"{caption}_Плановая_Траектория.xlsx";
}
}

View File

@ -29,7 +29,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
DepthEnd = 1.5,
IdMode = 1,
Mode = "Ротор",
AxialLoadPlan = 2.718281,
AxialLoadLimitMax = 3.1415926,
DeltaPressurePlan = 4,
@ -115,7 +114,6 @@ public class ProcessMapPlanDrillingControllerTest: BaseIntegrationTest
nameof(ProcessMapPlanDrillingDto.IdState),
nameof(ProcessMapPlanDrillingDto.Author),
nameof(ProcessMapPlanDrillingDto.Creation),
nameof(ProcessMapPlanDrillingDto.Mode),
nameof(ProcessMapPlanDrillingDto.Section)
};
MatchHelper.Match(expected, actual, excludeProps);

View File

@ -100,7 +100,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
.Returns(trajectoryPlanRows);
var stream = await trajectoryPlanExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
Assert.True(stream.File.Length > 0);
}
@ -111,7 +111,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
.Returns(trajectoryFactRows);
var stream = await trajectoryFactManualExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
Assert.True(stream.File.Length > 0);
}
[Fact]
@ -121,7 +121,7 @@ namespace AsbCloudWebApi.Tests.Services.Trajectory
.Returns(trajectoryFactRows);
var stream = await trajectoryFactNnbExportService.ExportAsync(idWell, CancellationToken.None);
Assert.True(stream.Length > 0);
Assert.True(stream.File.Length > 0);
}
}
}

View File

@ -13,7 +13,6 @@ using AsbCloudApp.Services;
using System.Linq;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudApp.Data.ProcessMaps;
using System.ComponentModel.DataAnnotations;
@ -30,15 +29,18 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
{
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository;
private readonly IWellService wellService;
private readonly ParserExcelService<TDto, WellRelatedParserRequest> parserService;
private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
private readonly IProcessMapPlanExportService processMapPlanExportService;
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ParserExcelService<TDto, WellRelatedParserRequest> parserService)
IParserService<TDto, WellRelatedParserRequest> parserService,
IProcessMapPlanExportService processMapPlanExportService)
{
this.repository = repository;
this.wellService = wellService;
this.parserService = parserService;
this.processMapPlanExportService = processMapPlanExportService;
}
protected abstract string TemplateFileName { get; }
@ -266,6 +268,21 @@ public abstract class ProcessMapPlanBaseController<TDto> : ControllerBase
throw new ForbidException("Нет доступа к скважине");
return idUser;
}
/// <summary>
/// Формируем excel файл с текущими строками РТК
/// </summary>
/// <param name="idWell">id скважины</param>
/// <param name="token"></param>
/// <returns>Запрашиваемый файл</returns>
[HttpGet("export")]
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
[ProducesResponseType(StatusCodes.Status204NoContent)]
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
{
var (fileName, file) = await processMapPlanExportService.ExportAsync(idWell, token);
return File(file, "application/octet-stream", fileName);
}
/// <summary>
/// returns user id or throw

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -13,8 +14,9 @@ public class ProcessMapPlanDrillingController : ProcessMapPlanBaseController<Pro
{
public ProcessMapPlanDrillingController(IChangeLogRepository<ProcessMapPlanDrillingDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanDrillingParser parserService)
: base(repository, wellService, parserService)
ProcessMapPlanDrillingParser parserService,
ProcessMapPlanDrillingExportService processMapPlanExportService)
: base(repository, wellService, parserService, processMapPlanExportService)
{
}

View File

@ -2,6 +2,7 @@
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Export;
using AsbCloudInfrastructure.Services.ProcessMapPlan.Parser;
namespace AsbCloudWebApi.Controllers.ProcessMaps;
@ -13,8 +14,9 @@ public class ProcessMapPlanReamController : ProcessMapPlanBaseController<Process
{
public ProcessMapPlanReamController(IChangeLogRepository<ProcessMapPlanReamDto, ProcessMapPlanBaseRequestWithWell> repository,
IWellService wellService,
ProcessMapPlanReamParser parserService)
: base(repository, wellService, parserService)
ProcessMapPlanReamParser parserService,
ProcessMapPlanReamExportService processMapPlanExportService)
: base(repository, wellService, parserService, processMapPlanExportService)
{
}

View File

@ -1,8 +1,6 @@
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Export;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -21,14 +19,14 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public abstract class TrajectoryController<TDto> : ControllerBase
where TDto : TrajectoryGeoDto
{
protected abstract string fileName { get; }
protected abstract string TemplateFileName { get; }
private readonly IWellService wellService;
private readonly TrajectoryExportService<TDto> trajectoryExportService;
private readonly ITrajectoryExportService trajectoryExportService;
private readonly ITrajectoryRepository<TDto> trajectoryRepository;
public TrajectoryController(IWellService wellService,
TrajectoryExportService<TDto> trajectoryExportService,
protected TrajectoryController(IWellService wellService,
ITrajectoryExportService trajectoryExportService,
ITrajectoryRepository<TDto> trajectoryRepository)
{
this.trajectoryExportService = trajectoryExportService;
@ -50,9 +48,9 @@ namespace AsbCloudWebApi.Controllers.Trajectory
if (!await CanUserAccessToWellAsync(idWell,
token).ConfigureAwait(false))
return Forbid();
var stream = await trajectoryExportService.ExportAsync(idWell, token);
var fileName = await trajectoryExportService.GetFileNameAsync(idWell, token);
return File(stream, "application/octet-stream", fileName);
var (fileName, file) = await trajectoryExportService.ExportAsync(idWell, token);
return File(file, "application/octet-stream", fileName);
}
/// <summary>

View File

@ -1,8 +1,6 @@
using System;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Data.Trajectory;
using AsbCloudApp.Repositories;
using AsbCloudApp.Services;
using AsbCloudInfrastructure.Services.Trajectory.Export;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
@ -12,8 +10,6 @@ using System.Threading;
using System.Threading.Tasks;
using AsbCloudApp.Data;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using AsbCloudInfrastructure.Services.Trajectory.Parser;
namespace AsbCloudWebApi.Controllers.Trajectory
{
@ -26,12 +22,12 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public abstract class TrajectoryEditableController<TDto> : TrajectoryController<TDto>
where TDto : TrajectoryGeoDto
{
private readonly TrajectoryParser<TDto> parserService;
private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
private readonly ITrajectoryEditableRepository<TDto> trajectoryRepository;
protected TrajectoryEditableController(IWellService wellService,
TrajectoryParser<TDto> parserService,
TrajectoryExportService<TDto> trajectoryExportService,
IParserService<TDto, WellRelatedParserRequest> parserService,
ITrajectoryExportService trajectoryExportService,
ITrajectoryEditableRepository<TDto> trajectoryRepository)
: base(wellService, trajectoryExportService, trajectoryRepository)
{
@ -50,7 +46,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
public IActionResult GetTemplate()
{
var stream = parserService.GetTemplateFile();
return File(stream, "application/octet-stream", fileName);
return File(stream, "application/octet-stream", TemplateFileName);
}
/// <summary>

View File

@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactManualController : TrajectoryEditableController<TrajectoryGeoFactDto>
{
protected override string fileName => "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файлаактическая_траектория.xlsx";
public TrajectoryFactManualController(IWellService wellService,
TrajectoryFactManualExportService trajectoryExportService,

View File

@ -15,7 +15,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
[Route("api/well/{idWell}/[controller]")]
public class TrajectoryFactNnbController : TrajectoryController<TrajectoryGeoFactDto>
{
protected override string fileName => "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файлаактическая_ннбраектория.xlsx";
public TrajectoryFactNnbController(
ITrajectoryNnbRepository trajectoryNnbRepository,
TrajectoryFactNnbExportService trajectoryExportService,

View File

@ -20,7 +20,7 @@ namespace AsbCloudWebApi.Controllers.Trajectory
{
private readonly TrajectoryService trajectoryVisualizationService;
protected override string fileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
protected override string TemplateFileName => "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
public TrajectoryPlanController(IWellService wellService,
TrajectoryPlanParser parserService,

View File

@ -7,10 +7,7 @@ using System.IO;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Security.Claims;
using AsbCloudApp.Data;
using AsbCloudApp.Exceptions;
using AsbCloudApp.Requests.ParserOptions;
using AsbCloudInfrastructure.Services.Parser;
using Microsoft.AspNetCore.Http;
namespace Microsoft.AspNetCore.Mvc;