From da52a8d9b656bc6ecff3f7833f507c5a4337cf7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Mon, 26 Aug 2024 11:08:32 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=81=D0=B8=D0=B9=20=D0=BF=D1=80=D0=BE=D1=88=D0=B8=D0=B2?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs | 16 ++++++++ AsbCloudApp/Requests/TelemetryInfoRequest.cs | 4 +- AsbCloudApp/Services/ITelemetryService.cs | 2 +- .../Services/SAUB/TelemetryService.cs | 39 ++++++++++++------- .../Controllers/TelemetryInfoController.cs | 7 ++-- 5 files changed, 47 insertions(+), 21 deletions(-) diff --git a/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs b/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs index 732fca23..10b36719 100644 --- a/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs +++ b/AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs @@ -67,3 +67,19 @@ 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/Requests/TelemetryInfoRequest.cs b/AsbCloudApp/Requests/TelemetryInfoRequest.cs index fb6f68d4..82b36a32 100644 --- a/AsbCloudApp/Requests/TelemetryInfoRequest.cs +++ b/AsbCloudApp/Requests/TelemetryInfoRequest.cs @@ -11,10 +11,10 @@ public class TelemetryInfoRequest public int IdCompany { get; set; } /// - /// Определяет состояние скважины + /// Необязательный параметр. Определяет состояние скважины /// 0 - неизвестно, /// 1 - в работе, /// 2 - завершена /// - public int IdWellState { get; set; } + public int? IdWellState { get; set; } } \ No newline at end of file diff --git a/AsbCloudApp/Services/ITelemetryService.cs b/AsbCloudApp/Services/ITelemetryService.cs index 9ebdb36e..e59ef022 100644 --- a/AsbCloudApp/Services/ITelemetryService.cs +++ b/AsbCloudApp/Services/ITelemetryService.cs @@ -69,7 +69,7 @@ public interface ITelemetryService /// /// /// - Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token); + Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token); /// /// Слить данные телеметрии в одну diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs index d67f3a18..96db61ce 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs @@ -78,15 +78,18 @@ public class TelemetryService : ITelemetryService DropTelemetryCache(); } - public async Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token) + public async Task> GetInfoAsync(TelemetryInfoRequest request, CancellationToken token) { - var idTelemetries = await db.Set() + var wells = db.Set() .Include(x => x.RelationCompaniesWells) - .Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany) && - x.IdState == request.IdWellState) - .Where(x => x.IdTelemetry.HasValue) - .Select(x => x.IdTelemetry!.Value) - .ToArrayAsync(token); + .Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany)); + + if (request.IdWellState.HasValue) + wells = wells.Where(x => x.IdState == request.IdWellState); + + var idTelemetries = await wells.Where(x => x.IdTelemetry.HasValue) + .Select(x => x.IdTelemetry!.Value) + .ToArrayAsync(token); var key = $"TelemetryInfo_{string.Join("", idTelemetries)}"; @@ -94,19 +97,25 @@ public class TelemetryService : ITelemetryService { entry.AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(10); - var query = db.Set() + var telemetries = await db.Set() + .Include(x => x.Well) .Where(x => idTelemetries.Contains(x.Id)) - .OrderBy(x => x.Info.DrillingStartDate); - - var entities = await query + .OrderBy(x => x.Info.DrillingStartDate) .AsNoTracking() .ToArrayAsync(token); - var dtos = entities.Select(x => + var dtos = telemetries.Select(x => { - var dto = x.Info.Adapt(); - dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours); - return dto; + var info = x.Info.Adapt(); + info.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(info.TimeZoneOffsetTotalHours); + + var dto = new WellTelemetryInfoDto + { + IdWell = x.Well!.Id, + Info = info + }; + + return dto; }); return dtos; diff --git a/AsbCloudWebApi/Controllers/TelemetryInfoController.cs b/AsbCloudWebApi/Controllers/TelemetryInfoController.cs index b7890f18..d12acecc 100644 --- a/AsbCloudWebApi/Controllers/TelemetryInfoController.cs +++ b/AsbCloudWebApi/Controllers/TelemetryInfoController.cs @@ -28,7 +28,8 @@ public class TelemetryInfoController : ControllerBase /// /// Получить список версий прошивок /// - /// Определяет состояние скважины + /// Необязательный параметр. Определяет состояние скважины + /// null - возвращаются все записи /// 0 - неизвестно, /// 1 - в работе, /// 2 - завершена @@ -36,8 +37,8 @@ public class TelemetryInfoController : ControllerBase /// [HttpGet] [Permission] - [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] - public async Task GetAsync([FromQuery] int idWellState, CancellationToken token) + [ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)] + public async Task GetAsync([FromQuery] int? idWellState, CancellationToken token) { var idCompany = User.GetCompanyId(); From 1a9ad8a904009ec375bfb9d7e2071e9cc2e2a1e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Tue, 27 Aug 2024 16:55:49 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Изменил нейминг 2. Поправил метод получения версии ПО. Поправил кеширование 3. В запрос добавил дополнительные прафила фильтрации --- AsbCloudApp/Data/SAUB/TelemetryInfoDto.cs | 16 ----- AsbCloudApp/Data/SAUB/VersionDto.cs | 17 ++++++ AsbCloudApp/Requests/TelemetryInfoRequest.cs | 20 ------ AsbCloudApp/Requests/VersionRequest.cs | 61 +++++++++++++++++++ AsbCloudApp/Services/ITelemetryService.cs | 4 +- .../Services/SAUB/TelemetryService.cs | 41 +++++-------- .../Controllers/TelemetryInfoController.cs | 58 ------------------ .../Controllers/VersionController.cs | 50 +++++++++++++++ 8 files changed, 146 insertions(+), 121 deletions(-) create mode 100644 AsbCloudApp/Data/SAUB/VersionDto.cs delete mode 100644 AsbCloudApp/Requests/TelemetryInfoRequest.cs create mode 100644 AsbCloudApp/Requests/VersionRequest.cs delete mode 100644 AsbCloudWebApi/Controllers/TelemetryInfoController.cs create mode 100644 AsbCloudWebApi/Controllers/VersionController.cs 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 From b6cbc63267fa22b8767b1b9ffa61f0ee219ed871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 28 Aug 2024 09:43:56 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B2?= =?UTF-8?q?=D0=BB=D0=BE=D0=B6=D0=B5=D0=BD=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20?= =?UTF-8?q?DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/VersionDto.cs | 63 ++++++++++++++++++- .../Services/SAUB/TelemetryService.cs | 11 +--- 2 files changed, 63 insertions(+), 11 deletions(-) diff --git a/AsbCloudApp/Data/SAUB/VersionDto.cs b/AsbCloudApp/Data/SAUB/VersionDto.cs index a5d48cfa..37150f32 100644 --- a/AsbCloudApp/Data/SAUB/VersionDto.cs +++ b/AsbCloudApp/Data/SAUB/VersionDto.cs @@ -1,4 +1,6 @@ -namespace AsbCloudApp.Data.SAUB; +using System; + +namespace AsbCloudApp.Data.SAUB; /// /// Версия ПО @@ -11,7 +13,62 @@ public class VersionDto public int IdWell { get; set; } /// - /// Информация о версии + /// дата начала бурения (заполнения данных на панели) /// - public TelemetryInfoDto Version { get; set; } = null!; + public DateTime DrillingStartDate { get; set; } + + /// + /// идентификатор временной зоны + /// + public string? TimeZoneId { get; set; } + + /// + /// смещение в часах относительно UTC + /// + public double TimeZoneOffsetTotalHours { get; set; } + + /// + /// название скважины + /// + public string Well { get; set; } = string.Empty; + + /// + /// название куста + /// + public string Cluster { get; set; } = string.Empty; + + /// + /// название месторождения + /// + public string Deposit { get; set; } = string.Empty; + + /// + /// название заказчика + /// + public string? Customer { get; set; } + + /// + /// версия ПО панели оператора + /// + public string? HmiVersion { get; set; } + + /// + /// версия ПО ПЛК САУБ + /// + public string? SaubPlcVersion { get; set; } + + /// + /// версия ПО ПЛК Спин мастер + /// + public string? SpinPlcVersion { get; set; } + + /// + /// версия ПО ПЛК Памп мастер + /// + public string? PumpPlcVersion { get; set; } + + /// + /// комментарий + /// + public string? Comment { get; set; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs index b624f16b..24c48795 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs @@ -100,14 +100,9 @@ public class TelemetryService : ITelemetryService var dtos = telemetries.Select(x => { - var version = x.Info.Adapt(); - version.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(version.TimeZoneOffsetTotalHours); - - var dto = new VersionDto - { - IdWell = x.Well!.Id, - Version = version - }; + var dto = x.Info.Adapt(); + dto.IdWell = x.Well!.Id; + dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours); return dto; }); From 053b21040149527756e3d14515c872dca86e8435 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D1=82=D0=B5=D0=BF=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=94?= =?UTF-8?q?=D0=BC=D0=B8=D1=82=D1=80=D0=B8=D0=B9?= Date: Wed, 28 Aug 2024 11:13:09 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?DTO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/SAUB/VersionDto.cs | 20 ---------- .../Services/SAUB/TelemetryService.cs | 39 +++++++++++++------ 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/AsbCloudApp/Data/SAUB/VersionDto.cs b/AsbCloudApp/Data/SAUB/VersionDto.cs index 37150f32..581640d3 100644 --- a/AsbCloudApp/Data/SAUB/VersionDto.cs +++ b/AsbCloudApp/Data/SAUB/VersionDto.cs @@ -12,21 +12,6 @@ public class VersionDto /// public int IdWell { get; set; } - /// - /// дата начала бурения (заполнения данных на панели) - /// - public DateTime DrillingStartDate { get; set; } - - /// - /// идентификатор временной зоны - /// - public string? TimeZoneId { get; set; } - - /// - /// смещение в часах относительно UTC - /// - public double TimeZoneOffsetTotalHours { get; set; } - /// /// название скважины /// @@ -66,9 +51,4 @@ public class VersionDto /// версия ПО ПЛК Памп мастер /// public string? PumpPlcVersion { get; set; } - - /// - /// комментарий - /// - public string? Comment { get; set; } } \ No newline at end of file diff --git a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs index 24c48795..6de56bdc 100644 --- a/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/SAUB/TelemetryService.cs @@ -80,29 +80,43 @@ public class TelemetryService : ITelemetryService public async Task> GetVersionsAsync(VersionRequest request, CancellationToken token) { - var wells = db.Set() + var query = db.Set() .Include(x => x.RelationCompaniesWells) + .ThenInclude(x => x.Company) + .Include(x => x.Cluster) + .ThenInclude(c => c.Deposit) .Where(x => x.RelationCompaniesWells.Any(y => y.IdCompany == request.IdCompany)); if (request.IdWellState.HasValue) - wells = wells.Where(x => x.IdState == request.IdWellState); + query = query.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); + query = query.Where(x => request.IdsWell.Contains(x.Id)); + + var wells = await query.Where(x => x.IdTelemetry.HasValue) + .ToDictionaryAsync(x => x.Id, x => x, token); + + var idTelemetries = wells.Select(x => x.Value.IdTelemetry!.Value); var telemetries = GetTelemetryCache() .Where(x => idTelemetries.Contains(x.Id)) .OrderBy(x => x.Info.DrillingStartDate); - var dtos = telemetries.Select(x => - { - var dto = x.Info.Adapt(); - dto.IdWell = x.Well!.Id; - dto.DrillingStartDate = x.Info.DrillingStartDate.ToRemoteDateTime(dto.TimeZoneOffsetTotalHours); + var dtos = telemetries.Select(x => + { + var well = wells[x.Well!.Id]; + + var dto = new VersionDto + { + IdWell = well.Id, + Well = well.Caption, + Cluster = well.Cluster.Caption, + Deposit = well.Cluster.Deposit.Caption, + Customer = well.RelationCompaniesWells.Select(r => r.Company).FirstOrDefault(c => c.IdCompanyType == 1)?.Caption, + HmiVersion = x.Info.HmiVersion, + SaubPlcVersion = x.Info.SaubPlcVersion, + SpinPlcVersion = x.Info.SpinPlcVersion, + }; return dto; }); @@ -110,6 +124,7 @@ public class TelemetryService : ITelemetryService return dtos; } + [Obsolete("This method will be private. Use TelemetryDto.TimeZone prop.")] public SimpleTimezoneDto GetTimezone(int idTelemetry) {