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;
|
2023-09-04 14:11:25 +05:00
|
|
|
|
using AsbCloudApp.Services.WellOperationImport;
|
2023-10-04 15:36:49 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperationImport.Options;
|
|
|
|
|
using AsbCloudApp.Exceptions;
|
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;
|
2023-09-04 14:11:25 +05:00
|
|
|
|
private readonly IWellOperationExportService wellOperationExportService;
|
|
|
|
|
private readonly IWellOperationImportTemplateService wellOperationImportTemplateService;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
private readonly IWellOperationImportService wellOperationImportService;
|
2023-10-04 15:36:49 +05:00
|
|
|
|
private readonly IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser;
|
|
|
|
|
private readonly IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser;
|
2023-09-05 16:23:40 +05:00
|
|
|
|
private readonly IUserRepository userRepository;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
|
2023-09-27 17:27:20 +05:00
|
|
|
|
public WellOperationController(IWellOperationRepository operationRepository,
|
2023-09-04 14:11:25 +05:00
|
|
|
|
IWellService wellService,
|
|
|
|
|
IWellOperationImportTemplateService wellOperationImportTemplateService,
|
|
|
|
|
IWellOperationExportService wellOperationExportService,
|
2023-09-05 16:23:40 +05:00
|
|
|
|
IWellOperationImportService wellOperationImportService,
|
2023-10-04 15:36:49 +05:00
|
|
|
|
IWellOperationExcelParser<WellOperationImportDefaultOptionsDto> wellOperationDefaultExcelParser,
|
|
|
|
|
IWellOperationExcelParser<WellOperationImportGazpromKhantosOptionsDto> wellOperationGazpromKhantosExcelParser,
|
2023-09-05 16:23:40 +05:00
|
|
|
|
IUserRepository userRepository)
|
2021-08-13 17:25:06 +05:00
|
|
|
|
{
|
2023-08-18 15:51:58 +05:00
|
|
|
|
this.operationRepository = operationRepository;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
this.wellService = wellService;
|
2023-09-04 14:11:25 +05:00
|
|
|
|
this.wellOperationImportTemplateService = wellOperationImportTemplateService;
|
|
|
|
|
this.wellOperationExportService = wellOperationExportService;
|
2021-10-09 20:16:22 +05:00
|
|
|
|
this.wellOperationImportService = wellOperationImportService;
|
2023-10-04 15:36:49 +05:00
|
|
|
|
this.wellOperationDefaultExcelParser = wellOperationDefaultExcelParser;
|
|
|
|
|
this.wellOperationGazpromKhantosExcelParser = wellOperationGazpromKhantosExcelParser;
|
2023-09-05 16:23:40 +05:00
|
|
|
|
this.userRepository = userRepository;
|
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
|
|
|
|
{
|
2023-09-05 16:23:40 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
2021-08-16 14:19:43 +05:00
|
|
|
|
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);
|
2023-08-18 15:51:58 +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
|
|
|
|
{
|
2023-09-05 16:23:40 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
2021-08-16 14:19:43 +05:00
|
|
|
|
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
|
|
|
|
{
|
2023-09-05 16:23:40 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
2021-08-16 14:19:43 +05:00
|
|
|
|
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>
|
2023-10-04 15:36:49 +05:00
|
|
|
|
/// Импорт операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2023-10-02 09:27:20 +05:00
|
|
|
|
/// <param name="options">Параметры для парсинга файла</param>
|
2021-10-11 13:45:06 +05:00
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
2023-10-02 09:27:20 +05:00
|
|
|
|
/// <param name="deleteBeforeImport">Удалить операции перед импортом = 1, если файл валидный</param>
|
|
|
|
|
/// <param name="token"></param>
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// <returns></returns>
|
2023-10-04 15:36:49 +05:00
|
|
|
|
[HttpPost("import/default/{deleteBeforeImport}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-10-04 15:36:49 +05:00
|
|
|
|
public async Task<IActionResult> ImportDefaultExcelFileAsync(int idWell,
|
|
|
|
|
[FromQuery] WellOperationImportDefaultOptionsDto options,
|
2021-10-09 20:16:22 +05:00
|
|
|
|
[FromForm] IFormFileCollection files,
|
2023-10-02 09:27:20 +05:00
|
|
|
|
[Range(0, 1, ErrorMessage = "Недопустимое значение. Допустимые: 0, 1")] int deleteBeforeImport,
|
2022-12-21 18:02:22 +05:00
|
|
|
|
CancellationToken token)
|
2021-10-09 20:16:22 +05:00
|
|
|
|
{
|
2023-09-04 14:11:25 +05:00
|
|
|
|
var idUser = User.GetUserId();
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
2023-10-04 15:36:49 +05:00
|
|
|
|
if (!idUser.HasValue)
|
|
|
|
|
throw new ForbidException("Неизвестный пользователь");
|
2023-09-05 16:23:40 +05:00
|
|
|
|
|
2023-10-04 15:36:49 +05:00
|
|
|
|
await AssertUserHasAccessToImportWellOperationsAsync(idWell, token);
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
|
|
|
|
if (files.Count < 1)
|
2023-09-28 17:42:30 +05:00
|
|
|
|
return this.ValidationBadRequest(nameof(files), "Нет файла");
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
|
|
|
|
var file = files[0];
|
2022-04-11 18:00:34 +05:00
|
|
|
|
if (Path.GetExtension(file.FileName).ToLower() != ".xlsx")
|
2023-09-28 17:42:30 +05:00
|
|
|
|
return this.ValidationBadRequest(nameof(files), "Требуется xlsx файл.");
|
2023-09-04 14:11:25 +05:00
|
|
|
|
|
2021-10-09 20:16:22 +05:00
|
|
|
|
using Stream stream = file.OpenReadStream();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
2023-10-04 15:36:49 +05:00
|
|
|
|
var sheet = wellOperationDefaultExcelParser.Parse(stream, options);
|
|
|
|
|
|
|
|
|
|
await wellOperationImportService.ImportAsync(idWell, idUser.Value, options.IdType, sheet, (deleteBeforeImport & 1) > 0, token);
|
|
|
|
|
}
|
|
|
|
|
catch (FileFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="options">Параметры для парсинга файла</param>
|
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
|
|
|
|
/// <param name="deleteBeforeImport">Удалить операции перед импортом = 1, если файл валидный</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("import/gazpromKhantos/{deleteBeforeImport}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> ImportGazpromKhantosExcelFileAsync(int idWell,
|
|
|
|
|
[FromQuery] WellOperationImportGazpromKhantosOptionsDto options,
|
|
|
|
|
[FromForm] IFormFileCollection files,
|
|
|
|
|
[Range(0, 1, ErrorMessage = "Недопустимое значение. Допустимые: 0, 1")] int deleteBeforeImport,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (!idUser.HasValue)
|
|
|
|
|
throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
|
|
|
|
|
await AssertUserHasAccessToImportWellOperationsAsync(idWell, token);
|
|
|
|
|
|
|
|
|
|
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 sheet = wellOperationGazpromKhantosExcelParser.Parse(stream, options);
|
|
|
|
|
|
|
|
|
|
await wellOperationImportService.ImportAsync(idWell, idUser.Value, options.IdType, sheet, (deleteBeforeImport & 1) > 0, token);
|
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
|
|
|
|
{
|
2023-09-28 17:42:30 +05:00
|
|
|
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
2021-10-09 20:16:22 +05:00
|
|
|
|
}
|
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();
|
|
|
|
|
|
2023-09-04 14:11:25 +05:00
|
|
|
|
var stream = await wellOperationExportService.ExportAsync(idWell, token);
|
2021-10-09 20:16:22 +05:00
|
|
|
|
var fileName = await wellService.GetWellCaptionByIdAsync(idWell, token) + "_operations.xlsx";
|
2023-08-10 12:08:02 +05:00
|
|
|
|
return File(stream, "application/octet-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
|
|
|
|
{
|
2023-09-04 14:11:25 +05:00
|
|
|
|
var stream = wellOperationImportTemplateService.GetExcelTemplateStream();
|
2021-10-11 13:45:06 +05:00
|
|
|
|
var fileName = "ЕЦП_шаблон_файла_операций.xlsx";
|
2023-08-10 12:08:02 +05:00
|
|
|
|
return File(stream, "application/octet-stream", fileName);
|
2021-10-11 13:45:06 +05:00
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 15:36:49 +05:00
|
|
|
|
private async Task AssertUserHasAccessToImportWellOperationsAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
var idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (!idCompany.HasValue || !idUser.HasValue)
|
|
|
|
|
throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
throw new ForbidException("Нет доступа к скважине");
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
|
|
|
|
throw new ForbidException("Недостаточно прав для редактирования ГГД на завершенной скважине");
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, token))
|
|
|
|
|
throw new ForbidException("Скважина недоступна для компании");
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 16:23:40 +05:00
|
|
|
|
private async Task<bool> CanUserEditWellOperationsAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idUser = User.GetUserId();
|
2023-09-13 11:42:44 +05:00
|
|
|
|
|
|
|
|
|
if (!idUser.HasValue)
|
|
|
|
|
return false;
|
2023-09-05 16:23:40 +05:00
|
|
|
|
|
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
|
|
|
|
|
2023-09-13 11:42:44 +05:00
|
|
|
|
if (well is null)
|
2023-09-05 16:23:40 +05:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
}
|