2022-07-14 03:47:11 +05:00
|
|
|
|
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;
|
2022-07-14 03:47:11 +05:00
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers.Subsystems
|
2022-08-03 16:35:21 +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
|
|
|
|
{
|
2022-08-15 01:17:00 +05:00
|
|
|
|
private readonly ISubsystemOperationTimeService subsystemOperationTimeService;
|
2022-08-05 17:10:56 +05:00
|
|
|
|
private readonly IWellService wellService;
|
2022-08-15 15:08:17 +05:00
|
|
|
|
private readonly ICrudService<SubsystemDto> subsystemServiceCrud;
|
|
|
|
|
private readonly ISubsystemService subsystemService;
|
|
|
|
|
public SubsystemOperationTimeController(ISubsystemOperationTimeService subsystemOperationTimeService, IWellService wellService, ICrudService<SubsystemDto> subsystemServiceCrud, ISubsystemService subsystemService)
|
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.subsystemServiceCrud = subsystemServiceCrud;
|
|
|
|
|
this.subsystemService = subsystemService;
|
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)]
|
|
|
|
|
public async Task<IActionResult> GetStatAsync([FromQuery] SubsystemOperationTimeRequest request, CancellationToken token = default)
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить список подсистем общий.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("subsystem")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemDto>), (int)System.Net.HttpStatusCode.OK)]
|
2022-08-05 17:10:56 +05:00
|
|
|
|
public async Task<IActionResult> GetSubsystemAsync([FromQuery] int? idWell, CancellationToken token = default)
|
2022-07-18 18:51:49 +05:00
|
|
|
|
{
|
2022-08-05 17:10:56 +05:00
|
|
|
|
if (idWell.HasValue)
|
|
|
|
|
if (!await UserHasAccesToWellAsync(idWell.Value, token))
|
2022-08-15 15:08:17 +05:00
|
|
|
|
return Forbid();
|
|
|
|
|
var result = await subsystemService.GetSubsystemAsync(idWell, token);
|
2022-08-05 17:10:56 +05:00
|
|
|
|
return Ok(result);
|
2022-07-18 18:51:49 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// получить список наработок подсистем
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet("operationTime")]
|
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<SubsystemOperationTimeDto>), (int)System.Net.HttpStatusCode.OK)]
|
2022-08-05 17:10:56 +05:00
|
|
|
|
|
2022-07-18 18:51:49 +05:00
|
|
|
|
public async Task<IActionResult> GetOperationTimeAsync(
|
|
|
|
|
[FromQuery] SubsystemOperationTimeRequest request,
|
|
|
|
|
CancellationToken token = default)
|
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.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)]
|
|
|
|
|
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);
|
|
|
|
|
return Ok(result);
|
|
|
|
|
}
|
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
|
|
|
|
}
|