2021-08-24 10:59:10 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-12-28 17:38:53 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2022-12-21 18:02:22 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2021-08-24 10:59:10 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-02-20 15:17:49 +05:00
|
|
|
|
using System;
|
2021-08-24 10:59:10 +05:00
|
|
|
|
using System.Collections.Generic;
|
2023-03-23 11:11:54 +05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
using System.IO;
|
2021-08-24 10:59:10 +05:00
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2021-08-13 17:25:06 +05:00
|
|
|
|
/// <summary>
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// Буровые операции (вводимые вручную)
|
2021-08-13 17:25:06 +05:00
|
|
|
|
/// </summary>
|
2021-08-17 09:39:05 +05:00
|
|
|
|
[Route("api/well/{idWell}/wellOperations")]
|
2021-08-13 17:25:06 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellOperationController : ControllerBase
|
|
|
|
|
{
|
2022-12-28 17:38:53 +05:00
|
|
|
|
private readonly IWellOperationRepository operationRepository;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
private readonly IWellOperationImportService wellOperationImportService;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
|
2022-12-28 17:38:53 +05:00
|
|
|
|
public WellOperationController(IWellOperationRepository operationService, IWellService wellService, IWellOperationImportService wellOperationImportService)
|
2021-08-13 17:25:06 +05:00
|
|
|
|
{
|
2022-12-28 17:38:53 +05:00
|
|
|
|
this.operationRepository = operationService;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
this.wellService = wellService;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
this.wellOperationImportService = wellOperationImportService;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-22 17:09:26 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает словарь типов секций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("sectionTypes")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-07-19 16:39:17 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-12-22 17:09:26 +05:00
|
|
|
|
public IActionResult GetSectionTypes()
|
|
|
|
|
{
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = operationRepository.GetSectionTypes();
|
2021-12-22 17:09:26 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список имен типов операций на скважине
|
|
|
|
|
/// </summary>
|
2023-04-11 10:42:56 +05:00
|
|
|
|
/// <param name="includeParents">флаг, нужно ли включать родителей в список</param>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <returns></returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("categories")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-19 12:24:57 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-04-11 10:42:56 +05:00
|
|
|
|
public IActionResult GetCategories(bool includeParents = true)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
2023-04-11 10:42:56 +05:00
|
|
|
|
var result = operationRepository.GetCategories(includeParents);
|
2021-08-16 14:19:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-15 17:02:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список плановых операций для сопоставления
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2023-02-21 13:22:24 +05:00
|
|
|
|
/// <param name="currentDate">дата для нахождения последней сопоставленной плановой операции</param>
|
2023-02-16 09:51:55 +05:00
|
|
|
|
/// <param name="token"></param>
|
2023-02-15 17:02:43 +05:00
|
|
|
|
/// <returns></returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("operationsPlan")]
|
2023-02-21 13:22:24 +05:00
|
|
|
|
[ProducesResponseType(typeof(WellOperationPlanDto), (int)System.Net.HttpStatusCode.OK)]
|
2023-02-20 15:17:49 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationsPlanAsync(
|
|
|
|
|
[FromRoute] int idWell,
|
2023-02-21 13:22:24 +05:00
|
|
|
|
[FromQuery] DateTime currentDate,
|
2023-02-20 15:17:49 +05:00
|
|
|
|
CancellationToken token)
|
2023-02-15 17:02:43 +05:00
|
|
|
|
{
|
2023-02-16 09:51:55 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-02-15 17:02:43 +05:00
|
|
|
|
var result = await operationRepository
|
2023-02-20 15:17:49 +05:00
|
|
|
|
.GetOperationsPlanAsync(idWell, currentDate, token)
|
2023-02-15 17:02:43 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
2023-02-21 17:16:45 +05:00
|
|
|
|
/// Отфильтрованный список фактических операций на скважине.
|
|
|
|
|
/// Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2022-12-21 18:02:22 +05:00
|
|
|
|
/// <param name="request"></param>
|
2021-08-18 16:57:20 +05:00
|
|
|
|
/// <param name="token"></param>
|
2023-02-20 15:17:49 +05:00
|
|
|
|
/// <returns>Список операций на скважине</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("fact")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-02-20 15:17:49 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-02-21 17:16:45 +05:00
|
|
|
|
public async Task<IActionResult> GetPageOperationsFactAsync(
|
2021-08-28 22:34:57 +05:00
|
|
|
|
[FromRoute] int idWell,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
[FromQuery] WellOperationRequestBase request,
|
|
|
|
|
CancellationToken token)
|
2021-08-13 17:25:06 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-12-21 18:02:22 +05:00
|
|
|
|
var requestToService = new WellOperationRequest(request, idWell);
|
2023-02-20 15:17:49 +05:00
|
|
|
|
var result = await operationRepository.GetAsync(
|
2022-12-21 18:02:22 +05:00
|
|
|
|
requestToService,
|
2021-08-18 16:57:20 +05:00
|
|
|
|
token)
|
|
|
|
|
.ConfigureAwait(false);
|
2021-08-13 17:25:06 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-21 17:16:45 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Отфильтрованный список плановых операций на скважине.
|
|
|
|
|
/// Если не применять фильтр, то вернется весь список. Сортированный по глубине затем по дате
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Список операций на скважине в контейнере для постраничного просмотра</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("plan")]
|
2023-02-21 17:16:45 +05:00
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetPageOperationsPlanAsync(
|
|
|
|
|
[FromRoute] int idWell,
|
|
|
|
|
[FromQuery] WellOperationRequestBase request,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var requestToService = new WellOperationRequest(request, idWell);
|
|
|
|
|
var result = await operationRepository.GetPageAsync(
|
|
|
|
|
requestToService,
|
|
|
|
|
token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-02 15:54:55 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Статистика операций по скважине, группированая по категориям
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2022-12-21 18:02:22 +05:00
|
|
|
|
/// <param name="request"></param>
|
2022-12-02 15:54:55 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("groupStat")]
|
2022-12-02 15:54:55 +05:00
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetGroupOperationsAsync(
|
|
|
|
|
[FromRoute] int idWell,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
[FromQuery] WellOperationRequestBase request,
|
|
|
|
|
CancellationToken token)
|
2022-12-02 15:54:55 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-12-21 18:02:22 +05:00
|
|
|
|
var requestToService = new WellOperationRequest(request, idWell);
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = await operationRepository.GetGroupOperationsStatAsync(
|
2022-12-21 18:02:22 +05:00
|
|
|
|
requestToService,
|
2022-12-02 15:54:55 +05:00
|
|
|
|
token)
|
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает нужную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idOperation">id нужной операции</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Нужную операцию на скважине</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("{idOperation}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
2022-12-22 11:26:19 +05:00
|
|
|
|
public async Task<IActionResult> GetOrDefaultAsync(int idWell, int idOperation,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
CancellationToken token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = await operationRepository.GetOrDefaultAsync(idOperation, token).ConfigureAwait(false);
|
2021-08-16 14:19:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет новые операции на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="values">Данные о добавляемых операциях</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
2021-12-30 17:05:44 +05:00
|
|
|
|
/// <returns>Количество добавленных в БД строк</returns>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[HttpPost]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-03-23 11:11:54 +05:00
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(
|
2023-06-02 12:36:27 +05:00
|
|
|
|
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell,
|
2023-03-23 11:11:54 +05:00
|
|
|
|
[FromBody] IEnumerable<WellOperationDto> values,
|
|
|
|
|
CancellationToken token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-02-16 09:51:55 +05:00
|
|
|
|
foreach (var value in values)
|
2023-04-04 12:52:11 +05:00
|
|
|
|
{
|
2023-02-16 09:51:55 +05:00
|
|
|
|
value.IdWell = idWell;
|
2023-04-04 12:52:11 +05:00
|
|
|
|
value.LastUpdateDate = DateTimeOffset.UtcNow;
|
2023-06-02 12:36:27 +05:00
|
|
|
|
value.IdUser = User.GetUserId();
|
2023-04-04 12:52:11 +05:00
|
|
|
|
}
|
2022-12-21 18:02:22 +05:00
|
|
|
|
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = await operationRepository.InsertRangeAsync(values, token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
.ConfigureAwait(false);
|
2022-12-21 18:02:22 +05:00
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет выбранную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-12-30 17:05:44 +05:00
|
|
|
|
/// <param name="idOperation">id выбранной операции</param>
|
|
|
|
|
/// <param name="value">Новые данные для выбранной операции</param>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество обновленных в БД строк</returns>
|
|
|
|
|
[HttpPut("{idOperation}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)]
|
2021-08-24 10:59:10 +05:00
|
|
|
|
public async Task<IActionResult> UpdateAsync(int idWell, int idOperation,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
[FromBody] WellOperationDto value, CancellationToken token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-02-16 09:51:55 +05:00
|
|
|
|
value.IdWell = idWell;
|
2022-12-21 18:02:22 +05:00
|
|
|
|
value.Id = idOperation;
|
2023-04-04 12:52:11 +05:00
|
|
|
|
value.LastUpdateDate = DateTimeOffset.UtcNow;
|
|
|
|
|
value.IdUser = User.GetUserId();
|
2022-12-21 18:02:22 +05:00
|
|
|
|
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = await operationRepository.UpdateAsync(value, token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-12-30 17:05:44 +05:00
|
|
|
|
/// Удаляет выбранную операцию на скважине
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-12-30 17:05:44 +05:00
|
|
|
|
/// <param name="idOperation">id выбранной операции</param>
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество удаленных из БД строк</returns>
|
|
|
|
|
[HttpDelete("{idOperation}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2021-08-16 14:19:43 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
2022-12-21 18:02:22 +05:00
|
|
|
|
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell,
|
|
|
|
|
token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-12-28 17:38:53 +05:00
|
|
|
|
var result = await operationRepository.DeleteAsync(new int[] { idOperation }, token)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
.ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Импортирует операции из excel (xlsx) файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-10-11 13:45:06 +05:00
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
|
|
|
|
/// <param name="options">Удалить операции перед импортом = 1, если фал валидный</param>
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// <param name="token"> Токен отмены задачи </param>
|
|
|
|
|
/// <returns></returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpPost("import/{options}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2022-04-11 18:00:34 +05:00
|
|
|
|
public async Task<IActionResult> ImportAsync(int idWell,
|
2021-10-09 20:16:22 +05:00
|
|
|
|
[FromForm] IFormFileCollection files,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
int options,
|
|
|
|
|
CancellationToken token)
|
2021-10-09 20:16:22 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
int? idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null || idUser is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (files.Count < 1)
|
|
|
|
|
return BadRequest("нет файла");
|
|
|
|
|
|
|
|
|
|
var file = files[0];
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
2021-10-09 20:16:22 +05:00
|
|
|
|
return BadRequest("Требуется xlsx файл.");
|
|
|
|
|
using Stream stream = file.OpenReadStream();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-05-23 10:53:31 +05:00
|
|
|
|
wellOperationImportService.Import(idWell, stream, idUser.Value, (options & 1) > 0);
|
2021-10-09 20:16:22 +05:00
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
catch (FileFormatException ex)
|
2021-10-09 20:16:22 +05:00
|
|
|
|
{
|
|
|
|
|
return BadRequest(ex.Message);
|
|
|
|
|
}
|
2022-04-11 18:00:34 +05:00
|
|
|
|
|
2021-10-09 20:16:22 +05:00
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2021-10-11 13:45:06 +05:00
|
|
|
|
/// Создает excel файл с операциями по скважине
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2023-08-01 11:17:46 +05:00
|
|
|
|
/// <param name="token">Токен отмены задачи </param>
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// <returns>Запрашиваемый файл</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("export")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-08-01 11:17:46 +05:00
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
|
|
|
|
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
2022-12-21 18:02:22 +05:00
|
|
|
|
public async Task<IActionResult> ExportAsync([FromRoute] int idWell, CancellationToken token)
|
2021-10-09 20:16:22 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var stream = wellOperationImportService.Export(idWell);
|
|
|
|
|
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_operations.xlsx";
|
2023-08-01 11:17:46 +05:00
|
|
|
|
return File(stream, fileName);
|
2022-03-17 16:56:13 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает excel файл с "сетевым графиком"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="scheduleReportService"></param>
|
|
|
|
|
/// <param name="token"> Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Запрашиваемый файл</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("scheduleReport")]
|
2022-03-17 16:56:13 +05:00
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)]
|
2022-12-21 18:02:22 +05:00
|
|
|
|
public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell, [FromServices] IScheduleReportService scheduleReportService, CancellationToken token)
|
2022-03-17 16:56:13 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var stream = await scheduleReportService.MakeReportAsync(idWell, token);
|
|
|
|
|
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_ScheduleReport.xlsx";
|
|
|
|
|
return File(stream, "application/octet-stream", fileName);
|
2021-10-09 20:16:22 +05:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 13:45:06 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает шаблон файла импорта
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>Запрашиваемый файл</returns>
|
2023-08-08 12:21:09 +05:00
|
|
|
|
[HttpGet("template")]
|
2021-10-11 13:45:06 +05:00
|
|
|
|
[AllowAnonymous]
|
2023-08-01 11:17:46 +05:00
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK, "application/octet-stream")]
|
2023-04-07 16:49:28 +05:00
|
|
|
|
public IActionResult GetTemplate()
|
2021-10-11 13:45:06 +05:00
|
|
|
|
{
|
|
|
|
|
var stream = wellOperationImportService.GetExcelTemplateStream();
|
|
|
|
|
var fileName = "ЕЦП_шаблон_файла_операций.xlsx";
|
2023-08-01 11:17:46 +05:00
|
|
|
|
return File(stream, fileName);
|
2021-10-11 13:45:06 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-22 11:26:19 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
2021-08-13 17:25:06 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2021-08-13 17:25:06 +05:00
|
|
|
|
}
|