From 626c3cb238d8b2cc0a44b237ab0c9c5962c2c3b9 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Tue, 26 Mar 2024 15:23:24 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20GetTimezone=20(?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D0=B1=D0=BE=D0=BB=D1=8C=D1=88?= =?UTF-8?q?=D0=B5=20=D0=BD=D0=B5=20=D0=BC=D0=B0=D0=BF=D0=BF=D0=B8=D1=82=20?= =?UTF-8?q?=D0=B2=20dto)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/WellService.cs | 68 ++++--------------- 1 file changed, 14 insertions(+), 54 deletions(-) diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index ac457347..853a0773 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -116,12 +116,12 @@ namespace AsbCloudInfrastructure.Services if (well is null) return null; - + var wellInfo = wellInfoService.FirstOrDefault(well => well.Id == idWell); if (wellInfo is null) return well.Adapt(); - + wellInfo.IdState = well.IdState; return wellInfo; } @@ -153,7 +153,7 @@ namespace AsbCloudInfrastructure.Services { if (IsTelemetryAssignedToDifferentWell(dto)) throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине."); - + if (dto.Id != 0 && (await GetCacheAsync(token)).Any(w => w.Id == dto.Id)) throw new ArgumentInvalidException(nameof(dto), $"Нельзя повторно добавить скважину с id: {dto.Id}"); @@ -177,12 +177,12 @@ namespace AsbCloudInfrastructure.Services throw new NotImplementedException(); } - public override async Task UpdateAsync(WellDto dto, + public override async Task UpdateAsync(WellDto dto, CancellationToken token) { if (IsTelemetryAssignedToDifferentWell(dto)) throw new ArgumentInvalidException(nameof(dto), "Телеметрия уже была привязана к другой скважине."); - + var oldRelations = (await GetCacheRelationCompanyWellAsync(token)) .Where(r => r.IdWell == dto.Id).ToArray(); @@ -192,16 +192,16 @@ namespace AsbCloudInfrastructure.Services dbContext.RelationCompaniesWells .RemoveRange(dbContext.RelationCompaniesWells .Where(r => r.IdWell == dto.Id)); - + DropCacheRelationCompanyWell(); var newRelations = dto.Companies .Select(c => new RelationCompanyWell { - IdWell = dto.Id, + IdWell = dto.Id, IdCompany = c.Id }); - + dbContext.RelationCompaniesWells.AddRange(newRelations); } @@ -215,7 +215,7 @@ namespace AsbCloudInfrastructure.Services public async Task GetWellCaptionByIdAsync(int idWell, CancellationToken token) { - var entity = await GetOrDefaultAsync(idWell, token).ConfigureAwait(false); + var entity = await GetOrDefaultAsync(idWell, token).ConfigureAwait(false); return entity!.Caption; } @@ -270,10 +270,7 @@ namespace AsbCloudInfrastructure.Services { var dto = base.Convert(entity); - if (entity.Timezone is null) - dto.Timezone = GetTimezone(entity.Id); - - dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id)?.ToOffset(TimeSpan.FromHours(dto.Timezone.Hours)); + dto.StartDate = wellOperationRepository.FirstOperationDate(entity.Id); dto.WellType = entity.WellType.Caption; dto.Cluster = entity.Cluster.Caption; dto.Deposit = entity.Cluster.Deposit.Caption; @@ -296,47 +293,10 @@ namespace AsbCloudInfrastructure.Services public SimpleTimezoneDto GetTimezone(int idWell) { - var well = GetOrDefault(idWell) + var cache = GetCache(); + var cacheItem = cache.FirstOrDefault(d => d.Id == idWell) ?? throw new ArgumentInvalidException(nameof(idWell), $"idWell: {idWell} does not exist."); - return GetTimezone(well); - } - - private SimpleTimezoneDto GetTimezone(WellDto wellDto) - { - if (wellDto.Timezone is not null) - return wellDto.Timezone; - - if (wellDto.Telemetry is not null) - { - var timezone = telemetryService.GetTimezone(wellDto.Telemetry.Id); - if (timezone is not null) - return timezone; - } - - var well = GetQuery().FirstOrDefault(w => w.Id == wellDto.Id); - - if (well is not null) - { - var point = GetCoordinates(well); - if (point is not null) - { - if (point.Timezone is not null) - { - return point.Timezone.Adapt(); - } - - if (point.Latitude is not null & point.Longitude is not null) - { - var timezone = timezoneService.GetOrDefaultByCoordinates(point.Latitude!.Value, point.Longitude!.Value); - if (timezone is not null) - { - return timezone; - } - } - } - } - - throw new Exception($"Can't find timezone for well {wellDto.Caption} id: {wellDto.Id}"); + return cacheItem.Timezone.Adapt(); } private bool IsTelemetryAssignedToDifferentWell(WellDto wellDto) @@ -349,7 +309,7 @@ namespace AsbCloudInfrastructure.Services if (existingWellWithAssignedTelemetry is null) return false; - + return existingWellWithAssignedTelemetry.Id != wellDto.Id; }