forked from ddrilling/AsbCloudServer
Fix TelemetryDataBaseService<TDto, TEntity>.GetRange(). Use cache.
This commit is contained in:
parent
50fd1d77e2
commit
52cd33647d
@ -26,17 +26,25 @@ namespace AsbCloudApp.Services
|
||||
Task<IEnumerable<TDto>> GetAsync(int idWell,
|
||||
DateTime dateBegin = default, double intervalSec = 600d,
|
||||
int approxPointsCount = 1024, CancellationToken token = default);
|
||||
|
||||
/// <summary>
|
||||
/// Получить данные тех. процесса
|
||||
/// </summary>
|
||||
/// <param name="idWell"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="token"></param>
|
||||
/// <returns></returns>
|
||||
Task<IEnumerable<TDto>> GetAsync(int idWell, TelemetryDataRequest request, CancellationToken token);
|
||||
|
||||
/// <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);
|
||||
DatesRangeDto? GetRange(int idWell, DateTimeOffset start, DateTimeOffset end);
|
||||
|
||||
/// <summary>
|
||||
/// добавить/изменить данные тех. процесса (используется панелью)
|
||||
|
@ -203,40 +203,27 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<DatesRangeDto?> GetRangeAsync(
|
||||
int idWell,
|
||||
DateTimeOffset start,
|
||||
DateTimeOffset end,
|
||||
CancellationToken token)
|
||||
public DatesRangeDto? GetRange(int idWell, DateTimeOffset start, DateTimeOffset end)
|
||||
{
|
||||
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 datesRange = telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id);
|
||||
|
||||
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),
|
||||
});
|
||||
if (datesRange is null)
|
||||
return null;
|
||||
|
||||
var data = await query.FirstOrDefaultAsync(token);
|
||||
if (data is null)
|
||||
return default;
|
||||
var from = datesRange.From > start.DateTime
|
||||
? datesRange.From : start.DateTime;
|
||||
|
||||
var to = datesRange.To < end.DateTime
|
||||
? datesRange.To : end.DateTime;
|
||||
|
||||
return new DatesRangeDto
|
||||
{
|
||||
From = data.DateStart.ToRemoteDateTime(timezone.Hours),
|
||||
To = data.DateEnd.ToRemoteDateTime(timezone.Hours),
|
||||
From = from,
|
||||
To = to,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -153,7 +153,7 @@ namespace AsbCloudWebApi.Controllers.SAUB
|
||||
if (!isCompanyOwnsWell)
|
||||
return Forbid();
|
||||
|
||||
var content = await telemetryDataService.GetRangeAsync(idWell, start, end, token);
|
||||
var content = telemetryDataService.GetRange(idWell, start, end);
|
||||
|
||||
return Ok(content);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ namespace AsbCloudWebApi.Controllers.Subsystems
|
||||
if (!await UserHasAccesToWellAsync(idWell, token))
|
||||
return Forbid();
|
||||
|
||||
var dateRange = await telemetryDataSaubService.GetRangeAsync(idWell, DateTimeOffset.MinValue, DateTimeOffset.MaxValue, token);
|
||||
var dateRange = telemetryDataSaubService.GetRange(idWell, DateTimeOffset.MinValue, DateTimeOffset.MaxValue);
|
||||
|
||||
return Ok(dateRange);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user