2024-07-04 11:02:45 +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;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
using AsbCloudApp.Data.WellOperation;
|
|
|
|
|
using AsbCloudApp.Requests.ExportOptions;
|
|
|
|
|
using AsbCloudApp.Requests.ParserOptions;
|
|
|
|
|
using AsbCloudDb.Model;
|
|
|
|
|
using AsbCloudInfrastructure.Services.WellOperations.Factories;
|
2024-05-15 17:22:52 +05:00
|
|
|
|
using System.Linq;
|
2021-08-13 17:25:06 +05:00
|
|
|
|
|
2024-03-22 12:42:48 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2024-03-22 12:42:48 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Буровые операции (вводимые вручную)
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well/{idWell}/wellOperations")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellOperationController : ControllerBase
|
|
|
|
|
{
|
2024-04-10 12:21:11 +05:00
|
|
|
|
private readonly IDictionary<int, string> templateNames = new Dictionary<int, string>
|
|
|
|
|
{
|
|
|
|
|
{ WellOperation.IdOperationTypeFact, "ЕЦП_шаблон_файла_фактические_операции.xlsx" },
|
|
|
|
|
{ WellOperation.IdOperationTypePlan, "ЕЦП_шаблон_файла_плановые_операции.xlsx" }
|
|
|
|
|
};
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
private readonly IUserRepository userRepository;
|
|
|
|
|
private readonly IWellOperationRepository wellOperationRepository;
|
|
|
|
|
private readonly IWellOperationCategoryRepository wellOperationCategoryRepository;
|
|
|
|
|
private readonly IWellService wellService;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
private readonly WellOperationParserFactory wellOperationParserFactory;
|
|
|
|
|
private readonly WellOperationExportServiceFactory wellOperationExportServiceFactory;
|
2024-04-10 12:24:20 +05:00
|
|
|
|
|
2024-04-09 15:12:40 +05:00
|
|
|
|
public WellOperationController(IWellOperationRepository wellOperationRepository,
|
2024-04-10 12:21:11 +05:00
|
|
|
|
IWellOperationCategoryRepository wellOperationCategoryRepository,
|
|
|
|
|
IWellService wellService,
|
|
|
|
|
IUserRepository userRepository,
|
|
|
|
|
WellOperationParserFactory wellOperationParserFactory,
|
|
|
|
|
WellOperationExportServiceFactory wellOperationExportServiceFactory)
|
|
|
|
|
{
|
|
|
|
|
this.wellOperationRepository = wellOperationRepository;
|
|
|
|
|
this.wellOperationCategoryRepository = wellOperationCategoryRepository;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
this.userRepository = userRepository;
|
|
|
|
|
this.wellOperationParserFactory = wellOperationParserFactory;
|
|
|
|
|
this.wellOperationExportServiceFactory = wellOperationExportServiceFactory;
|
2024-04-09 15:12:40 +05:00
|
|
|
|
}
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Добавляет новые операции на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">Id скважины</param>
|
|
|
|
|
/// <param name="dtos">Добавляемые операции</param>
|
|
|
|
|
/// <param name="deleteBeforeInsert">Удалить операции перед сохранением</param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns>Количество добавленных в БД записей</returns>
|
|
|
|
|
[HttpPost("{deleteBeforeInsert:bool}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> InsertRangeAsync(
|
|
|
|
|
[Range(1, int.MaxValue, ErrorMessage = "Id скважины не может быть меньше 1")]
|
|
|
|
|
int idWell,
|
|
|
|
|
bool deleteBeforeInsert,
|
|
|
|
|
[FromBody] IEnumerable<WellOperationDto> dtos,
|
|
|
|
|
CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, cancellationToken))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, cancellationToken))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
{
|
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
|
dto.LastUpdateDate = null;
|
|
|
|
|
dto.IdUser = User.GetUserId();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await wellOperationRepository.InsertRangeAsync(dtos, deleteBeforeInsert, cancellationToken);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Обновляет выбранную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="dtos"></param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество обновленных в БД строк</returns>
|
|
|
|
|
[HttpPut]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> UpdateRangeAsync(int idWell,
|
|
|
|
|
[FromBody] IEnumerable<WellOperationDto> dtos,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
foreach (var dto in dtos)
|
|
|
|
|
{
|
|
|
|
|
dto.IdWell = idWell;
|
|
|
|
|
dto.IdUser = User.GetUserId();
|
|
|
|
|
dto.LastUpdateDate = DateTimeOffset.UtcNow;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = await wellOperationRepository.UpdateRangeAsync(dtos, token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает словарь типов секций
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("sectionTypes")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellSectionTypeDto>), StatusCodes.Status200OK)]
|
|
|
|
|
public IActionResult GetSectionTypes()
|
|
|
|
|
{
|
|
|
|
|
var result = wellOperationRepository.GetSectionTypes();
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Статистика операций по скважине, группированная по категориям
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("groupStat")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellGroupOpertionDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetGroupOperationsAsync(
|
|
|
|
|
[FromRoute] int idWell,
|
|
|
|
|
[FromQuery] WellOperationRequestBase request,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var requestToservice = new WellOperationRequest(request, new[] { idWell });
|
|
|
|
|
|
|
|
|
|
var result = await wellOperationRepository.GetGroupOperationsStatAsync(requestToservice, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает список имен типов операций на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="includeParents">флаг, нужно ли включать родителей в список</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), StatusCodes.Status200OK)]
|
|
|
|
|
public IActionResult GetCategories(bool includeParents = true)
|
|
|
|
|
{
|
2024-04-10 15:05:15 +05:00
|
|
|
|
var result = wellOperationCategoryRepository.Get(includeParents, false);
|
2024-04-10 12:21:11 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Постраничный список операций на скважине.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Список операций на скважине</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
2024-07-18 09:10:06 +05:00
|
|
|
|
public async Task<IActionResult> GetPageAsync(
|
2024-04-10 12:21:11 +05:00
|
|
|
|
[FromRoute] int idWell,
|
|
|
|
|
[FromQuery] WellOperationRequestBase request,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var requestToService = new WellOperationRequest(request, new[] { idWell });
|
|
|
|
|
|
|
|
|
|
var result = await wellOperationRepository.GetPageAsync(requestToService, token);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 09:38:53 +05:00
|
|
|
|
/// <summary>
|
2024-07-18 09:10:06 +05:00
|
|
|
|
/// Получение страницу с нужной операцией
|
2024-07-10 09:38:53 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="id">id операции</param>
|
2024-07-12 12:02:38 +05:00
|
|
|
|
/// <param name="operationType">тип получаемых операций</param>
|
|
|
|
|
/// <param name="take">кол-во записей на странице</param>
|
|
|
|
|
/// <param name="sortFields">параметры сортировки страниц</param>
|
2024-07-10 09:38:53 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
2024-07-18 09:10:06 +05:00
|
|
|
|
[HttpGet("getPageWithOperation")]
|
2024-07-10 09:38:53 +05:00
|
|
|
|
[Permission]
|
2024-07-30 15:07:15 +05:00
|
|
|
|
[ProducesResponseType(typeof(PaginationContainer<WellOperationDto>), StatusCodes.Status200OK)]
|
2024-07-18 09:10:06 +05:00
|
|
|
|
public async Task<IActionResult> GetPageWithOperationAsync([FromRoute] int idWell,
|
|
|
|
|
int id,
|
2024-07-12 12:02:38 +05:00
|
|
|
|
int operationType,
|
|
|
|
|
int? take,
|
|
|
|
|
[FromQuery] IEnumerable<string>? sortFields,
|
|
|
|
|
CancellationToken token)
|
2024-07-10 09:38:53 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2024-07-30 15:07:15 +05:00
|
|
|
|
var paginationContainer = await wellOperationRepository.GetPageAsync(idWell, id, operationType, take, sortFields, token);
|
2024-07-10 09:38:53 +05:00
|
|
|
|
|
2024-07-30 15:07:15 +05:00
|
|
|
|
if (paginationContainer == null)
|
2024-07-10 09:38:53 +05:00
|
|
|
|
return NoContent();
|
2024-07-30 15:07:15 +05:00
|
|
|
|
|
|
|
|
|
return Ok(paginationContainer);
|
2024-07-10 09:38:53 +05:00
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает excel файл с "сетевым графиком"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="scheduleReportService"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns>Запрашиваемый файл</returns>
|
|
|
|
|
[HttpGet("scheduleReport")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> ScheduleReportAsync([FromRoute] int idWell,
|
|
|
|
|
[FromServices] IScheduleReportService scheduleReportService,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
|
|
|
|
|
if (idCompany is null)
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await wellService.IsCompanyInvolvedInWellAsync(idCompany.Value, idWell, token))
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет выбранную операцию на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="idOperation">id выбранной операции</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество удаленных из БД строк</returns>
|
|
|
|
|
[HttpDelete("{idOperation}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> DeleteAsync(int idWell, int idOperation, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var result = await wellOperationRepository.DeleteRangeAsync(new[] { idOperation }, token);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-15 17:11:56 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удаляет выбранные операции по скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины</param>
|
|
|
|
|
/// <param name="ids">ids выбранных операций</param>
|
|
|
|
|
/// <param name="token">Токен отмены задачи</param>
|
|
|
|
|
/// <returns>Количество удаленных из БД строк</returns>
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
[ProducesResponseType(typeof(int), StatusCodes.Status200OK)]
|
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest)]
|
|
|
|
|
public async Task<IActionResult> DeleteRangeAsync([FromRoute] int idWell, IEnumerable<int> ids, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2024-05-15 17:22:52 +05:00
|
|
|
|
if (!ids.Any())
|
|
|
|
|
return this.ValidationBadRequest(nameof(ids), "Пустой список операций");
|
|
|
|
|
|
2024-05-15 17:11:56 +05:00
|
|
|
|
var result = await wellOperationRepository.DeleteRangeAsync(ids, token);
|
|
|
|
|
|
2024-05-15 17:22:52 +05:00
|
|
|
|
if(result == ICrudRepository<WellOperationDto>.ErrorIdNotFound)
|
|
|
|
|
return this.ValidationBadRequest(nameof(ids), "Минимум одна из операций не найдена в базе");
|
|
|
|
|
|
2024-05-15 17:11:56 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Формирование excel файла с операциями на скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="idType"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("export")]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
|
|
|
|
public async Task<IActionResult> ExportAsync(int idWell,
|
|
|
|
|
int idType,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var options = new WellOperationExportRequest(idWell, idType);
|
|
|
|
|
var exportService = wellOperationExportServiceFactory.CreateExportService<WellOperationExportRequest>(idType);
|
|
|
|
|
|
|
|
|
|
var (fileName, file) = await exportService.ExportAsync(options, token);
|
|
|
|
|
|
|
|
|
|
return File(file, "application/octet-stream", fileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Парсинг ГГД из excel (xlsx) файла
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="idType"></param>
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost("parse/{idType}")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(ParserResultDto<WellOperationDto>), StatusCodes.Status200OK)]
|
|
|
|
|
public async Task<IActionResult> ParseAsync(int idWell,
|
|
|
|
|
int idType,
|
|
|
|
|
[Required] IFormFile file,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
if (!await CanUserEditWellOperationsAsync(idWell, token))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var stream = file.GetExcelFile();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var timezone = wellService.GetTimezone(idWell);
|
|
|
|
|
var options = new WellOperationParserRequest(idWell, idType, timezone);
|
|
|
|
|
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
|
|
|
|
var result = parser.Parse(stream, options);
|
|
|
|
|
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
catch (FileFormatException ex)
|
|
|
|
|
{
|
|
|
|
|
return this.ValidationBadRequest(nameof(file), ex.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение шаблона для заполнения ГГД
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("template")]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[ProducesResponseType(typeof(PhysicalFileResult), StatusCodes.Status200OK, "application/octet-stream")]
|
2024-04-10 12:19:32 +05:00
|
|
|
|
public IActionResult GetTemplate(int idType)
|
|
|
|
|
{
|
2024-04-10 12:21:11 +05:00
|
|
|
|
var parser = wellOperationParserFactory.CreateParser<WellOperationParserRequest>(idType);
|
|
|
|
|
var stream = parser.GetTemplateFile();
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
return File(stream, "application/octet-stream", templateNames[idType]);
|
|
|
|
|
}
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
|
|
|
idWell, token).ConfigureAwait(false);
|
|
|
|
|
}
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
private async Task<bool> CanUserEditWellOperationsAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idUser = User.GetUserId();
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
if (!idUser.HasValue)
|
|
|
|
|
return false;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
var well = await wellService.GetOrDefaultAsync(idWell, token);
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
if (well is null)
|
|
|
|
|
return false;
|
2024-03-22 12:42:48 +05:00
|
|
|
|
|
2024-04-10 12:21:11 +05:00
|
|
|
|
return well.IdState != 2 || userRepository.HasPermission(idUser.Value, "WellOperation.editCompletedWell");
|
|
|
|
|
}
|
2023-11-17 11:19:04 +05:00
|
|
|
|
}
|