2023-09-15 14:51:15 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Data.Subsystems;
|
2022-07-18 18:51:49 +05:00
|
|
|
|
using AsbCloudApp.Requests;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using AsbCloudApp.Services;
|
2022-07-18 18:51:49 +05:00
|
|
|
|
using AsbCloudApp.Services.Subsystems;
|
2023-09-15 14:51:15 +05:00
|
|
|
|
using AsbCloudDb.Model;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2023-09-15 14:51:15 +05:00
|
|
|
|
using System;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
2023-09-15 14:51:15 +05:00
|
|
|
|
{
|
2022-07-14 03:47:11 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Наработка подсистем
|
|
|
|
|
/// </summary>
|
2022-07-18 18:51:49 +05:00
|
|
|
|
[Route("api/[controller]")]
|
2022-07-14 03:47:11 +05:00
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
2022-08-02 15:26:33 +05:00
|
|
|
|
public class SubsystemOperationTimeController : ControllerBase
|
2022-07-14 03:47:11 +05:00
|
|
|
|
{
|
2023-09-15 14:51:15 +05:00
|
|
|
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
|
|
|
|
private readonly ITelemetryDataSaubService telemetryDataSaubService;
|
2022-08-05 17:10:56 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
private readonly ISubsystemService subsystemService;
|
2022-12-06 10:03:24 +05:00
|
|
|
|
|
|
|
|
|
private readonly Dictionary<int, string> subsystemNames = new()
|
|
|
|
|
{
|
|
|
|
|
{ 1, "SAUB" },
|
|
|
|
|
{ 65537, "Torque Master" },
|
|
|
|
|
{ 65536, "Spin Master" }
|
|
|
|
|
};
|
|
|
|
|
|
2023-09-15 14:51:15 +05:00
|
|
|
|
public SubsystemOperationTimeController(
|
|
|
|
|
ISubsystemOperationTimeService subsystemOperationTimeService,
|
|
|
|
|
IWellService wellService,
|
|
|
|
|
ISubsystemService subsystemService,
|
|
|
|
|
ITelemetryDataSaubService telemetryDataSaubService)
|
2022-07-18 18:51:49 +05:00
|
|
|
|
{
|
2022-08-15 15:08:17 +05:00
|
|
|
|
this.subsystemOperationTimeService = subsystemOperationTimeService;
|
2022-08-05 17:10:56 +05:00
|
|
|
|
this.wellService = wellService;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
this.subsystemService = subsystemService;
|
2023-09-15 14:51:15 +05:00
|
|
|
|
this.telemetryDataSaubService = telemetryDataSaubService;
|
2022-07-18 18:51:49 +05:00
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить статистику
|
|
|
|
|
/// </summary>
|
2022-08-01 13:55:51 +05:00
|
|
|
|
[HttpGet("stat")]
|
2022-08-03 16:35:21 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-09-28 16:25:29 +05:00
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
|
2022-07-18 18:51:49 +05:00
|
|
|
|
{
|
2022-08-05 17:10:56 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
|
|
|
return Forbid();
|
2022-08-03 16:35:21 +05:00
|
|
|
|
var subsystemResult = await subsystemOperationTimeService.GetStatAsync(request, token);
|
2022-07-18 18:51:49 +05:00
|
|
|
|
return Ok(subsystemResult);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-28 09:43:32 +05:00
|
|
|
|
/// <summary>
|
2023-09-15 14:51:15 +05:00
|
|
|
|
/// получить период, за который будет рассчитываться статистика
|
2023-08-28 09:43:32 +05:00
|
|
|
|
/// </summary>
|
2023-09-15 14:51:15 +05:00
|
|
|
|
[HttpGet("operationsPeriod/{idWell}")]
|
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public async Task<IActionResult> GetStatDateRangeAsync([FromRoute] int idWell, CancellationToken token)
|
2023-08-28 09:43:32 +05:00
|
|
|
|
{
|
2023-09-15 14:51:15 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(idWell, token))
|
2023-08-28 09:43:32 +05:00
|
|
|
|
return Forbid();
|
2023-09-15 14:51:15 +05:00
|
|
|
|
|
|
|
|
|
var dateRange = await telemetryDataSaubService.GetRangeAsync(idWell, DateTimeOffset.MinValue, DateTimeOffset.MaxValue, token);
|
|
|
|
|
|
2023-08-28 09:43:32 +05:00
|
|
|
|
return Ok(dateRange);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-31 18:19:14 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить статистику по активным скважинам
|
|
|
|
|
/// </summary>
|
2022-11-02 15:49:07 +05:00
|
|
|
|
/// <param name="GtDate"> Больше или равно дате </param>
|
|
|
|
|
/// <param name="LtDate"> Меньше или равно дате </param>
|
|
|
|
|
/// <param name="token"> Токен </param>
|
|
|
|
|
/// <returns> </returns>
|
2022-10-31 18:19:14 +05:00
|
|
|
|
[HttpGet("statByActiveWell")]
|
2022-11-04 17:56:34 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemActiveWellStatDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetStatByWellAsync(DateTime? GtDate, DateTime? LtDate, CancellationToken token)
|
2022-10-31 18:59:08 +05:00
|
|
|
|
{
|
|
|
|
|
var idCompany = User.GetCompanyId();
|
2022-11-02 15:49:07 +05:00
|
|
|
|
if (!idCompany.HasValue)
|
|
|
|
|
return Forbid();
|
2022-11-03 15:57:45 +05:00
|
|
|
|
var subsystemResult = await subsystemOperationTimeService.GetStatByActiveWells(idCompany.Value, GtDate, LtDate, token);
|
2022-11-02 15:49:07 +05:00
|
|
|
|
return Ok(subsystemResult);
|
2022-10-31 18:19:14 +05:00
|
|
|
|
}
|
|
|
|
|
|
2022-07-18 18:51:49 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить список подсистем общий.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("subsystem")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int? idWell, CancellationToken token)
|
2022-07-18 18:51:49 +05:00
|
|
|
|
{
|
2023-09-15 14:51:15 +05:00
|
|
|
|
if (idWell.HasValue)
|
2022-08-05 17:10:56 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
2023-09-15 14:51:15 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
2022-09-07 18:01:39 +05:00
|
|
|
|
return Ok(result);
|
2022-10-21 15:52:51 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить доступный диапазон дат наработки подсистемы.
|
|
|
|
|
/// </summary>
|
2022-10-26 10:30:59 +05:00
|
|
|
|
[HttpGet("datesRange")]
|
2022-10-25 09:42:08 +05:00
|
|
|
|
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
|
2023-07-03 14:33:34 +05:00
|
|
|
|
public async Task<IActionResult> GetDateRangeOperationTimeAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token)
|
2022-10-21 15:52:51 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
2023-09-15 14:51:15 +05:00
|
|
|
|
return Forbid();
|
2022-10-21 15:52:51 +05:00
|
|
|
|
var result = await subsystemOperationTimeService.GetDateRangeOperationTimeAsync(request, token);
|
|
|
|
|
return Ok(result);
|
2022-07-18 18:51:49 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить список наработок подсистем
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("operationTime")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemOperationTimeDto>), (int)System.Net.HttpStatusCode.OK)]
|
2023-09-28 16:25:29 +05:00
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
2022-07-18 18:51:49 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationTimeAsync(
|
|
|
|
|
[FromQuery] SubsystemOperationTimeRequest request,
|
2023-07-03 14:33:34 +05:00
|
|
|
|
CancellationToken token)
|
2022-08-05 17:10:56 +05:00
|
|
|
|
{
|
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
|
|
|
return Forbid();
|
2022-09-20 22:24:51 +05:00
|
|
|
|
|
2022-07-18 18:51:49 +05:00
|
|
|
|
var result = await subsystemOperationTimeService.GetOperationTimeAsync(request, token);
|
|
|
|
|
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)]
|
2023-09-28 16:25:29 +05:00
|
|
|
|
[ProducesResponseType(typeof(ValidationProblemDetails), (int)System.Net.HttpStatusCode.BadRequest)]
|
2022-07-18 18:51:49 +05:00
|
|
|
|
public async Task<IActionResult> DeleteAsync(
|
|
|
|
|
[FromQuery] SubsystemOperationTimeRequest request,
|
|
|
|
|
CancellationToken token)
|
|
|
|
|
{
|
2022-08-05 17:10:56 +05:00
|
|
|
|
if (!await UserHasAccesToWellAsync(request.IdWell, token))
|
|
|
|
|
return Forbid();
|
2022-07-18 18:51:49 +05:00
|
|
|
|
var result = await subsystemOperationTimeService.DeleteAsync(request, token);
|
2023-09-15 14:51:15 +05:00
|
|
|
|
return Ok(result);
|
2022-07-18 18:51:49 +05:00
|
|
|
|
}
|
2022-08-05 17:10:56 +05:00
|
|
|
|
|
2022-12-06 10:03:24 +05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Получение словаря названий подсистем
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("names")]
|
|
|
|
|
[ProducesResponseType(typeof(Dictionary<int, string>), (int)System.Net.HttpStatusCode.OK)]
|
|
|
|
|
public IActionResult GetSubsystemsNames()
|
2023-09-15 14:51:15 +05:00
|
|
|
|
{
|
2022-12-06 10:03:24 +05:00
|
|
|
|
return Ok(subsystemNames);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-05 17:10:56 +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-07-14 03:47:11 +05:00
|
|
|
|
}
|
2022-07-18 18:51:49 +05:00
|
|
|
|
}
|