2022-04-28 15:04:13 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
2022-06-15 14:57:37 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2022-06-17 17:21:14 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
2022-06-17 17:21:14 +05:00
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
using System.Threading;
|
2022-06-15 14:57:37 +05:00
|
|
|
|
using System.Threading.Tasks;
|
2022-04-28 15:04:13 +05:00
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers.SAUB
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Операции определенные по телеметрии САУБ
|
|
|
|
|
/// </summary>
|
2022-06-17 17:21:14 +05:00
|
|
|
|
[Route("api/[controller]")]
|
2022-04-28 15:04:13 +05:00
|
|
|
|
[ApiController]
|
2022-06-17 17:21:14 +05:00
|
|
|
|
[Authorize]
|
2022-04-28 15:04:13 +05:00
|
|
|
|
public class DetectedOperationController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly IDetectedOperationService detectedOperationService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public DetectedOperationController(IDetectedOperationService detectedOperationService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.detectedOperationService = detectedOperationService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2022-06-17 17:21:14 +05:00
|
|
|
|
/// получить справочник операций. Отличается от операций заводимых вручную.
|
|
|
|
|
/// При задании id скважины вернет только те операции, которые определились в телеметрии этой скважины.
|
2022-04-28 15:04:13 +05:00
|
|
|
|
/// </summary>
|
2022-06-17 17:21:14 +05:00
|
|
|
|
/// <param name="idWell">[опционально] id скважины</param>
|
2022-04-28 15:04:13 +05:00
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("categories")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
2022-06-17 17:21:14 +05:00
|
|
|
|
public async Task<IActionResult> GetCategoriesAsync([FromQuery] int? idWell, CancellationToken token = default)
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2022-06-17 17:21:14 +05:00
|
|
|
|
var result = await detectedOperationService.GetCategoriesAsync(idWell, token);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получить фильтрованный список операций по телеметрии САУБ
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet]
|
2022-06-14 15:35:31 +05:00
|
|
|
|
[ProducesResponseType(typeof(DetectedOperationListDto), (int)System.Net.HttpStatusCode.OK)]
|
2022-04-28 15:04:13 +05:00
|
|
|
|
public async Task<IActionResult> GetAsync(
|
|
|
|
|
[FromQuery] DetectedOperationRequest request,
|
|
|
|
|
CancellationToken token = default)
|
|
|
|
|
{
|
2022-06-17 17:21:14 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
2022-04-28 15:04:13 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-06-17 17:21:14 +05:00
|
|
|
|
var result = await detectedOperationService.GetAsync(request, token);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Удалить операции.
|
|
|
|
|
/// Удаленные операции будут определены повторно сервисом автоматизированного определения операций.
|
|
|
|
|
/// Может потребоваться при изменении алгоритмов определения
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="token"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpDelete]
|
|
|
|
|
[Permission]
|
|
|
|
|
[ProducesResponseType(typeof(int), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> DeleteAsync(
|
|
|
|
|
[FromQuery] DetectedOperationRequest request,
|
2022-06-17 17:21:14 +05:00
|
|
|
|
CancellationToken token)
|
2022-04-28 15:04:13 +05:00
|
|
|
|
{
|
2022-06-17 17:21:14 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
2022-04-28 15:04:13 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
|
2022-06-17 17:21:14 +05:00
|
|
|
|
var result = await detectedOperationService.DeleteAsync(request, token);
|
2022-04-28 15:04:13 +05:00
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
2022-06-17 17:21:14 +05:00
|
|
|
|
|
|
|
|
|
protected async Task<bool> UserHasAccesToWellAsync(int idWell, CancellationToken token)
|
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
|
|
|
|
if (idCompany is not null &&
|
|
|
|
|
await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token)
|
|
|
|
|
.ConfigureAwait(false))
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2022-04-28 15:04:13 +05:00
|
|
|
|
}
|
|
|
|
|
}
|