2024-07-04 11:02:45 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2024-02-21 15:08:51 +05:00
|
|
|
|
using AsbCloudApp.Data.ProcessMaps;
|
2022-10-19 13:56:34 +05:00
|
|
|
|
using AsbCloudApp.Repositories;
|
2021-10-12 12:17:46 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
namespace AsbCloudWebApi.Controllers;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Композитная скважина
|
|
|
|
|
/// </summary>
|
|
|
|
|
[Route("api/well/{idWell}/composite")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class WellCompositeController : ControllerBase
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
private readonly IWellCompositeRepository wellCompositeRepository;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public WellCompositeController(IWellCompositeRepository wellCompositeRepository,
|
|
|
|
|
IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.wellCompositeRepository = wellCompositeRepository;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// <summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// Получает композитную скважину для скважины
|
2022-06-16 17:37:10 +05:00
|
|
|
|
/// </summary>
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <param name="idWell">id скважины для которой собрана композитная скважина</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellCompositeDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetAsync(int idWell, CancellationToken token)
|
2021-10-12 12:17:46 +05:00
|
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2021-10-12 12:17:46 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = await wellCompositeRepository.GetAsync(idWell, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2021-10-12 12:17:46 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Создает или заменяет композитную скважину для скважины с idWell
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell">id скважины для которой собрана композитная скважина</param>
|
|
|
|
|
/// <param name="wellComposites">Секции композитной скважины</param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[Permission]
|
|
|
|
|
public async Task<IActionResult> SaveAsync(int idWell, IEnumerable<WellCompositeDto> wellComposites, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2021-10-12 12:17:46 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = await wellCompositeRepository.SaveAsync(idWell, wellComposites, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2023-01-26 15:37:46 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение РТК по композитной скважине
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="idWell"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("compositeProcessMap")]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<ProcessMapPlanBaseDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetCompositeProcessMap(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
|
|
|
|
|
return Forbid();
|
2023-01-26 10:59:24 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +05:00
|
|
|
|
var result = await wellCompositeRepository.GetCompositeProcessMap(idWell, token).ConfigureAwait(false);
|
|
|
|
|
return Ok(result);
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|
2023-05-19 16:51:41 +05:00
|
|
|
|
|
2024-08-19 10:01:07 +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);
|
|
|
|
|
}
|
2021-10-12 12:17:46 +05:00
|
|
|
|
}
|