forked from ddrilling/AsbCloudServer
Контроллеры по формированию плановых и фактических траекторий наследуются от одного TrajectoryController
This commit is contained in:
parent
81bd89aafc
commit
454945e2dc
@ -11,6 +11,10 @@ namespace AsbCloudApp.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class TrajectoryGeoDto
|
public abstract class TrajectoryGeoDto
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ИД строки с координатами
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Id скважины
|
/// Id скважины
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -7,11 +7,6 @@ namespace AsbCloudApp.Data;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrajectoryGeoFactDto : TrajectoryGeoDto
|
public class TrajectoryGeoFactDto : TrajectoryGeoDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// ИД строки с координатами
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Радиус цели
|
/// Радиус цели
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -6,11 +6,6 @@ namespace AsbCloudApp.Data
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TrajectoryGeoPlanDto: TrajectoryGeoDto
|
public class TrajectoryGeoPlanDto: TrajectoryGeoDto
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// ИД строки с координатами
|
|
||||||
/// </summary>
|
|
||||||
public int Id { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Радиус цели
|
/// Радиус цели
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -10,7 +10,7 @@ namespace AsbCloudInfrastructure.Services.Trajectory
|
|||||||
{
|
{
|
||||||
public override string templateFileName { get; set; } = "FactTrajectoryTemplate.xlsx";
|
public override string templateFileName { get; set; } = "FactTrajectoryTemplate.xlsx";
|
||||||
public override string usingTemplateFile { get; set; } = "AsbCloudInfrastructure.Services.Trajectory";
|
public override string usingTemplateFile { get; set; } = "AsbCloudInfrastructure.Services.Trajectory";
|
||||||
public override string sheetNamePlannedTrajectory { get; set; } = "Плановая траектория";
|
public override string sheetNamePlannedTrajectory { get; set; } = "Фактическая траектория";
|
||||||
public override int headerRowsCount { get; set; } = 2;
|
public override int headerRowsCount { get; set; } = 2;
|
||||||
public override int ColumnWellboreDepth { get; set; } = 1;
|
public override int ColumnWellboreDepth { get; set; } = 1;
|
||||||
public override int ColumnZenithAngle { get; set; } = 2;
|
public override int ColumnZenithAngle { get; set; } = 2;
|
||||||
|
@ -1,14 +1,7 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudInfrastructure.Services;
|
|
||||||
using AsbCloudInfrastructure.Services.Trajectory;
|
using AsbCloudInfrastructure.Services.Trajectory;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
namespace AsbCloudWebApi.Controllers.Trajectory;
|
namespace AsbCloudWebApi.Controllers.Trajectory;
|
||||||
@ -16,194 +9,18 @@ namespace AsbCloudWebApi.Controllers.Trajectory;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Фактическая траектория
|
/// Фактическая траектория
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Authorize]
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("api/well/{idWell}/[controller]")]
|
[Route("api/well/{idWell}/[controller]")]
|
||||||
public class FactTrajectoryController : ControllerBase
|
public class FactTrajectoryController : TrajectoryController<TrajectoryGeoFactDto>
|
||||||
{
|
{
|
||||||
private readonly ITrajectoryEditableRepository<TrajectoryGeoFactDto> factTrajectoryRepository;
|
public FactTrajectoryController(IWellService wellService,
|
||||||
private readonly IWellService wellService;
|
FactTrajectoryImportService factTrajectoryImportService,
|
||||||
private readonly FactTrajectoryImportService factTrajectoryImportService;
|
ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryFactRepository)
|
||||||
|
: base(
|
||||||
public FactTrajectoryController(
|
wellService,
|
||||||
ITrajectoryEditableRepository<TrajectoryGeoFactDto> trajectoryFactRepository,
|
factTrajectoryImportService,
|
||||||
IWellService wellService,
|
trajectoryFactRepository)
|
||||||
FactTrajectoryImportService factTrajectoryImportService)
|
|
||||||
{
|
{
|
||||||
this.factTrajectoryRepository = trajectoryFactRepository;
|
fileName = "ЕЦП_шаблон_файла_фактическая_траектория.xlsx";
|
||||||
this.wellService = wellService;
|
|
||||||
this.factTrajectoryImportService = factTrajectoryImportService;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Метод получения всех строк фактических траекторий по id скважины
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">Id скважины</param>
|
|
||||||
/// <param name="cancellationToken">Токен отмены операции</param>
|
|
||||||
/// <returns></returns>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<TrajectoryGeoFactDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> GetRowsAsync([FromRoute] int idWell,
|
|
||||||
CancellationToken cancellationToken)
|
|
||||||
{
|
|
||||||
var importedFactTrajectories = await factTrajectoryRepository.GetAsync(idWell,
|
|
||||||
cancellationToken);
|
|
||||||
|
|
||||||
return Ok(importedFactTrajectories);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавить одну новую строчку координат для фактической траектории
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="row"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
|
||||||
[HttpPost]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> AddAsync(int idWell, [FromBody] TrajectoryGeoFactDto row,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
var idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
row.IdUser = idUser.Value;
|
|
||||||
row.IdWell = idWell;
|
|
||||||
var result = await factTrajectoryRepository.AddAsync(row, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Изменить выбранную строку с координатами
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idRow"></param>
|
|
||||||
/// <param name="row"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно обновленных строк в БД</returns>
|
|
||||||
[HttpPut("{idRow}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
|
|
||||||
[FromBody] TrajectoryGeoFactDto row, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
int? idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
row.Id = idRow;
|
|
||||||
row.IdUser = idUser.Value;
|
|
||||||
row.IdWell = idWell;
|
|
||||||
var result = await factTrajectoryRepository.UpdateAsync(row, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Удалить выбранную строку с координатами
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idRow"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно удаленных строк из БД</returns>
|
|
||||||
[HttpDelete("{idRow}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> DeleteAsync(int idWell, int idRow, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var result = await factTrajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token);
|
|
||||||
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
var stream = await factTrajectoryImportService.ExportAsync(idWell, token);
|
|
||||||
var fileName = await factTrajectoryImportService.GetFileNameAsync(idWell, token);
|
|
||||||
return File(stream, "application/octet-stream", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Возвращает excel шаблон для заполнения строк фактической траектории
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Запрашиваемый файл</returns>
|
|
||||||
[HttpGet("template")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
||||||
public IActionResult GetTemplate()
|
|
||||||
{
|
|
||||||
var stream = factTrajectoryImportService.GetTemplateFile();
|
|
||||||
var fileName = "ЕЦП_шаблон_файла_фактическая_импортируемая_траектория.xlsx";
|
|
||||||
return File(stream, "application/octet-stream", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Импортирует координаты из excel (xlsx) файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
|
||||||
/// <param name="deleteBeforeImport">Удалить операции перед импортом, если фал валидный</param>
|
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
|
||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
|
||||||
[HttpPost("import/{deleteBeforeImport}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
|
||||||
public async Task<IActionResult> ImportAsync(int idWell,
|
|
||||||
[FromForm] IFormFileCollection files,
|
|
||||||
bool deleteBeforeImport,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
int? idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
if (files.Count < 1)
|
|
||||||
return this.ValidationBadRequest(nameof(files), "нет файла");
|
|
||||||
var file = files[0];
|
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
|
||||||
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
|
||||||
using Stream stream = file.OpenReadStream();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var trajectoryRows = await factTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, token);
|
|
||||||
|
|
||||||
if (deleteBeforeImport)
|
|
||||||
await factTrajectoryRepository.DeleteByIdWellAsync(idWell, token);
|
|
||||||
|
|
||||||
var rowsCount = await factTrajectoryRepository.AddRangeAsync(trajectoryRows, token);
|
|
||||||
|
|
||||||
return Ok(rowsCount);
|
|
||||||
}
|
|
||||||
catch (FileFormatException ex)
|
|
||||||
{
|
|
||||||
return this.ValidationBadRequest(nameof(files), ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
|
||||||
{
|
|
||||||
int? idCompany = User.GetCompanyId();
|
|
||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
||||||
idWell, token).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -2,11 +2,8 @@
|
|||||||
using AsbCloudApp.Repositories;
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudInfrastructure.Services.Trajectory;
|
using AsbCloudInfrastructure.Services.Trajectory;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Http;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -18,216 +15,23 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[Route("api/well/{idWell}/plannedTrajectory")]
|
[Route("api/well/{idWell}/plannedTrajectory")]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Authorize]
|
public class PlannedTrajectoryController : TrajectoryController<TrajectoryGeoPlanDto>
|
||||||
public class PlannedTrajectoryController : ControllerBase
|
|
||||||
{
|
{
|
||||||
private readonly IWellService wellService;
|
|
||||||
private readonly PlannedTrajectoryImportService plannedTrajectoryImportService;
|
|
||||||
private readonly ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryRepository;
|
|
||||||
private readonly TrajectoryService trajectoryVisualizationService;
|
private readonly TrajectoryService trajectoryVisualizationService;
|
||||||
|
|
||||||
public PlannedTrajectoryController(IWellService wellService,
|
public PlannedTrajectoryController(IWellService wellService,
|
||||||
PlannedTrajectoryImportService plannedTrajectoryImportService,
|
PlannedTrajectoryImportService plannedTrajectoryImportService,
|
||||||
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryRepository,
|
ITrajectoryEditableRepository<TrajectoryGeoPlanDto> plannedTrajectoryRepository,
|
||||||
TrajectoryService trajectoryVisualizationService)
|
TrajectoryService trajectoryVisualizationService)
|
||||||
|
: base(
|
||||||
|
wellService,
|
||||||
|
plannedTrajectoryImportService,
|
||||||
|
plannedTrajectoryRepository)
|
||||||
{
|
{
|
||||||
this.plannedTrajectoryImportService = plannedTrajectoryImportService;
|
fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
|
||||||
this.wellService = wellService;
|
|
||||||
this.plannedTrajectoryRepository = plannedTrajectoryRepository;
|
|
||||||
this.trajectoryVisualizationService = trajectoryVisualizationService;
|
this.trajectoryVisualizationService = trajectoryVisualizationService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Возвращает excel шаблон для заполнения строк плановой траектории
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>Запрашиваемый файл</returns>
|
|
||||||
[HttpGet("template")]
|
|
||||||
[AllowAnonymous]
|
|
||||||
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
|
||||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
|
||||||
public IActionResult GetTemplate()
|
|
||||||
{
|
|
||||||
var stream = plannedTrajectoryImportService.GetTemplateFile();
|
|
||||||
var fileName = "ЕЦП_шаблон_файла_плановая_траектория.xlsx";
|
|
||||||
return File(stream, "application/octet-stream", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <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)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
var stream = await plannedTrajectoryImportService.ExportAsync(idWell, token);
|
|
||||||
var fileName = await plannedTrajectoryImportService.GetFileNameAsync(idWell, token);
|
|
||||||
return File(stream, "application/octet-stream", fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Импортирует координаты из excel (xlsx) файла
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="files">Коллекция из одного файла xlsx</param>
|
|
||||||
/// <param name="deleteBeforeImport">Удалить операции перед импортом, если фал валидный</param>
|
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
|
||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
|
||||||
[HttpPost("import/{deleteBeforeImport}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
|
||||||
public async Task<IActionResult> ImportAsync(int idWell,
|
|
||||||
[FromForm] IFormFileCollection files,
|
|
||||||
bool deleteBeforeImport,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
int? idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
if (files.Count < 1)
|
|
||||||
return this.ValidationBadRequest(nameof(files), "нет файла");
|
|
||||||
var file = files[0];
|
|
||||||
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
|
||||||
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
|
||||||
using Stream stream = file.OpenReadStream();
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var trajectoryRows = await plannedTrajectoryImportService.ImportAsync(idWell, idUser.Value, stream, token);
|
|
||||||
|
|
||||||
if (deleteBeforeImport)
|
|
||||||
await plannedTrajectoryRepository.DeleteByIdWellAsync(idWell, token);
|
|
||||||
|
|
||||||
var rowsCount = await plannedTrajectoryRepository.AddRangeAsync(trajectoryRows, token);
|
|
||||||
|
|
||||||
return Ok(rowsCount);
|
|
||||||
}
|
|
||||||
catch (FileFormatException ex)
|
|
||||||
{
|
|
||||||
return this.ValidationBadRequest(nameof(files), ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Получаем список всех строк координат плановой траектории (для клиента)
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell">id скважины</param>
|
|
||||||
/// <param name="token"> Токен отмены задачи </param>
|
|
||||||
/// <returns>Список добавленных координат плановой траектории</returns>
|
|
||||||
[HttpGet]
|
|
||||||
[ProducesResponseType(typeof(IEnumerable<TrajectoryGeoPlanDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> GetAsync([FromRoute] int idWell, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
var result = await plannedTrajectoryRepository.GetAsync(idWell, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавить одну новую строчку координат для плановой траектории
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="row"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
|
||||||
[HttpPost]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> AddAsync(int idWell, [FromBody] TrajectoryGeoPlanDto row,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
var idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
row.IdUser = idUser.Value;
|
|
||||||
row.IdWell = idWell;
|
|
||||||
var result = await plannedTrajectoryRepository.AddAsync(row, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Добавить массив строчек координат для плановой траектории
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="rows"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно записанных строк в БД</returns>
|
|
||||||
[HttpPost("range")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<TrajectoryGeoPlanDto> rows,
|
|
||||||
CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
int? idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
foreach (var item in rows)
|
|
||||||
{
|
|
||||||
item.IdUser = idUser.Value;
|
|
||||||
item.IdWell = idWell;
|
|
||||||
}
|
|
||||||
var result = await plannedTrajectoryRepository.AddRangeAsync(rows, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Изменить выбранную строку с координатами
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idRow"></param>
|
|
||||||
/// <param name="row"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно обновленных строк в БД</returns>
|
|
||||||
[HttpPut("{idRow}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
|
|
||||||
[FromBody] TrajectoryGeoPlanDto row, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
int? idUser = User.GetUserId();
|
|
||||||
if (!idUser.HasValue)
|
|
||||||
return Forbid();
|
|
||||||
row.Id = idRow;
|
|
||||||
row.IdUser = idUser.Value;
|
|
||||||
row.IdWell = idWell;
|
|
||||||
var result = await plannedTrajectoryRepository.UpdateAsync(row, token);
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Удалить выбранную строку с координатами
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="idWell"></param>
|
|
||||||
/// <param name="idRow"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns>количество успешно удаленных строк из БД</returns>
|
|
||||||
[HttpDelete("{idRow}")]
|
|
||||||
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
||||||
public async Task<IActionResult> DeleteAsync(int idWell, int idRow, CancellationToken token)
|
|
||||||
{
|
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
|
||||||
token).ConfigureAwait(false))
|
|
||||||
return Forbid();
|
|
||||||
|
|
||||||
var result = await plannedTrajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token);
|
|
||||||
|
|
||||||
return Ok(result);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получение координат для визуализации траектории (плановой и фактической)
|
/// Получение координат для визуализации траектории (плановой и фактической)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -238,20 +42,13 @@ namespace AsbCloudWebApi.Controllers.Trajectory
|
|||||||
[ProducesResponseType(typeof(PlanFactBase<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>, IEnumerable<TrajectoryCartesianFactDto>>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(PlanFactBase<IEnumerable<TrajectoryCartesianPlanDto>, IEnumerable<TrajectoryCartesianFactDto>, IEnumerable<TrajectoryCartesianFactDto>>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> GetTrajectoryCartesianPlanFactAsync(int idWell, CancellationToken token)
|
public async Task<IActionResult> GetTrajectoryCartesianPlanFactAsync(int idWell, CancellationToken token)
|
||||||
{
|
{
|
||||||
if (!await CanUserAccessToWellAsync(idWell,
|
if (!await base.CanUserAccessToWellAsync(idWell,
|
||||||
token).ConfigureAwait(false))
|
token).ConfigureAwait(false))
|
||||||
return Forbid();
|
return Forbid();
|
||||||
|
|
||||||
var result = await trajectoryVisualizationService.GetTrajectoryCartesianAsync(idWell, token);
|
var result = await trajectoryVisualizationService.GetTrajectoryCartesianAsync(idWell, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
|
||||||
{
|
|
||||||
int? idCompany = User.GetCompanyId();
|
|
||||||
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
||||||
idWell, token).ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
237
AsbCloudWebApi/Controllers/Trajectory/TrajectoryController.cs
Normal file
237
AsbCloudWebApi/Controllers/Trajectory/TrajectoryController.cs
Normal file
@ -0,0 +1,237 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudInfrastructure.Services.Trajectory;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Http;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudWebApi.Controllers.Trajectory
|
||||||
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Плановые и фактические траектории (загрузка и хранение)
|
||||||
|
/// </summary>
|
||||||
|
[ApiController]
|
||||||
|
[Authorize]
|
||||||
|
public abstract class TrajectoryController<Tdto> : ControllerBase
|
||||||
|
where Tdto : TrajectoryGeoDto
|
||||||
|
{
|
||||||
|
protected string fileName;
|
||||||
|
|
||||||
|
private readonly IWellService wellService;
|
||||||
|
private readonly TrajectoryImportService<Tdto> trajectoryImportService;
|
||||||
|
private readonly ITrajectoryEditableRepository<Tdto> trajectoryRepository;
|
||||||
|
|
||||||
|
public TrajectoryController(IWellService wellService,
|
||||||
|
TrajectoryImportService<Tdto> trajectoryImportService,
|
||||||
|
ITrajectoryEditableRepository<Tdto> trajectoryRepository)
|
||||||
|
{
|
||||||
|
this.trajectoryImportService = trajectoryImportService;
|
||||||
|
this.wellService = wellService;
|
||||||
|
this.trajectoryRepository = trajectoryRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Возвращает excel шаблон для заполнения строк траектории
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Запрашиваемый файл</returns>
|
||||||
|
[HttpGet("template")]
|
||||||
|
[AllowAnonymous]
|
||||||
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
||||||
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||||
|
public IActionResult GetTemplate()
|
||||||
|
{
|
||||||
|
var stream = trajectoryImportService.GetTemplateFile();
|
||||||
|
return File(stream, "application/octet-stream", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
var stream = await trajectoryImportService.ExportAsync(idWell, token);
|
||||||
|
var fileName = await trajectoryImportService.GetFileNameAsync(idWell, token);
|
||||||
|
return File(stream, "application/octet-stream", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Импортирует координаты из excel (xlsx) файла
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
||||||
|
/// <param name="deleteBeforeImport">Удалить операции перед импортом, если фал валидный</param>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
|
[HttpPost("import/{deleteBeforeImport}")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
||||||
|
public async Task<IActionResult> ImportAsync(int idWell,
|
||||||
|
[FromForm] IFormFileCollection files,
|
||||||
|
bool deleteBeforeImport,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
int? idUser = User.GetUserId();
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
if (files.Count < 1)
|
||||||
|
return this.ValidationBadRequest(nameof(files), "нет файла");
|
||||||
|
var file = files[0];
|
||||||
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
||||||
|
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
||||||
|
using Stream stream = file.OpenReadStream();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var trajectoryRows = await trajectoryImportService.ImportAsync(idWell, idUser.Value, stream, token);
|
||||||
|
|
||||||
|
if (deleteBeforeImport)
|
||||||
|
await trajectoryRepository.DeleteByIdWellAsync(idWell, token);
|
||||||
|
|
||||||
|
var rowsCount = await trajectoryRepository.AddRangeAsync(trajectoryRows, token);
|
||||||
|
|
||||||
|
return Ok(rowsCount);
|
||||||
|
}
|
||||||
|
catch (FileFormatException ex)
|
||||||
|
{
|
||||||
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получаем список всех строк координат траектории (для клиента)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell">id скважины</param>
|
||||||
|
/// <param name="token"> Токен отмены задачи </param>
|
||||||
|
/// <returns>Список добавленных координат траектории</returns>
|
||||||
|
[HttpGet]
|
||||||
|
//[ProducesResponseType(typeof(IEnumerable<Tdto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public virtual async Task<IActionResult> GetAsync([FromRoute] int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
var result = await trajectoryRepository.GetAsync(idWell, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавить одну новую строчку координат для плановой траектории
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="row"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
|
[HttpPost]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> AddAsync(int idWell, [FromBody] Tdto row,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
var idUser = User.GetUserId();
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
row.IdUser = idUser.Value;
|
||||||
|
row.IdWell = idWell;
|
||||||
|
var result = await trajectoryRepository.AddAsync(row, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Добавить массив строчек координат для плановой траектории
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="rows"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>количество успешно записанных строк в БД</returns>
|
||||||
|
[HttpPost("range")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> AddRangeAsync(int idWell, [FromBody] IEnumerable<Tdto> rows,
|
||||||
|
CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
int? idUser = User.GetUserId();
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
foreach (var item in rows)
|
||||||
|
{
|
||||||
|
item.IdUser = idUser.Value;
|
||||||
|
item.IdWell = idWell;
|
||||||
|
}
|
||||||
|
var result = await trajectoryRepository.AddRangeAsync(rows, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Изменить выбранную строку с координатами
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idRow"></param>
|
||||||
|
/// <param name="row"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>количество успешно обновленных строк в БД</returns>
|
||||||
|
[HttpPut("{idRow}")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> UpdateAsync(int idWell, int idRow,
|
||||||
|
[FromBody] Tdto row, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
int? idUser = User.GetUserId();
|
||||||
|
if (!idUser.HasValue)
|
||||||
|
return Forbid();
|
||||||
|
row.Id = idRow;
|
||||||
|
row.IdUser = idUser.Value;
|
||||||
|
row.IdWell = idWell;
|
||||||
|
var result = await trajectoryRepository.UpdateAsync(row, token);
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Удалить выбранную строку с координатами
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idWell"></param>
|
||||||
|
/// <param name="idRow"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns>количество успешно удаленных строк из БД</returns>
|
||||||
|
[HttpDelete("{idRow}")]
|
||||||
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> DeleteAsync(int idWell, int idRow, CancellationToken token)
|
||||||
|
{
|
||||||
|
if (!await CanUserAccessToWellAsync(idWell,
|
||||||
|
token).ConfigureAwait(false))
|
||||||
|
return Forbid();
|
||||||
|
|
||||||
|
var result = await trajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token);
|
||||||
|
|
||||||
|
return Ok(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
||||||
|
{
|
||||||
|
int? idCompany = User.GetCompanyId();
|
||||||
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||||
|
idWell, token).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user