From 5948a762bae7a23313e4ee0610a644128caabc92 Mon Sep 17 00:00:00 2001 From: ngfrolov Date: Wed, 11 Jan 2023 16:00:11 +0500 Subject: [PATCH] #7963103 fixes --- .../Data/SAUB/TelemetryWirelineRunOutDto.cs | 2 +- .../ITelemetryWirelineRunOutRepository.cs | 2 +- AsbCloudDb/Model/TelemetryWirelineRunOut.cs | 2 +- AsbCloudInfrastructure/DateTimeExtentions.cs | 12 ++++++ .../TelemetryWirelineRunOutRepository.cs | 40 +++++++++---------- .../SAUB/TelemetryWirelineRunOutController.cs | 6 ++- 6 files changed, 39 insertions(+), 25 deletions(-) diff --git a/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs b/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs index 862f7fa3..fb75c933 100644 --- a/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs +++ b/AsbCloudApp/Data/SAUB/TelemetryWirelineRunOutDto.cs @@ -11,7 +11,7 @@ namespace AsbCloudApp.Data.SAUB /// /// отметка времени /// - public DateTimeOffset DateTime { get; set; } + public DateTime DateTime { get; set; } /// /// Наработка талевого каната с момента перетяжки каната, т*км diff --git a/AsbCloudApp/Repositories/ITelemetryWirelineRunOutRepository.cs b/AsbCloudApp/Repositories/ITelemetryWirelineRunOutRepository.cs index f3e11814..b79c370b 100644 --- a/AsbCloudApp/Repositories/ITelemetryWirelineRunOutRepository.cs +++ b/AsbCloudApp/Repositories/ITelemetryWirelineRunOutRepository.cs @@ -28,7 +28,7 @@ namespace AsbCloudApp.Repositories /// /// /// - Task GetValueOrDefaultAsync(int idWell, CancellationToken token); + Task GetOrDefaultAsync(int idWell, CancellationToken token); /// /// Возвращает данные по всем скважинам diff --git a/AsbCloudDb/Model/TelemetryWirelineRunOut.cs b/AsbCloudDb/Model/TelemetryWirelineRunOut.cs index 86af2463..0d9ab12c 100644 --- a/AsbCloudDb/Model/TelemetryWirelineRunOut.cs +++ b/AsbCloudDb/Model/TelemetryWirelineRunOut.cs @@ -13,7 +13,7 @@ namespace AsbCloudDb.Model public int IdTelemetry { get; set; } [Column("date_time"), Comment("Отметка времени")] - public DateTime DateTime { get; set; } + public DateTimeOffset DateTime { get; set; } [Column("hauling"), Comment("Наработка талевого каната с момента перетяжки каната, т*км")] public float Hauling { get; set; } diff --git a/AsbCloudInfrastructure/DateTimeExtentions.cs b/AsbCloudInfrastructure/DateTimeExtentions.cs index 10a20972..181740a5 100644 --- a/AsbCloudInfrastructure/DateTimeExtentions.cs +++ b/AsbCloudInfrastructure/DateTimeExtentions.cs @@ -4,6 +4,12 @@ namespace AsbCloudInfrastructure { public static class DateTimeExtentions { + /// + /// Приветсти к UTC из времени куста + /// + /// + /// + /// public static DateTimeOffset ToUtcDateTimeOffset(this DateTime date, double remoteTimezoneOffsetHours) { if (date == default) @@ -18,6 +24,12 @@ namespace AsbCloudInfrastructure return new DateTimeOffset(dateUtc); } + /// + /// Привести ко времени куста из utc + /// + /// + /// + /// public static DateTime ToRemoteDateTime(this DateTimeOffset date, double remoteTimezoneOffsetHours) { if (date == default) diff --git a/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs b/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs index aeb1b8ee..134a1ac8 100644 --- a/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs +++ b/AsbCloudInfrastructure/Repository/TelemetryWirelineRunOutRepository.cs @@ -4,7 +4,7 @@ using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb; using AsbCloudDb.Model; -using DocumentFormat.OpenXml.Spreadsheet; +using AsbCloudInfrastructure.Services.SAUB; using Mapster; using Microsoft.EntityFrameworkCore; using System.Collections.Generic; @@ -34,29 +34,34 @@ namespace AsbCloudInfrastructure.Repository public async Task AddOrUpdateAsync(string uid, TelemetryWirelineRunOutDto dto, CancellationToken token) { var idTelemetry = telemetryService.GetOrCreateTelemetryIdByUid(uid); - var entity = Convert(idTelemetry, dto); + var timezoneOffset = telemetryService.GetTimezone(idTelemetry).Hours; + var entity = Convert(idTelemetry, dto, timezoneOffset); var updatingItem = context.TelemetryWirelineRunOut .Where(x => x.IdTelemetry == idTelemetry) - .AsNoTracking() .FirstOrDefault(); if (updatingItem is null) context.TelemetryWirelineRunOut.Add(entity); else - context.TelemetryWirelineRunOut.Upsert(entity); + context.TelemetryWirelineRunOut.Update(entity); return await context.SaveChangesAsync(token); } /// - public async Task GetValueOrDefaultAsync(int idWell, CancellationToken token) + public async Task GetOrDefaultAsync(int idWell, CancellationToken token) { var well = await wellService.GetOrDefaultAsync(idWell, token).ConfigureAwait(false); if (well is null) return null; - var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell); + return await GetOrDefaultAsync(well, token); + } + + private async Task GetOrDefaultAsync(WellDto well, CancellationToken token) + { + var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(well.Id); if (idTelemetry is null) return null; @@ -69,26 +74,20 @@ namespace AsbCloudInfrastructure.Repository if (entity is null) return null; - var timezone = telemetryService.GetTimezone((int)idTelemetry); - return Convert(entity, well, timezone.Hours); + var timezoneHours = well.Timezone.Hours; + return Convert(entity, well, timezoneHours); } /// public async Task> GetAllAsync(int idCompany, CancellationToken token) { - var result = new List(); - var wells = await wellService.GetAllAsync(token) + var wells = await wellService.GetWellsByCompanyAsync(idCompany, token) .ConfigureAwait(false); + var result = new List(wells.Count()); foreach (var well in wells) { - bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync(idCompany, well.Id, token) - .ConfigureAwait(false); - - if (!isCompanyOwnsWell) - continue; - - var dto = await GetValueOrDefaultAsync(well.Id, token); + var dto = await GetOrDefaultAsync(well, token); if (dto is not null) result.Add(dto); } @@ -96,17 +95,18 @@ namespace AsbCloudInfrastructure.Repository return result; } - private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto) + private static TelemetryWirelineRunOut Convert(int idTelemetry, TelemetryWirelineRunOutDto dto, double timezoneOffset) { var entity = dto.Adapt(); entity.IdTelemetry = idTelemetry; - entity.DateTime = entity.DateTime.ToUniversalTime(); + entity.DateTime = dto.DateTime.ToUtcDateTimeOffset(timezoneOffset); return entity; } + private static TelemetryWirelineRunOutDto Convert(TelemetryWirelineRunOut entity, WellDto well, double timezoneOffset) { var dto = entity.Adapt(); - dto.DateTime = entity.DateTime.ToUtcDateTimeOffset(timezoneOffset); + dto.DateTime = entity.DateTime.ToRemoteDateTime(timezoneOffset); dto.WellInfo = well; return dto; } diff --git a/AsbCloudWebApi/Controllers/SAUB/TelemetryWirelineRunOutController.cs b/AsbCloudWebApi/Controllers/SAUB/TelemetryWirelineRunOutController.cs index 5896b51b..c32fd408 100644 --- a/AsbCloudWebApi/Controllers/SAUB/TelemetryWirelineRunOutController.cs +++ b/AsbCloudWebApi/Controllers/SAUB/TelemetryWirelineRunOutController.cs @@ -11,6 +11,7 @@ using AsbCloudApp.Repositories; namespace AsbCloudWebApi.Controllers.SAUB { +#nullable enable /// /// Наработка талевого каната /// @@ -86,7 +87,7 @@ namespace AsbCloudWebApi.Controllers.SAUB if (!isCompanyOwnsWell) return Forbid(); - var dto = await repository.GetValueOrDefaultAsync(idWell, token); + var dto = await repository.GetOrDefaultAsync(idWell, token); if (dto is null) return NoContent(); @@ -103,6 +104,7 @@ namespace AsbCloudWebApi.Controllers.SAUB var dtos = await repository.GetAllAsync((int)idCompany, token); return Ok(dtos); } - } + +#nullable disable }