forked from ddrilling/AsbCloudServer
110 lines
4.0 KiB
C#
110 lines
4.0 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Data.Subsystems;
|
|
using AsbCloudApp.Requests;
|
|
using AsbCloudApp.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace AsbCloudWebApi.Controllers.Subsystems;
|
|
|
|
/// <summary>
|
|
/// Наработка подсистем
|
|
/// </summary>
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
[Authorize]
|
|
public class SubsystemController : ControllerBase
|
|
{
|
|
private readonly ISubsystemService subsystemService;
|
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
|
private readonly IWellService wellService;
|
|
|
|
public SubsystemController(
|
|
ISubsystemService subsystemService,
|
|
IWellService wellService,
|
|
ITelemetryDataSaubService telemetryDataSaubService)
|
|
{
|
|
this.subsystemService = subsystemService;
|
|
this.wellService = wellService;
|
|
this.telemetryDataSaubService = telemetryDataSaubService;
|
|
}
|
|
|
|
/// <summary>
|
|
/// получить статистику
|
|
/// </summary>
|
|
[HttpGet("stat")]
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
|
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemRequest request, CancellationToken token)
|
|
{
|
|
if (!await UserHasAccessToWellAsync(request.IdWell, token))
|
|
return Forbid();
|
|
var subsystemResult = await subsystemService.GetStatAsync(request, token);
|
|
return Ok(subsystemResult);
|
|
}
|
|
|
|
/// <summary>
|
|
/// получить период, за который будет рассчитываться статистика
|
|
/// </summary>
|
|
[HttpGet("operationsPeriod/{idWell}")]
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
|
|
{
|
|
if (!await UserHasAccessToWellAsync(idWell, token))
|
|
return Forbid();
|
|
|
|
var dateRange = telemetryDataSaubService.GetRange(idWell);
|
|
|
|
return Ok(dateRange);
|
|
}
|
|
|
|
[HttpGet("drillerDetectedOperationStat")]
|
|
[ProducesResponseType(typeof(IEnumerable<DrillerDetectedOperationStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetByWellsAsync([FromQuery] GetStatRequest request,
|
|
CancellationToken token)
|
|
{
|
|
if (!request.IdsWells.Any())
|
|
return NoContent();
|
|
|
|
foreach(var idWell in request.IdsWells)
|
|
if (!await UserHasAccessToWellAsync(idWell, token))
|
|
return Forbid();
|
|
|
|
var result = await subsystemService.GetByWellsAsync(request, token);
|
|
|
|
return Ok(result);
|
|
}
|
|
|
|
/// <summary>
|
|
/// получить статистику по плановым и фактическим подсистемам на скважинах
|
|
/// </summary>
|
|
[HttpGet("/api/serviceWork/subsystemWells")]
|
|
[Permission("SubsystemStatPlanFact.get")]
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemPlanFactStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
|
public async Task<IActionResult> GetStatPlanFactAsync([FromQuery] SubsystemPlanFactRequest request, CancellationToken token)
|
|
{
|
|
foreach (var idWell in request.IdsWell)
|
|
{
|
|
if (!await UserHasAccessToWellAsync(idWell, token))
|
|
return Forbid();
|
|
}
|
|
var subsystemStat = await subsystemService.GetStatPlanFactByWellsAsync(request, token);
|
|
|
|
return Ok(subsystemStat);
|
|
}
|
|
|
|
private async Task<bool> UserHasAccessToWellAsync(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;
|
|
}
|
|
} |