diff --git a/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs b/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs
index 10b36719..13b60fdb 100644
--- a/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs
+++ b/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs
@@ -66,20 +66,4 @@ public class TelemetryInfoDto
/// комментарий
///
public string? Comment { get; set; }
-}
-
-///
-/// Информация о телеметрии скважины
-///
-public class WellTelemetryInfoDto
-{
- ///
- /// Идентификатор скважины
- ///
- public int IdWell { get; set; }
-
- ///
- /// Информация о телеметрии
- ///
- public TelemetryInfoDto Info { get; set; } = null!;
}
\ No newline at end of file
diff --git a/AsbCloudApp/Data/SAUB/VersionDto.cs b/AsbCloudApp/Data/SAUB/VersionDto.cs
new file mode 100644
index 00000000..a5d48cfa
--- /dev/null
+++ b/AsbCloudApp/Data/SAUB/VersionDto.cs
@@ -0,0 +1,17 @@
+namespace AsbCloudApp.Data.SAUB;
+
+///
+/// Версия ПО
+///
+public class VersionDto
+{
+ ///
+ /// Идентификатор скважины
+ ///
+ public int IdWell { get; set; }
+
+ ///
+ /// Информация о версии
+ ///
+ public TelemetryInfoDto Version { get; set; } = null!;
+}
\ No newline at end of file
diff --git a/AsbCloudApp/Requests/TelemetryInfoRequest.cs b/AsbCloudApp/Requests/TelemetryInfoRequest.cs
deleted file mode 100644
index 82b36a32..00000000
--- a/AsbCloudApp/Requests/TelemetryInfoRequest.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-namespace AsbCloudApp.Requests;
-
-///
-/// Запрос получения информации по телеметрии
-///
-public class TelemetryInfoRequest
-{
- ///
- /// Идентификатор компании
- ///
- public int IdCompany { get; set; }
-
- ///
- /// Необязательный параметр. Определяет состояние скважины
- /// 0 - неизвестно,
- /// 1 - в работе,
- /// 2 - завершена
- ///
- public int? IdWellState { get; set; }
-}
\ No newline at end of file
diff --git a/AsbCloudApp/Requests/VersionRequest.cs b/AsbCloudApp/Requests/VersionRequest.cs
new file mode 100644
index 00000000..5264543e
--- /dev/null
+++ b/AsbCloudApp/Requests/VersionRequest.cs
@@ -0,0 +1,61 @@
+using System.Collections.Generic;
+
+namespace AsbCloudApp.Requests;
+
+///
+/// Запрос получения версий ПО
+///
+public class VersionRequestBase
+{
+ ///
+ /// Конструктор по умолчанию
+ ///
+ public VersionRequestBase()
+ {
+ }
+
+ ///
+ /// Копирующий конструктор
+ ///
+ ///
+ public VersionRequestBase(VersionRequestBase request)
+ {
+ IdWellState = request.IdWellState;
+ IdsWell = request.IdsWell;
+ }
+
+ ///
+ /// Необязательный параметр. Определяет состояние скважины
+ /// null - возвращаются все записи
+ /// 0 - неизвестно,
+ /// 1 - в работе,
+ /// 2 - завершена
+ ///
+ public int? IdWellState { get; set; }
+
+ ///
+ /// Идентификаторы скважин
+ ///
+ public IEnumerable? IdsWell { get; set; }
+}
+
+///
+/// Запрос получения версий ПО
+///
+public class VersionRequest : VersionRequestBase
+{
+ ///
+ /// Конструктор
+ ///
+ public VersionRequest(int idCompany,
+ VersionRequestBase request)
+ : base(request)
+ {
+ IdCompany = idCompany;
+ }
+
+ ///
+ /// Идентификатор компании
+ ///
+ public int IdCompany { get; set; }
+}
\ No newline at end of file
diff --git a/AsbCloudApp/Services/ITelemetryService.cs b/AsbCloudApp/Services/ITelemetryService.cs
index e59ef022..c1b4ba99 100644
--- a/AsbCloudApp/Services/ITelemetryService.cs
+++ b/AsbCloudApp/Services/ITelemetryService.cs
@@ -64,12 +64,12 @@ public interface ITelemetryService
Task UpdateInfoAsync(string uid, TelemetryInfoDto info, CancellationToken token);
///
- /// Получить данные о телеметрии
+ /// Получить версии ПО
///
///
///
///
- Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token);
+ Task> GetVersionsAsync(VersionRequest request, CancellationToken token);
///
/// Слить данные телеметрии в одну
diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs
index 96db61ce..b624f16b 100644
--- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs
+++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs
@@ -78,7 +78,7 @@ public class TelemetryService : ITelemetryService
DropTelemetryCache();
}
- public async Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token)
+ public async Task> GetVersionsAsync(VersionRequest request, CancellationToken token)
{
var wells = db.Set()
.Include(x => x.RelationCompaniesWells)
@@ -86,42 +86,33 @@ public class TelemetryService : ITelemetryService
if (request.IdWellState.HasValue)
wells = wells.Where(x => x.IdState == request.IdWellState);
+
+ if (request.IdsWell?.Any() == true)
+ wells = wells.Where(x => request.IdsWell.Contains(x.Id));
var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue)
.Select(x => x.IdTelemetry!.Value)
.ToArrayAsync(token);
- var key = $"TelemetryInfo_{string.Join("", idTelemetries)}";
+ var telemetries = GetTelemetryCache()
+ .Where(x => idTelemetries.Contains(x.Id))
+ .OrderBy(x => x.Info.DrillingStartDate);
- var result = await memoryCache.GetOrCreateAsync(key, async entry =>
+ var dtos = telemetries.Select(x =>
{
- entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10);
+ var version = x.Info.Adapt();
+ version.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(version.TimeZoneOffsetTotalHours);
- var telemetries = await db.Set()
- .Include(x => x.Well)
- .Where(x => idTelemetries.Contains(x.Id))
- .OrderBy(x => x.Info.DrillingStartDate)
- .AsNoTracking()
- .ToArrayAsync(token);
-
- var dtos = telemetries.Select(x =>
+ var dto = new VersionDto
{
- var info = x.Info.Adapt();
- info.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(info.TimeZoneOffsetTotalHours);
+ IdWell = x.Well!.Id,
+ Version = version
+ };
- var dto = new WellTelemetryInfoDto
- {
- IdWell = x.Well!.Id,
- Info = info
- };
-
- return dto;
- });
-
- return dtos;
+ return dto;
});
- return result!;
+ return dtos;
}
[Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")]
diff --git a/AsbCloudWebApi/Controllers/TelemetryInfoController.cs b/AsbCloudWebApi/Controllers/TelemetryInfoController.cs
deleted file mode 100644
index d12acecc..00000000
--- a/AsbCloudWebApi/Controllers/TelemetryInfoController.cs
+++ /dev/null
@@ -1,58 +0,0 @@
-using System.Collections.Generic;
-using System.Threading;
-using System.Threading.Tasks;
-using AsbCloudApp.Data.SAUB;
-using AsbCloudApp.Requests;
-using AsbCloudApp.Services;
-using Microsoft.AspNetCore.Authorization;
-using Microsoft.AspNetCore.Http;
-using Microsoft.AspNetCore.Mvc;
-
-namespace AsbCloudWebApi.Controllers;
-
-///
-/// Версии прошивок
-///
-[Route("api/[controller]")]
-[ApiController]
-[Authorize]
-public class TelemetryInfoController : ControllerBase
-{
- private readonly ITelemetryService telemetryService;
-
- public TelemetryInfoController(ITelemetryService telemetryService)
- {
- this.telemetryService = telemetryService;
- }
-
- ///
- /// Получить список версий прошивок
- ///
- /// Необязательный параметр. Определяет состояние скважины
- /// null - возвращаются все записи
- /// 0 - неизвестно,
- /// 1 - в работе,
- /// 2 - завершена
- ///
- ///
- [HttpGet]
- [Permission]
- [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
- public async Task GetAsync([FromQuery] int? idWellState, CancellationToken token)
- {
- var idCompany = User.GetCompanyId();
-
- if (!idCompany.HasValue)
- return Forbid();
-
- var requestToService = new TelemetryInfoRequest
- {
- IdCompany = idCompany.Value,
- IdWellState = idWellState
- };
-
- var telemetriesInfo = await telemetryService.GetInfoAsync(requestToService, token);
-
- return Ok(telemetriesInfo);
- }
-}
\ No newline at end of file
diff --git a/AsbCloudWebApi/Controllers/VersionController.cs b/AsbCloudWebApi/Controllers/VersionController.cs
new file mode 100644
index 00000000..c62b53ee
--- /dev/null
+++ b/AsbCloudWebApi/Controllers/VersionController.cs
@@ -0,0 +1,50 @@
+using System.Collections.Generic;
+using System.Threading;
+using System.Threading.Tasks;
+using AsbCloudApp.Data.SAUB;
+using AsbCloudApp.Requests;
+using AsbCloudApp.Services;
+using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+
+namespace AsbCloudWebApi.Controllers;
+
+///
+/// Версии ПО
+///
+[Route("api/[controller]")]
+[ApiController]
+[Authorize]
+public class VersionController : ControllerBase
+{
+ private readonly ITelemetryService telemetryService;
+
+ public VersionController(ITelemetryService telemetryService)
+ {
+ this.telemetryService = telemetryService;
+ }
+
+ ///
+ /// Получить список версий ПО
+ ///
+ ///
+ ///
+ ///
+ [HttpGet]
+ [Permission]
+ [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
+ public async Task GetAsync([FromQuery] VersionRequestBase request, CancellationToken token)
+ {
+ var idCompany = User.GetCompanyId();
+
+ if (!idCompany.HasValue)
+ return Forbid();
+
+ var requestToService = new VersionRequest(idCompany.Value, request);
+
+ var version = await telemetryService.GetVersionsAsync(requestToService, token);
+
+ return Ok(version);
+ }
+}
\ No newline at end of file