DD.WellWorkover.Cloud/AsbCloudWebApi/Controllers/ClusterOperationStatController.cs
2021-11-19 11:17:45 +05:00

67 lines
2.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using AsbCloudApp.Data;
using AsbCloudApp.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace AsbCloudWebApi.Controllers
{
/// <summary>
/// Контроллер статистики вручную внесенных операций на кусту
/// </summary>
[Route("api/cluster")]
[ApiController]
[Authorize]
public class ClusterOperationStatController : ControllerBase
{
private readonly IWellOperationService operationService;
private readonly IWellService wellService;
private readonly IWellOperationImportService wellOperationImportService;
public ClusterOperationStatController(IWellOperationService operationService,
IWellService wellService, IWellOperationImportService wellOperationImportService)
{
this.operationService = operationService;
this.wellService = wellService;
this.wellOperationImportService = wellOperationImportService;
}
/// <summary>
/// Формирует данные по среднему и максимальному МСП на кусту
/// </summary>
/// <param name="idWell">id скважины с данного куста (через нее будут полуены данные)</param>
/// <param name="token"></param>
/// <returns>Возвращает данные по среднему и максимальному МСП на кусту</returns>
[HttpGet("{idWell}/ropStat")]
[ProducesResponseType(typeof(ClusterRopStatDto), (int)System.Net.HttpStatusCode.OK)]
public async Task<IActionResult> GetClusterRopStatAsync([FromRoute] int idWell,
CancellationToken token = default)
{
if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false))
return Forbid();
// var result = await operationService.GetOperationsAsync(
// idWell, token).ConfigureAwait(false);
var result = new ClusterRopStatDto()
{
RopMax = 3.2,
RopAverage = 1.1
};
return Ok(result);
}
private async Task<bool> CanUserAccessToWellAsync(int idWell, CancellationToken token = default)
{
int? idCompany = User.GetCompanyId();
return idCompany is not null && await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
idWell, token).ConfigureAwait(false);
}
}
}