forked from ddrilling/AsbCloudServer
TelemetryDataBaseService Add GetAsync method with new request
This commit is contained in:
parent
67f447d00e
commit
7293dc11e3
59
AsbCloudApp/Requests/TelemetryRequest.cs
Normal file
59
AsbCloudApp/Requests/TelemetryRequest.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace AsbCloudApp.Requests;
|
||||
|
||||
/// <summary>
|
||||
/// Параметры запроса телеметрии
|
||||
/// </summary>
|
||||
public class TelemetryDataRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// Максимально допустимое кол-во строк данных
|
||||
/// </summary>
|
||||
public const int MaxTake = 3072;
|
||||
|
||||
/// <summary>
|
||||
/// greater or equal then Date
|
||||
/// </summary>
|
||||
public DateTimeOffset? GeDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// less or equal then Date
|
||||
/// </summary>
|
||||
public DateTimeOffset? LeDate { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Делитель для прореживания выборки.
|
||||
/// <list type="bullet">
|
||||
/// <item>1 - без прореживания (default); </item>
|
||||
/// <item>2 - каждое 2-е значение; </item>
|
||||
/// <item>10 - каждое 10-е значение; </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[Range(0, 300)]
|
||||
public int Divider { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// сортировка/выравнивание данных в запросе по дате
|
||||
/// <list type="bullet">
|
||||
/// <item>0 - более ранние данные вперед; </item>
|
||||
/// <item>1 - более поздние данные вперед; </item>
|
||||
/// </list>
|
||||
/// </summary>
|
||||
[Range(0, 1)]
|
||||
public int Order { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Пропустить с начала
|
||||
/// </summary>
|
||||
[Range(0, int.MaxValue)]
|
||||
public int Skip { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Кол-во возвращаемых, но не больше MaxTake
|
||||
/// </summary>
|
||||
[Range(1, MaxTake)]
|
||||
public int Take { get; set; } = 1024;
|
||||
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
@ -25,6 +26,7 @@ namespace AsbCloudApp.Services
|
||||
Task<IEnumerable<TDto>> GetAsync(int idWell,
|
||||
DateTime dateBegin = default, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
Task<IEnumerable<TDto>> GetAsync(int idWell, TelemetryDataRequest request, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// Получение статистики за период
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Exceptions;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
@ -137,10 +138,57 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
}
|
||||
|
||||
var entities = await query
|
||||
.OrderBy(d => d.DateTime)
|
||||
.AsNoTracking()
|
||||
.ToListAsync(token)
|
||||
.ConfigureAwait(false);
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var dtos = entities.Select(e => Convert(e, timezone.Hours));
|
||||
|
||||
return dtos;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<IEnumerable<TDto>> GetAsync(int idWell, AsbCloudApp.Requests.TelemetryDataRequest request, CancellationToken token)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return Enumerable.Empty<TDto>();
|
||||
|
||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||
|
||||
var dbSet = db.Set<TEntity>();
|
||||
|
||||
var query = dbSet
|
||||
.Where(d => d.IdTelemetry == telemetry.Id)
|
||||
.AsNoTracking();
|
||||
|
||||
if (request.GeDate.HasValue)
|
||||
query = query.Where(d => d.DateTime >= request.GeDate);
|
||||
|
||||
if (request.LeDate.HasValue)
|
||||
query = query.Where(d => d.DateTime >= request.LeDate);
|
||||
|
||||
if (request.Divider > 1)
|
||||
query = query.Where((d) => (((d.DateTime.DayOfYear * 24 + d.DateTime.Hour) * 60 + d.DateTime.Minute) * 60 + d.DateTime.Second) % request.Divider == 0);
|
||||
|
||||
switch (request.Order)
|
||||
{
|
||||
case 1:// Поздние вперед
|
||||
query = query
|
||||
.OrderByDescending(d => d.DateTime)
|
||||
.Skip(request.Skip)
|
||||
.Take(request.Take)
|
||||
.OrderBy(d => d.DateTime);
|
||||
break;
|
||||
default:// Ранние вперед
|
||||
query = query
|
||||
.OrderBy(d => d.DateTime)
|
||||
.Skip(request.Skip)
|
||||
.Take(request.Take);
|
||||
break;
|
||||
}
|
||||
|
||||
var entities = await query
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var dtos = entities.Select(e => Convert(e, timezone.Hours));
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@ -96,6 +97,36 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Новая версия. Возвращает данные САУБ по скважине.
|
||||
/// По умолчанию за последние 10 минут.
|
||||
/// </summary>
|
||||
/// <param name="idWell">id скважины</param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token">Токен завершения задачи</param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}/data")]
|
||||
[Permission]
|
||||
public virtual async Task<ActionResult<IEnumerable<TDto>>> GetData2Async(int idWell,
|
||||
[FromQuery]TelemetryDataRequest request,
|
||||
CancellationToken token)
|
||||
{
|
||||
int? idCompany = User.GetCompanyId();
|
||||
|
||||
if (idCompany is null)
|
||||
return Forbid();
|
||||
|
||||
bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany,
|
||||
idWell, token).ConfigureAwait(false);
|
||||
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await telemetryDataService.GetAsync(idWell, request, token);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает диапазон дат за которые есть телеметрия за период времени
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user