diff --git a/AsbCloudApp/Services/ITelemetryDataService.cs b/AsbCloudApp/Services/ITelemetryDataService.cs index bb40771b..9cf4a805 100644 --- a/AsbCloudApp/Services/ITelemetryDataService.cs +++ b/AsbCloudApp/Services/ITelemetryDataService.cs @@ -23,18 +23,27 @@ namespace AsbCloudApp.Services /// кол-во элементов до которых эти данные прореживаются /// /// - Task> GetAsync(int idWell, + Task> GetByWellAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default); /// - /// Получить данные тех. процесса + /// Получить данные тех. процесса по скважине /// /// /// /// /// - Task> GetAsync(int idWell, TelemetryDataRequest request, CancellationToken token); + Task> GetByWellAsync(int idWell, TelemetryDataRequest request, CancellationToken token); + + /// + /// Получение данных тех. процесса по телеметрии + /// + /// + /// + /// + /// + Task> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token); /// /// Период за который есть данные по скважине в рамках временного интервала diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs index e296692c..f9cc64ee 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataBaseService.cs @@ -11,6 +11,7 @@ using System.Diagnostics; using System.Linq; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Requests; namespace AsbCloudInfrastructure.Services.SAUB { @@ -22,7 +23,7 @@ namespace AsbCloudInfrastructure.Services.SAUB protected readonly ITelemetryService telemetryService; protected readonly ITelemetryDataCache telemetryDataCache; - public TelemetryDataBaseService( + protected TelemetryDataBaseService( IAsbCloudDbContext db, ITelemetryService telemetryService, ITelemetryDataCache telemetryDataCache) @@ -86,7 +87,7 @@ namespace AsbCloudInfrastructure.Services.SAUB } /// - public virtual async Task> GetAsync(int idWell, + public virtual async Task> GetByWellAsync(int idWell, DateTime dateBegin = default, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default) { @@ -146,23 +147,41 @@ namespace AsbCloudInfrastructure.Services.SAUB } /// - public virtual async Task> GetAsync(int idWell, AsbCloudApp.Requests.TelemetryDataRequest request, CancellationToken token) + public virtual async Task> GetByWellAsync(int idWell, TelemetryDataRequest request, CancellationToken token) { var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(idWell); if (telemetry is null) return Enumerable.Empty(); - var timezone = telemetryService.GetTimezone(telemetry.Id); + return await GetByTelemetryAsync(telemetry.Id, request, token); + } - var cache = telemetryDataCache.GetOrDefault(telemetry.Id, request); + public async Task> GetByTelemetryAsync(int idTelemetry, TelemetryDataRequest request, CancellationToken token) + { + var timezone = telemetryService.GetTimezone(idTelemetry); + + var cache = telemetryDataCache.GetOrDefault(idTelemetry, request); + if(cache is not null) return cache; + + var query = BuildQuery(idTelemetry, request); + var entities = await query + .AsNoTracking() + .ToArrayAsync(token); + + var dtos = entities.Select(e => Convert(e, timezone.Hours)); + + return dtos; + } + + private IQueryable BuildQuery(int idTelemetry, TelemetryDataRequest request) + { var dbSet = db.Set(); var query = dbSet - .Where(d => d.IdTelemetry == telemetry.Id) - .AsNoTracking(); + .Where(d => d.IdTelemetry == idTelemetry); if (request.GeDate.HasValue) { @@ -196,12 +215,7 @@ namespace AsbCloudInfrastructure.Services.SAUB break; } - var entities = await query - .ToArrayAsync(token); - - var dtos = entities.Select(e => Convert(e, timezone.Hours)); - - return dtos; + return query; } /// @@ -263,9 +277,9 @@ namespace AsbCloudInfrastructure.Services.SAUB return telemetryDataCache.GetOrDefaultDataDateRange(telemetry.Id); } - public abstract TDto Convert(TEntity src, double timezoneOffset); + protected abstract TDto Convert(TEntity src, double timezoneOffset); - public abstract TEntity Convert(TDto src, double timezoneOffset); + protected abstract TEntity Convert(TDto src, double timezoneOffset); } } diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs index fdced02c..92db8e4d 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryDataSaubService.cs @@ -111,7 +111,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService(); var telemetryUser = telemetryUserService @@ -122,7 +122,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService(); var telemetryUser = telemetryUserService.GetOrDefault(src.IdTelemetry, src.IdUser ?? int.MinValue); @@ -151,7 +151,7 @@ public class TelemetryDataSaubService : TelemetryDataBaseService 32_768 }; - var data = await GetAsync(idWell, beginDate, intervalSec, approxPointsCount, token); + var data = await GetByWellAsync(idWell, beginDate, intervalSec, approxPointsCount, token); var fileName = $"DataSaub idWell{idWell}"; if (telemetry.Info is not null) diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs index 4c8ec124..5ff378de 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryDataBaseController.cs @@ -92,7 +92,7 @@ namespace AsbCloudWebApi.Controllers.SAUB if (!isCompanyOwnsWell) return Forbid(); - var content = await telemetryDataService.GetAsync(idWell, begin, + var content = await telemetryDataService.GetByWellAsync(idWell, begin, intervalSec, approxPointsCount, token).ConfigureAwait(false); return Ok(content); @@ -123,7 +123,7 @@ namespace AsbCloudWebApi.Controllers.SAUB if (!isCompanyOwnsWell) return Forbid(); - var content = await telemetryDataService.GetAsync(idWell, request, token); + var content = await telemetryDataService.GetByWellAsync(idWell, request, token); return Ok(content); }