2021-06-16 14:47:36 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2021-06-17 15:12:39 +05:00
|
|
|
|
using AsbCloudApp.Data;
|
|
|
|
|
using AsbCloudApp.Services;
|
2021-06-16 14:47:36 +05:00
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
|
|
|
|
|
namespace AsbCloudWebApi.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/analytics")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Authorize]
|
|
|
|
|
public class AnalyticsController : ControllerBase
|
|
|
|
|
{
|
2021-06-17 15:12:39 +05:00
|
|
|
|
private readonly IAnalyticsService analyticsService;
|
|
|
|
|
private readonly IWellService wellService;
|
|
|
|
|
|
|
|
|
|
public AnalyticsController(IAnalyticsService analyticsService, IWellService wellService)
|
|
|
|
|
{
|
|
|
|
|
this.analyticsService = analyticsService;
|
|
|
|
|
this.wellService = wellService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает данные по скважине "глубина-день"
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <returns>Коллекцию данных по скважине "глубина-день"</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/wellDepthToDay")]
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-06-17 15:12:39 +05:00
|
|
|
|
public IActionResult GetWellDepthToDay(int wellId)
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-06-22 09:49:53 +05:00
|
|
|
|
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
|
|
|
|
return Ok(wellDepthToDayData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает данные по глубине скважины за период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
2021-06-25 15:10:05 +05:00
|
|
|
|
/// <param name="intervalHoursTimestamp">количество секунд в необходимом интервале времени</param>
|
|
|
|
|
/// <param name="workBeginTimestamp">количество секунд в времени начала смены</param>
|
2021-06-17 15:12:39 +05:00
|
|
|
|
/// <returns>Коллекцию данных по глубине скважины за период</returns>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/wellDepthToInterval")]
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<WellDepthToIntervalDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-06-25 15:10:05 +05:00
|
|
|
|
public IActionResult GetWellDepthToInterval(int wellId, int intervalHoursTimestamp, int workBeginTimestamp)
|
2021-06-17 15:12:39 +05:00
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-06-25 15:10:05 +05:00
|
|
|
|
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, intervalHoursTimestamp, workBeginTimestamp);
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
|
|
|
|
return Ok(wellDepthToIntervalData);
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// <summary>
|
2021-06-22 09:49:53 +05:00
|
|
|
|
/// Возвращает данные по операциям на скважине "операции-время"
|
2021-06-16 14:47:36 +05:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="begin">дата начала интервала</param>
|
|
|
|
|
/// <param name="end">дата окончания интервала</param>
|
|
|
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
2021-06-22 09:49:53 +05:00
|
|
|
|
[HttpGet]
|
|
|
|
|
[Route("{wellId}/operationsSummary")]
|
2021-06-24 13:02:31 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-06-22 09:49:53 +05:00
|
|
|
|
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default)
|
|
|
|
|
{
|
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-06-22 09:49:53 +05:00
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
|
|
|
|
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
|
|
|
|
|
|
|
|
|
|
return Ok(analytics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Возвращает детальные данные по операциям на скважине за период
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="wellId">id скважины</param>
|
|
|
|
|
/// <param name="begin">дата начала интервала</param>
|
|
|
|
|
/// <param name="end">дата окончания интервала</param>
|
|
|
|
|
/// <returns>Коллекцию операций на скважине</returns>
|
|
|
|
|
|
2021-06-16 14:47:36 +05:00
|
|
|
|
[HttpGet]
|
2021-06-17 15:12:39 +05:00
|
|
|
|
[Route("{wellId}/operationsToTime")]
|
2021-06-24 13:02:31 +05:00
|
|
|
|
[ProducesResponseType(typeof(IEnumerable<OperationPercentageDto>), (int)System.Net.HttpStatusCode.OK)]
|
2021-06-17 15:12:39 +05:00
|
|
|
|
public IActionResult GetOperationsToTime(int wellId, DateTime begin = default, DateTime end = default)
|
2021-06-16 14:47:36 +05:00
|
|
|
|
{
|
2021-06-17 15:12:39 +05:00
|
|
|
|
int? idCustomer = User.GetCustomerId();
|
|
|
|
|
|
|
|
|
|
if (idCustomer is null)
|
2021-06-28 10:31:18 +05:00
|
|
|
|
return Forbid();
|
2021-06-17 15:12:39 +05:00
|
|
|
|
|
|
|
|
|
if (!wellService.CheckWellOwnership((int)idCustomer, wellId))
|
|
|
|
|
return Forbid();
|
|
|
|
|
|
2021-06-25 15:10:05 +05:00
|
|
|
|
var analytics = analyticsService.GetOperationsToTime(wellId, begin, end);
|
2021-06-16 14:47:36 +05:00
|
|
|
|
|
|
|
|
|
return Ok(analytics);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|