diff --git a/AsbCloudApp/Services/ITelemetryService.cs b/AsbCloudApp/Services/ITelemetryService.cs index 3c434700..9ebdb36e 100644 --- a/AsbCloudApp/Services/ITelemetryService.cs +++ b/AsbCloudApp/Services/ITelemetryService.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Data.SAUB; +using AsbCloudApp.Requests; using System; using System.Collections.Generic; using System.IO; @@ -62,6 +63,14 @@ public interface ITelemetryService /// Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token); + /// + /// Получить данные о телеметрии + /// + /// + /// + /// + Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token); + /// /// Слить данные телеметрии в одну /// diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs index 49d6d821..13aea69c 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs @@ -14,6 +14,7 @@ using System.Linq; using System.Text.Csv; using System.Threading; using System.Threading.Tasks; +using AsbCloudApp.Requests; namespace AsbCloudInfrastructure.Services.SAUB; @@ -78,6 +79,32 @@ public class TelemetryService : ITelemetryService DropTelemetryCache(); } + public async Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token) + { + var idTelemetries = await db.Set().Include(x => x.RelationCompaniesWells) + .Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) && + x.IdState == request.IdWellState) + .Select(x => x.IdTelemetry) + .ToArrayAsync(token); + + var query = db.Set() + .Where(x => idTelemetries.Contains(x.Id)); + + if (request.SortFields?.Any() == true) + query = query.SortBy(request.SortFields); + + var entities = await query + .AsNoTracking() + .ToArrayAsync(token); + + return entities.Select(x => + { + var dto = x.Info.Adapt(); + dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours); + return dto; + }); + } + [Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")] public SimpleTimezoneDto GetTimezone(int idTelemetry) {