2021-08-24 10:59:10 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2024-01-24 09:21:07 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperationImport;
|
|
|
|
|
using AsbCloudApp.Data.WellOperationImport.Options;
|
|
|
|
|
using AsbCloudApp.Exceptions;
|
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;
|
2024-01-24 09:21:07 +05:00
|
|
|
|
using AsbCloudApp.Services.WellOperationImport;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
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;
|
2023-11-17 11:19:04 +05:00
|
|
|
|
using System.Linq;
|
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;
|
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;
|
2024-02-22 13:34:05 +05:00
|
|
|
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
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
|
|
|
|
|
2024-01-24 09:21:07 +05:00
|
|
|
|
public WellOperationController(IWellOperationRepository operationRepository,
|
|
|
|
|
IWellService wellService,
|
2023-09-04 14:11:25 +05:00
|
|
|
|
IWellOperationImportTemplateService wellOperationImportTemplateService,
|
|
|
|
|
IWellOperationExportService wellOperationExportService,
|
2023-09-05 16:23:40 +05:00
|
|
|
|
IWellOperationImportService wellOperationImportService,
|
2024-02-22 13:34:05 +05:00
|
|
|
|
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
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;
|
2024-02-22 13:34:05 +05:00
|
|
|
|
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
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
|
|
|
|
{
|
2024-02-22 13:34:05 +05:00
|
|
|
|
var result = wellOperationCategoryRepository.Get(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>
|
2024-02-22 13:34:05 +05:00
|
|
|
|
/// Статистика операций по скважине, группированная по категориям
|
2022-12-02 15:54:55 +05:00
|
|
|
|
/// </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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет новую операцию на скважину
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="idType">Тип добавляемой операции</param>
|
|
|
|
|
/// <param name="wellOperation">Добавляемая операция</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns>Количество добавленных в БД записей</returns>
|
|
|
|
|
[HttpPost("{idType:int}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> InsertAsync(
|
|
|
|
|
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell,
|
|
|
|
|
[Range(0, 1, ErrorMessage = "Тип операции недопустим. Допустимые: 0, 1")] int idType,
|
|
|
|
|
WellOperationDto wellOperation,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
|
|
|
|
return Forbid();
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
wellOperation.IdWell = idWell;
|
|
|
|
|
wellOperation.IdUser = User.GetUserId();
|
|
|
|
|
wellOperation.IdType = idType;
|
|
|
|
|
|
|
|
|
|
var result = await operationRepository.InsertRangeAsync(new[] { wellOperation }, cancellationToken);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 14:19:43 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет новые операции на скважине
|
|
|
|
|
/// </summary>
|
2023-11-17 11:19:04 +05:00
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="wellOperations">Добавляемые операции</param>
|
|
|
|
|
/// <param name="idType">Тип добавляемых операций</param>
|
|
|
|
|
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns>Количество добавленных в БД записей</returns>
|
|
|
|
|
[HttpPost("{idType:int}/{deleteBeforeInsert:bool}")]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-11-17 11:19:04 +05:00
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2023-03-23 11:11:54 +05:00
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(
|
2023-11-17 11:19:04 +05:00
|
|
|
|
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")] int idWell,
|
|
|
|
|
[Range(0, 1, ErrorMessage = "Тип операции недопустим. Допустимые: 0, 1")] int idType,
|
|
|
|
|
bool deleteBeforeInsert,
|
|
|
|
|
[FromBody] IEnumerable<WellOperationDto> wellOperations,
|
|
|
|
|
CancellationToken cancellationToken)
|
2021-08-16 14:19:43 +05:00
|
|
|
|
{
|
2023-11-17 11:19:04 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
2023-09-05 16:23:40 +05:00
|
|
|
|
return Forbid();
|
2023-11-17 11:19:04 +05:00
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
2021-08-16 14:19:43 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2023-12-08 15:56:00 +05:00
|
|
|
|
if (deleteBeforeInsert)
|
2023-04-04 12:52:11 +05:00
|
|
|
|
{
|
2023-11-17 11:19:04 +05:00
|
|
|
|
var existingOperations = await operationRepository.GetAsync(new WellOperationRequest
|
|
|
|
|
{
|
|
|
|
|
IdWell = idWell,
|
|
|
|
|
OperationType = idType
|
|
|
|
|
}, cancellationToken);
|
2022-12-21 18:02:22 +05:00
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
await operationRepository.DeleteAsync(existingOperations.Select(o => o.Id), cancellationToken);
|
|
|
|
|
}
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
foreach (var wellOperation in wellOperations)
|
|
|
|
|
{
|
|
|
|
|
wellOperation.IdWell = idWell;
|
|
|
|
|
wellOperation.IdUser = User.GetUserId();
|
|
|
|
|
wellOperation.IdType = idType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await operationRepository.InsertRangeAsync(wellOperations, cancellationToken);
|
|
|
|
|
|
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();
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-09-05 16:23:40 +05:00
|
|
|
|
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.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();
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-09-05 16:23:40 +05:00
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 13:11:28 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Импорт фактических операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
|
|
|
|
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("import/fact/default/{deleteBeforeInsert:bool}")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
[Permission]
|
|
|
|
|
public Task<IActionResult> ImportFactDefaultExcelFileAsync(int idWell,
|
|
|
|
|
[FromForm] IFormFileCollection files,
|
|
|
|
|
bool deleteBeforeInsert,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var options = new WellOperationImportDefaultOptionsDto
|
|
|
|
|
{
|
|
|
|
|
IdType = WellOperation.IdOperationTypeFact
|
|
|
|
|
};
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
2023-12-08 13:11:28 +05:00
|
|
|
|
return ImportExcelFileAsync(idWell, files, options,
|
|
|
|
|
(stream, _) => wellOperationDefaultExcelParser.Parse(stream, options),
|
|
|
|
|
deleteBeforeInsert,
|
|
|
|
|
cancellationToken);
|
|
|
|
|
}
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// <summary>
|
2023-12-08 13:11:28 +05:00
|
|
|
|
/// Импорт плановых операций из excel (xlsx) файла. Стандартный заполненный шаблон
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
2021-10-11 13:45:06 +05:00
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
2023-11-17 11:19:04 +05:00
|
|
|
|
/// <param name="cancellationToken"></param>
|
2021-10-09 20:16:22 +05:00
|
|
|
|
/// <returns></returns>
|
2023-12-08 13:11:28 +05:00
|
|
|
|
[HttpPost("import/plan/default")]
|
2023-11-17 11:19:04 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2022-01-19 11:42:26 +05:00
|
|
|
|
[Permission]
|
2023-12-08 13:11:28 +05:00
|
|
|
|
public Task<IActionResult> ImportPlanDefaultExcelFileAsync(int idWell,
|
2021-10-09 20:16:22 +05:00
|
|
|
|
[FromForm] IFormFileCollection files,
|
2023-12-08 13:11:28 +05:00
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
var options = new WellOperationImportDefaultOptionsDto
|
|
|
|
|
{
|
|
|
|
|
IdType = WellOperation.IdOperationTypePlan
|
|
|
|
|
};
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-12-08 13:11:28 +05:00
|
|
|
|
return ImportExcelFileAsync(idWell, files, options,
|
|
|
|
|
(stream, _) => wellOperationDefaultExcelParser.Parse(stream, options),
|
|
|
|
|
null,
|
|
|
|
|
cancellationToken);
|
|
|
|
|
}
|
2023-10-04 15:36:49 +05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Импорт операций из excel (xlsx) файла. ГПНХ (Хантос)
|
|
|
|
|
/// </summary>
|
2023-12-22 09:48:18 +05:00
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="options">Параметры парсинга</param>
|
2023-10-04 15:36:49 +05:00
|
|
|
|
/// <param name="files">Коллекция из одного файла xlsx</param>
|
2023-11-17 11:19:04 +05:00
|
|
|
|
/// <param name="cancellationToken"></param>
|
2023-10-04 15:36:49 +05:00
|
|
|
|
/// <returns></returns>
|
2023-12-08 13:11:28 +05:00
|
|
|
|
[HttpPost("import/plan/gazpromKhantos")]
|
2023-11-17 11:19:04 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationDto>), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
2023-10-04 15:36:49 +05:00
|
|
|
|
[Permission]
|
2023-12-08 13:11:28 +05:00
|
|
|
|
public Task<IActionResult> ImportPlanGazpromKhantosExcelFileAsync(int idWell,
|
2023-12-22 09:48:18 +05:00
|
|
|
|
[FromQuery] WellOperationImportGazpromKhantosOptionsDto options,
|
2023-11-17 11:19:04 +05:00
|
|
|
|
[FromForm] IFormFileCollection files,
|
2023-12-08 13:11:28 +05:00
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-12-22 09:48:18 +05:00
|
|
|
|
options.IdType = WellOperation.IdOperationTypePlan;
|
|
|
|
|
|
2023-12-08 13:11:28 +05:00
|
|
|
|
return ImportExcelFileAsync(idWell, files, options,
|
|
|
|
|
(stream, _) => wellOperationGazpromKhantosExcelParser.Parse(stream, options),
|
|
|
|
|
null,
|
|
|
|
|
cancellationToken);
|
|
|
|
|
}
|
2021-10-09 20:16:22 +05:00
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
|
|
|
|
|
2024-02-19 11:42:59 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет полые дубликаты операций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/api/well/wellOperations/RemoveDuplicates")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[Obsolete]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> RemoveDuplicates(CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await operationRepository.RemoveDuplicates((_, _) => { }, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет полностью пересекающиеся операции или "подрезает" более поздние их по глубине и дате.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="geDate"></param>
|
|
|
|
|
/// <param name="leDate"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("/api/well/wellOperations/TrimOverlapping")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[Obsolete]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> TrimOverlapping(DateTimeOffset? geDate, DateTimeOffset leDate, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var result = await operationRepository.TrimOverlapping(geDate, leDate, (_, _) => { }, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
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-12-08 13:11:28 +05:00
|
|
|
|
//TODO: deleteBeforeInsert тоже быстрый костыль
|
2023-11-17 11:19:04 +05:00
|
|
|
|
private async Task<IActionResult> ImportExcelFileAsync<TOptions>(int idWell, [FromForm] IFormFileCollection files,
|
|
|
|
|
TOptions options,
|
|
|
|
|
Func<Stream, TOptions, SheetDto> parseMethod,
|
2023-12-08 13:11:28 +05:00
|
|
|
|
bool? deleteBeforeInsert,
|
2023-11-17 11:19:04 +05:00
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
where TOptions : IWellOperationImportOptions
|
2023-10-04 15:36:49 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
var idUser = User.GetUserId();
|
|
|
|
|
|
|
|
|
|
if (!idCompany.HasValue || !idUser.HasValue)
|
|
|
|
|
throw new ForbidException("Неизвестный пользователь");
|
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
2023-10-04 15:36:49 +05:00
|
|
|
|
throw new ForbidException("Нет доступа к скважине");
|
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
2023-10-04 15:36:49 +05:00
|
|
|
|
throw new ForbidException("Недостаточно прав для редактирования ГГД на завершенной скважине");
|
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, cancellationToken))
|
2023-10-04 15:36:49 +05:00
|
|
|
|
throw new ForbidException("Скважина недоступна для компании");
|
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
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();
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var sheet = parseMethod(stream, options);
|
|
|
|
|
|
|
|
|
|
var wellOperations = wellOperationImportService.Import(idWell, idUser.Value, options.IdType, sheet)
|
|
|
|
|
.OrderBy(w => w.DateStart);
|
|
|
|
|
|
2023-12-08 15:56:00 +05:00
|
|
|
|
var dateStart = wellOperations.MinOrDefault(w => w.DateStart);
|
2023-11-17 11:19:04 +05:00
|
|
|
|
|
|
|
|
|
foreach (var wellOperation in wellOperations)
|
2023-12-08 15:56:00 +05:00
|
|
|
|
{
|
|
|
|
|
if (dateStart.HasValue)
|
|
|
|
|
wellOperation.Day = (wellOperation.DateStart - dateStart.Value).TotalDays;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-08 13:11:28 +05:00
|
|
|
|
//TODO: очень быстрый костыль
|
|
|
|
|
if (deleteBeforeInsert is not null && options.IdType == WellOperation.IdOperationTypeFact)
|
|
|
|
|
{
|
2024-01-24 09:21:07 +05:00
|
|
|
|
return await InsertRangeAsync(idWell, options.IdType,
|
|
|
|
|
deleteBeforeInsert.Value,
|
2023-12-08 13:11:28 +05:00
|
|
|
|
wellOperations,
|
|
|
|
|
cancellationToken);
|
|
|
|
|
}
|
2023-11-17 11:19:04 +05:00
|
|
|
|
|
|
|
|
|
return Ok(wellOperations);
|
|
|
|
|
}
|
|
|
|
|
catch (FileFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
return this.ValidationBadRequest(nameof(files), ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
2023-11-17 11:19:04 +05:00
|
|
|
|
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);
|
|
|
|
|
}
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
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;
|
2024-01-24 09:21:07 +05:00
|
|
|
|
|
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");
|
|
|
|
|
}
|
2021-08-13 17:25:06 +05:00
|
|
|
|
}
|
2023-11-17 11:19:04 +05:00
|
|
|
|
}
|