2024-05-17 16:40:31 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.ProcessMaps;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
using AsbCloudApp.Exceptions;
|
2024-05-17 16:40:31 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2024-03-14 15:18:02 +05:00
|
|
|
|
using AsbCloudApp.Requests.ExportOptions;
|
2024-05-17 16:40:31 +05:00
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
|
|
|
|
using AsbCloudApp.Services;
|
2024-03-22 09:37:06 +05:00
|
|
|
|
using AsbCloudApp.Services.Export;
|
|
|
|
|
using AsbCloudApp.Services.Parsers;
|
2024-06-04 16:55:44 +05:00
|
|
|
|
using AsbCloudDb.Model.ProcessMapPlan;
|
2024-05-17 16:40:31 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
2024-02-21 15:08:51 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers.ProcessMaps;
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-02-21 15:08:51 +05:00
|
|
|
|
/// РТК план базовый
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/well/{idWell}/[controller]")]
|
|
|
|
|
[Authorize]
|
2024-06-04 16:55:44 +05:00
|
|
|
|
public abstract class ProcessMapPlanBaseController<TEntity, TDto> : ControllerBase
|
|
|
|
|
where TEntity : ProcessMapPlanBase
|
2024-02-21 15:08:51 +05:00
|
|
|
|
where TDto : ProcessMapPlanBaseDto
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-06-05 12:08:38 +05:00
|
|
|
|
private readonly IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2024-03-14 10:30:25 +05:00
|
|
|
|
private readonly IParserService<TDto, WellRelatedParserRequest> parserService;
|
2024-05-17 16:40:31 +05:00
|
|
|
|
private readonly ITelemetryService telemetryService;
|
2024-03-14 15:18:02 +05:00
|
|
|
|
private readonly IExportService<WellRelatedExportRequest> processMapPlanExportService;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
|
2024-06-05 12:08:38 +05:00
|
|
|
|
protected ProcessMapPlanBaseController(IChangeLogRepository<TDto, ProcessMapPlanBaseRequestWithWell> repository,
|
2024-02-21 15:08:51 +05:00
|
|
|
|
IWellService wellService,
|
2024-03-14 10:30:25 +05:00
|
|
|
|
IParserService<TDto, WellRelatedParserRequest> parserService,
|
2024-05-17 16:40:31 +05:00
|
|
|
|
IExportService<WellRelatedExportRequest> processMapPlanExportService,
|
|
|
|
|
ITelemetryService telemetryService)
|
2024-02-21 15:08:51 +05:00
|
|
|
|
{
|
|
|
|
|
this.repository = repository;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.parserService = parserService;
|
2024-05-17 16:40:31 +05:00
|
|
|
|
this.telemetryService = telemetryService;
|
2024-03-14 10:30:25 +05:00
|
|
|
|
this.processMapPlanExportService = processMapPlanExportService;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected abstract string TemplateFileName { get; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// Добавление
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-17 16:40:31 +05:00
|
|
|
|
public async Task<IActionResult> InsertRange([FromRoute][Range(0, int.MaxValue)] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-20 15:38:37 +05:00
|
|
|
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
2024-03-11 16:26:58 +05:00
|
|
|
|
|
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
|
|
2024-01-20 15:38:37 +05:00
|
|
|
|
var result = await repository.InsertRange(idUser, dtos, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить все по скважине и добавить новые
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("replace")]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-01-20 15:38:37 +05:00
|
|
|
|
public async Task<IActionResult> ClearAndInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-20 15:38:37 +05:00
|
|
|
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
|
2024-03-11 16:26:58 +05:00
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
|
|
|
|
|
var result = await repository.ClearAndInsertRange(idUser, request, dtos, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-31 13:37:48 +05:00
|
|
|
|
/// Пометить записи как удаленные
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="ids"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-31 13:37:48 +05:00
|
|
|
|
public async Task<IActionResult> MarkAsDeleted([FromRoute] int idWell, IEnumerable<int> ids, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-20 15:38:37 +05:00
|
|
|
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
|
2024-05-31 13:37:48 +05:00
|
|
|
|
var result = await repository.MarkAsDeleted(idUser, ids, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Очистка
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpDelete("clear")]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> Clear([FromRoute] int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
|
|
|
|
|
|
|
|
|
var request = new ProcessMapPlanBaseRequestWithWell(idWell);
|
|
|
|
|
var result = await repository.Clear(idUser, request, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// <summary>
|
2024-05-31 13:37:48 +05:00
|
|
|
|
/// Получение текущих записей по параметрам
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-31 13:37:48 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<TDto>>> GetCurrent([FromRoute] int idWell, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-22 13:16:39 +05:00
|
|
|
|
await AssertUserHasAccessToWell(idWell, token);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
|
2024-05-17 16:40:31 +05:00
|
|
|
|
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
|
2024-06-04 16:55:44 +05:00
|
|
|
|
|
2024-05-31 11:53:58 +05:00
|
|
|
|
var result = await repository.GetCurrent(serviceRequest, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-17 16:40:31 +05:00
|
|
|
|
/// <summary>
|
2024-05-31 13:37:48 +05:00
|
|
|
|
/// Получение измененных записей за определенную дату по ключу скважины
|
2024-05-17 16:40:31 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="moment"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-31 15:58:28 +05:00
|
|
|
|
[HttpGet("changelogByMoment")]
|
2024-05-17 16:40:31 +05:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-31 15:58:28 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetChangeLogByMoment([FromRoute] int idWell, DateTimeOffset? moment, CancellationToken token)
|
2024-05-17 16:40:31 +05:00
|
|
|
|
{
|
|
|
|
|
await AssertUserHasAccessToWell(idWell, token);
|
|
|
|
|
|
2024-06-04 16:55:44 +05:00
|
|
|
|
var dataRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
|
2024-05-17 16:40:31 +05:00
|
|
|
|
|
2024-05-31 15:58:28 +05:00
|
|
|
|
var changeLogRequest = new ChangeLogRequest()
|
|
|
|
|
{
|
|
|
|
|
Moment = moment
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-05 15:52:40 +05:00
|
|
|
|
var builder = repository
|
|
|
|
|
.GetQueryBuilder(changeLogRequest)
|
|
|
|
|
.ApplyRequest(dataRequest);
|
2024-06-04 16:55:44 +05:00
|
|
|
|
|
2024-06-05 15:52:40 +05:00
|
|
|
|
var dtos = await builder.GetChangeLogData(token);
|
2024-06-04 16:55:44 +05:00
|
|
|
|
|
|
|
|
|
return Ok(dtos);
|
2024-05-17 16:40:31 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-05-31 13:37:48 +05:00
|
|
|
|
/// Получение записей за определенную дату по uid
|
2024-05-17 16:40:31 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="uid"></param>
|
|
|
|
|
/// <param name="updateFrom"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-29 17:55:01 +05:00
|
|
|
|
[AllowAnonymous]
|
2024-05-17 16:40:31 +05:00
|
|
|
|
[HttpGet("/api/telemetry/{uid}/[controller]")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-29 17:55:01 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetByUid(string uid, DateTimeOffset? updateFrom, CancellationToken token)
|
2024-05-17 16:40:31 +05:00
|
|
|
|
{
|
|
|
|
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid) ?? -1;
|
|
|
|
|
|
|
|
|
|
if (idWell < 0)
|
|
|
|
|
return this.ValidationBadRequest(nameof(uid), "Скважина по uid не найдена");
|
|
|
|
|
|
2024-05-31 13:40:39 +05:00
|
|
|
|
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell)
|
2024-05-17 16:40:31 +05:00
|
|
|
|
{
|
|
|
|
|
UpdateFrom = updateFrom,
|
2024-05-31 13:40:39 +05:00
|
|
|
|
};
|
2024-05-17 16:40:31 +05:00
|
|
|
|
|
2024-05-31 15:58:28 +05:00
|
|
|
|
var result = await repository.GetChangeLogForDate(serviceRequest, null, token);
|
2024-05-17 16:40:31 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Изменения за определенную дату
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="date"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-05-31 15:58:28 +05:00
|
|
|
|
[HttpGet("changeLogForDate")]
|
2024-01-19 17:48:45 +05:00
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-05-31 15:58:28 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<ChangeLogDto<TDto>>>> GetChangeLogForDate([FromRoute] int idWell, [FromQuery] DateOnly? date, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-20 15:38:37 +05:00
|
|
|
|
await AssertUserHasAccessToWell(idWell, token);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
|
|
|
|
|
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
|
2024-05-31 15:58:28 +05:00
|
|
|
|
var result = await repository.GetChangeLogForDate(serviceRequest, date, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Даты за которые есть изменения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("dates")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-01-20 15:38:37 +05:00
|
|
|
|
public async Task<ActionResult<IEnumerable<DateOnly>>> GetDatesChange([FromRoute] int idWell, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-01-20 15:38:37 +05:00
|
|
|
|
await AssertUserHasAccessToWell(idWell, token);
|
2024-01-29 12:25:58 +05:00
|
|
|
|
|
|
|
|
|
var serviceRequest = new ProcessMapPlanBaseRequestWithWell(idWell);
|
|
|
|
|
var result = await repository.GetDatesChange(serviceRequest, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2024-01-29 12:25:58 +05:00
|
|
|
|
/// Редактирование или добавление [для пакетного редактирования]
|
2024-01-19 17:48:45 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-01-29 12:25:58 +05:00
|
|
|
|
[HttpPut()]
|
2024-01-19 17:48:45 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2024-01-29 12:25:58 +05:00
|
|
|
|
public async Task<IActionResult> UpdateOrInsertRange([FromRoute] int idWell, IEnumerable<TDto> dtos, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
2024-03-11 16:26:58 +05:00
|
|
|
|
if (!dtos.Any())
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return NoContent();
|
2024-05-17 16:40:31 +05:00
|
|
|
|
|
2024-01-20 15:38:37 +05:00
|
|
|
|
var idUser = await AssertUserHasAccessToWell(idWell, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
2024-03-11 16:26:58 +05:00
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
|
|
2024-01-29 12:25:58 +05:00
|
|
|
|
var result = await repository.UpdateOrInsertRange(idUser, dtos, token);
|
2024-01-19 17:48:45 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2024-02-21 15:08:51 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Импорт РТК из excel (xlsx) файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
2024-03-11 14:50:43 +05:00
|
|
|
|
/// <param name="file"></param>
|
2024-02-21 15:08:51 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("parse")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<ActionResult<ParserResultDto<TDto>>> Parse(int idWell,
|
2024-05-17 16:40:31 +05:00
|
|
|
|
[Required] IFormFile file,
|
2024-02-21 15:08:51 +05:00
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
await AssertUserHasAccessToWell(idWell, token);
|
|
|
|
|
|
2024-03-11 14:50:43 +05:00
|
|
|
|
var stream = file.GetExcelFile();
|
2024-02-21 15:08:51 +05:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2024-03-12 12:02:03 +05:00
|
|
|
|
var options = new WellRelatedParserRequest(idWell);
|
|
|
|
|
var dto = parserService.Parse(stream, options);
|
2024-05-17 16:40:31 +05:00
|
|
|
|
|
2024-02-21 15:08:51 +05:00
|
|
|
|
return Ok(dto);
|
|
|
|
|
}
|
|
|
|
|
catch (FileFormatException ex)
|
|
|
|
|
{
|
2024-03-11 14:50:43 +05:00
|
|
|
|
return this.ValidationBadRequest(nameof(file), ex.Message);
|
2024-02-21 15:08:51 +05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение шаблона для заполнения РТК
|
|
|
|
|
/// </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 = parserService.GetTemplateFile();
|
|
|
|
|
return File(stream, "application/octet-stream", TemplateFileName);
|
|
|
|
|
}
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// returns user id, if he has access to well
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ForbidException"></exception>
|
2024-01-20 15:38:37 +05:00
|
|
|
|
private async Task<int> AssertUserHasAccessToWell(int idWell, CancellationToken token)
|
2024-01-19 17:48:45 +05:00
|
|
|
|
{
|
|
|
|
|
var idUser = GetUserId();
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (!idCompany.HasValue)
|
|
|
|
|
throw new ForbidException("Нет доступа к скважине");
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, token))
|
|
|
|
|
throw new ForbidException("Нет доступа к скважине");
|
|
|
|
|
return idUser;
|
|
|
|
|
}
|
2024-05-17 16:40:31 +05:00
|
|
|
|
|
2024-03-14 10:30:25 +05:00
|
|
|
|
/// <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)
|
|
|
|
|
{
|
2024-03-14 15:18:02 +05:00
|
|
|
|
var exportOptions = new WellRelatedExportRequest(idWell);
|
|
|
|
|
var (fileName, file) = await processMapPlanExportService.ExportAsync(exportOptions, token);
|
2024-03-14 10:30:25 +05:00
|
|
|
|
return File(file, "application/octet-stream", fileName);
|
|
|
|
|
}
|
2024-01-19 17:48:45 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// returns user id or throw
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
/// <exception cref="ForbidException"></exception>
|
|
|
|
|
private int GetUserId()
|
|
|
|
|
{
|
|
|
|
|
var idUser = User.GetUserId() ?? throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
return idUser;
|
|
|
|
|
}
|
2024-02-09 11:32:31 +05:00
|
|
|
|
}
|