forked from ddrilling/AsbCloudServer
90 lines
3.7 KiB
C#
90 lines
3.7 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers.SAUB
|
|
{
|
|
/// <summary>
|
|
/// Операции определенные по телеметрии САУБ
|
|
/// </summary>
|
|
[Route("api/well/{idWell}/[controller]")]
|
|
[ApiController]
|
|
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>
|
|
/// получить справочник операций. Отличается от операций заводимых вручную
|
|
/// </summary>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("categories")]
|
|
[ProducesResponseType(typeof(IEnumerable<WellOperationCategoryDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetCategoriesAsync(CancellationToken token = default)
|
|
{
|
|
var result = await detectedOperationService.GetCategoriesAsync(token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Получить фильтрованный список операций по телеметрии САУБ
|
|
/// </summary>
|
|
/// <param name="idWell"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="token"></param>
|
|
/// <returns></returns>
|
|
[HttpGet]
|
|
[ProducesResponseType(typeof(DetectedOperationListDto), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetAsync(
|
|
int idWell,
|
|
[FromQuery] DetectedOperationRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
int? idCompany = User.GetCompanyId();
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
idWell, token).ConfigureAwait(false))
|
|
return Forbid();
|
|
|
|
var result = await detectedOperationService.GetAsync(idWell, request, token);
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Удалить операции.
|
|
/// Удаленные операции будут определены повторно сервисом автоматизированного определения операций.
|
|
/// Может потребоваться при изменении алгоритмов определения
|
|
/// </summary>
|
|
/// <param name="idWell"></param>
|
|
/// <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(
|
|
int idWell,
|
|
[FromQuery] DetectedOperationRequest request,
|
|
CancellationToken token = default)
|
|
{
|
|
int? idCompany = User.GetCompanyId();
|
|
if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
|
idWell, token).ConfigureAwait(false))
|
|
return Forbid();
|
|
|
|
var result = await detectedOperationService.DeleteAsync(idWell, request, token);
|
|
return Ok(result);
|
|
}
|
|
}
|
|
}
|