forked from ddrilling/AsbCloudServer
TelemetryDataBaseController add GetRangeAsync method. for witsml
This commit is contained in:
parent
80a07d0b4e
commit
3a1779de94
@ -26,6 +26,16 @@ namespace AsbCloudApp.Services
|
||||
DateTime dateBegin = default, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получение статистики за период
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<DatesRangeDto?> GetRangeAsync(int idWell, DateTimeOffset start, DateTimeOffset end, CancellationToken token);
|
||||
|
||||
/// <summary>
|
||||
/// добавить/изменить данные тех. процесса (используется панелью)
|
||||
/// </summary>
|
||||
|
@ -1,4 +1,5 @@
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudDb;
|
||||
using AsbCloudDb.Model;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@ -13,7 +14,7 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
{
|
||||
public abstract class TelemetryDataBaseService<TDto, TEntity> : ITelemetryDataService<TDto>
|
||||
where TDto : AsbCloudApp.Data.ITelemetryData
|
||||
where TEntity : class, ITelemetryData
|
||||
where TEntity : class, AsbCloudDb.Model.ITelemetryData
|
||||
{
|
||||
protected readonly IAsbCloudDbContext db;
|
||||
protected readonly ITelemetryService telemetryService;
|
||||
@ -146,6 +147,44 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return dtos;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<DatesRangeDto?> GetRangeAsync(
|
||||
int idWell,
|
||||
DateTimeOffset start,
|
||||
DateTimeOffset end,
|
||||
CancellationToken token)
|
||||
{
|
||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell);
|
||||
if (telemetry is null)
|
||||
return default;
|
||||
|
||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
||||
var startUtc = start.ToOffset(TimeSpan.Zero);
|
||||
var endUtc = end.ToOffset(TimeSpan.Zero);
|
||||
|
||||
var dbSet = db.Set<TEntity>();
|
||||
var query = dbSet
|
||||
.Where(i => i.IdTelemetry == telemetry.Id)
|
||||
.Where(i => i.DateTime >= startUtc)
|
||||
.Where(i => i.DateTime <= endUtc)
|
||||
.GroupBy(i => i.IdTelemetry)
|
||||
.Select(g => new
|
||||
{
|
||||
DateStart = g.Min(i => i.DateTime),
|
||||
DateEnd = g.Max(i => i.DateTime),
|
||||
});
|
||||
|
||||
var data = await query.FirstOrDefaultAsync(token);
|
||||
if (data is null)
|
||||
return default;
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = data.DateStart.ToRemoteDateTime(timezone.Hours),
|
||||
To = data.DateEnd.ToRemoteDateTime(timezone.Hours),
|
||||
};
|
||||
}
|
||||
|
||||
public abstract TDto Convert(TEntity src, double timezoneOffset);
|
||||
|
||||
public abstract TEntity Convert(TDto src, double timezoneOffset);
|
||||
|
@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -95,6 +96,37 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает диапазон дат за которые есть телеметрия за период времени
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="end"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("{idWell}/dateRange")]
|
||||
public virtual async Task<ActionResult<DatesRangeDto?>> GetRangeAsync(
|
||||
[FromRoute] int idWell,
|
||||
[Required] DateTimeOffset start,
|
||||
[Required] DateTimeOffset end,
|
||||
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.GetRangeAsync(idWell, start, end, token);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает диапазон дат сохраненных данных.
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user