From 7127dfd9bbd31eb1286f07fcd2b579a91db8ff7e Mon Sep 17 00:00:00 2001 From: "ai.astrakhantsev" Date: Mon, 13 Feb 2023 09:10:48 +0500 Subject: [PATCH] =?UTF-8?q?#8636739=20=D0=92=D0=B8=D0=B7=D1=83=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=82=D1=80=D0=B0=D0=B5?= =?UTF-8?q?=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=B8=203D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/TrajectoryVisualizationDataDto.cs | 41 ----------------- .../Data/TrajectoryVisualizationDto.cs | 14 +----- .../IPlannedTrajectoryRepository.cs} | 4 +- .../ITrajectoryVisualizationRepository.cs | 23 ---------- AsbCloudInfrastructure/DependencyInjection.cs | 3 +- .../PlannedTrajectoryRepository.cs} | 39 ++++++++-------- .../TrajectoryVisualizationRepository.cs | 44 ------------------- .../PlannedTrajectoryImportService.cs | 5 ++- .../TrajectoryVisualizationService.cs | 17 ++++--- .../PlannedTrajectoryController.cs | 17 +++---- 10 files changed, 46 insertions(+), 161 deletions(-) delete mode 100644 AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs rename AsbCloudApp/{Services/IPlannedTrajectoryService.cs => Repositories/IPlannedTrajectoryRepository.cs} (96%) delete mode 100644 AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs rename AsbCloudInfrastructure/{Services/PlannedTrajectory/PlannedTrajectoryService.cs => Repository/PlannedTrajectoryRepository.cs} (79%) delete mode 100644 AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs deleted file mode 100644 index 7fbce489..00000000 --- a/AsbCloudApp/Data/TrajectoryVisualizationDataDto.cs +++ /dev/null @@ -1,41 +0,0 @@ -namespace AsbCloudDb.Model -{ -#nullable enable - /// - /// Данные для визуализации траектории - /// - public class TrajectoryVisualizationDataDto - { - - /// - /// Глубина по стволу - /// - public double WellboreDepth { get; set; } - - /// - /// Зенит - /// - public double Zenith { get; set; } - - /// - /// Азимут - /// - public double Azimuth { get; set; } - - /// - /// Координаты по оси X - /// - public double X { get; set; } - - /// - /// Координаты по оси Y - /// - public double Y { get; set; } - - /// - /// Координаты по оси Z - /// - public double Z { get; set; } - } -#nullable disable -} diff --git a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs index 3d8cbe8c..bc67f9c0 100644 --- a/AsbCloudApp/Data/TrajectoryVisualizationDto.cs +++ b/AsbCloudApp/Data/TrajectoryVisualizationDto.cs @@ -3,18 +3,8 @@ /// /// Визуализация траектории 3D /// - public class TrajectoryVisualizationDto : IWellRelated - { - - /// - public int IdWell { get; set; } - - /// - /// Плоскость - /// - public double Flat { get; set; } - - /// + public class TrajectoryVisualizationDto + {/// /// Координаты по оси X /// public double X { get; set; } diff --git a/AsbCloudApp/Services/IPlannedTrajectoryService.cs b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs similarity index 96% rename from AsbCloudApp/Services/IPlannedTrajectoryService.cs rename to AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs index 31fc1130..b18f72cf 100644 --- a/AsbCloudApp/Services/IPlannedTrajectoryService.cs +++ b/AsbCloudApp/Repositories/IPlannedTrajectoryRepository.cs @@ -3,14 +3,14 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudApp.Services +namespace AsbCloudApp.Repositories { #nullable enable /// /// CRUD для работы с плановой траекторией из клиента /// /// - public interface IPlannedTrajectoryService + public interface IPlannedTrajectoryRepository { /// /// Получить все добавленные по скважине координаты плановой траектории diff --git a/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs b/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs deleted file mode 100644 index 24cb646b..00000000 --- a/AsbCloudApp/Repositories/ITrajectoryVisualizationRepository.cs +++ /dev/null @@ -1,23 +0,0 @@ -using AsbCloudDb.Model; -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudApp.Repositories -{ -#nullable enable - /// - /// Визуализация траектории 3D - /// - public interface ITrajectoryVisualizationRepository - { - /// - /// Получение данных для расчета - /// - /// - /// - /// - Task> GetAllAsync(int idWell, CancellationToken token); - } -#nullable disable -} diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 32a6f490..cfa4d8ac 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -126,7 +126,6 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -178,7 +177,7 @@ namespace AsbCloudInfrastructure services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); // Subsystem service services.AddTransient, CrudCacheRepositoryBase>(); diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs similarity index 79% rename from AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs rename to AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs index d00a9563..dba77d7b 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryService.cs +++ b/AsbCloudInfrastructure/Repository/PlannedTrajectoryRepository.cs @@ -1,5 +1,6 @@ using AsbCloudApp.Data; using AsbCloudApp.Exceptions; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; @@ -10,31 +11,33 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; -namespace AsbCloudInfrastructure.Services.PlannedTrajectory +namespace AsbCloudInfrastructure.Repository { #nullable enable - public class PlannedTrajectoryService : IPlannedTrajectoryService + public class PlannedTrajectoryRepository : IPlannedTrajectoryRepository { private readonly IAsbCloudDbContext db; private readonly IWellService wellService; - public PlannedTrajectoryService(IAsbCloudDbContext db, IWellService wellService) + public PlannedTrajectoryRepository(IAsbCloudDbContext db, IWellService wellService) { this.db = db; this.wellService = wellService; } /// public async Task AddRangeAsync(IEnumerable plannedTrajectoryRows, CancellationToken token) - { + { var idWell = plannedTrajectoryRows.First().IdWell; if (!plannedTrajectoryRows.All(r => r.IdWell == idWell)) throw new ArgumentInvalidException("Все строки должны относиться к одной скважине", nameof(plannedTrajectoryRows)); var offsetHours = wellService.GetTimezone(idWell).Hours; var entities = plannedTrajectoryRows - .Select(e => { + .Select(e => + { var entity = Convert(e, offsetHours); entity.Id = 0; - return entity;}); - + return entity; + }); + db.PlannedTrajectories.AddRange(entities); return await db.SaveChangesAsync(token) .ConfigureAwait(false); @@ -46,7 +49,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory var offsetHours = wellService.GetTimezone(plannedTrajectoryRow.IdWell).Hours; var entity = Convert(plannedTrajectoryRow, offsetHours); entity.Id = 0; - db.PlannedTrajectories.Add(entity); + db.PlannedTrajectories.Add(entity); return await db.SaveChangesAsync(token) .ConfigureAwait(false); } @@ -77,13 +80,13 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory var well = wellService.GetOrDefault(idWell); if (well is null || well.Timezone is null) throw new ArgumentInvalidException("idWell doesn`t exist", nameof(idWell)); - var offsetHours = well.Timezone.Hours; + var offsetHours = well.Timezone.Hours; var query = db.PlannedTrajectories .AsNoTracking() - .Where(x => x.IdWell == idWell); + .Where(x => x.IdWell == idWell); var entities = await query .OrderBy(e => e.WellboreDepth) - .ToListAsync(token); + .ToListAsync(token); var result = entities .Select(r => Convert(r, offsetHours)); return result; @@ -99,19 +102,19 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory .ConfigureAwait(false); } - private PlannedTrajectoryDto Convert(AsbCloudDb.Model.PlannedTrajectory entity, double offsetHours) - { - var dto = entity.Adapt(); + private PlannedTrajectoryDto Convert(PlannedTrajectory entity, double offsetHours) + { + var dto = entity.Adapt(); dto.UpdateDate = entity.UpdateDate.ToRemoteDateTime(offsetHours); return dto; } - private AsbCloudDb.Model.PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours) - { - var entity = dto.Adapt(); + private PlannedTrajectory Convert(PlannedTrajectoryDto dto, double offsetHours) + { + var entity = dto.Adapt(); entity.UpdateDate = DateTime.Now.ToUtcDateTimeOffset(offsetHours); return entity; - } + } } #nullable disable } diff --git a/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs b/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs deleted file mode 100644 index 76b11e7a..00000000 --- a/AsbCloudInfrastructure/Repository/TrajectoryVisualizationRepository.cs +++ /dev/null @@ -1,44 +0,0 @@ -using AsbCloudApp.Repositories; -using AsbCloudDb.Model; -using Microsoft.EntityFrameworkCore; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; - -namespace AsbCloudInfrastructure.Repository -{ -#nullable enable - public class TrajectoryVisualizationRepository : ITrajectoryVisualizationRepository - { - private readonly IAsbCloudDbContext context; - - public TrajectoryVisualizationRepository(IAsbCloudDbContext context) - { - this.context = context; - } - - /// - public async Task> GetAllAsync(int idWell, CancellationToken token) - { - var dtos = await context.PlannedTrajectories - .Where(t => t.IdWell == idWell) - .OrderBy(x => x.UpdateDate) - .Select(x => Convert(x)) - .ToListAsync(token) - .ConfigureAwait(false); - - return dtos; - } - - private static TrajectoryVisualizationDataDto Convert(PlannedTrajectory dto) - { - return new TrajectoryVisualizationDataDto { - WellboreDepth = dto.WellboreDepth, - Azimuth = dto.AzimuthGeo, - Zenith = dto.ZenithAngle - }; - } - } -#nullable disable -} diff --git a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs index 8e2278fa..0bf97365 100644 --- a/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs +++ b/AsbCloudInfrastructure/Services/PlannedTrajectory/PlannedTrajectoryImportService.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using ClosedXML.Excel; using System; @@ -18,7 +19,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory */ private readonly IWellService wellService; - private readonly IPlannedTrajectoryService plannedTrajectoryService; + private readonly IPlannedTrajectoryRepository plannedTrajectoryService; private const string templateFileName = "PlannedTrajectoryTemplate.xlsx"; private const string usingTemplateFile = "AsbCloudInfrastructure.Services.PlannedTrajectory"; @@ -40,7 +41,7 @@ namespace AsbCloudInfrastructure.Services.PlannedTrajectory private const int ColumnOrificeOffset = 14; private const int ColumnComment = 15; - public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryService plannedTrajectoryService) + public PlannedTrajectoryImportService(IWellService wellService, IPlannedTrajectoryRepository plannedTrajectoryService) { this.wellService = wellService; diff --git a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs index 97aae641..c6ad3b4b 100644 --- a/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs +++ b/AsbCloudInfrastructure/Services/TrajectoryVisualizationService.cs @@ -11,9 +11,9 @@ namespace AsbCloudInfrastructure.Services { public class TrajectoryVisualizationService : ITrajectoryVisualizationService { - private readonly ITrajectoryVisualizationRepository repository; + private readonly IPlannedTrajectoryRepository repository; - public TrajectoryVisualizationService(ITrajectoryVisualizationRepository repository) + public TrajectoryVisualizationService(IPlannedTrajectoryRepository repository) { this.repository = repository; } @@ -21,22 +21,21 @@ namespace AsbCloudInfrastructure.Services public async Task> GetTrajectoryAsync(int idWell, CancellationToken token) { var result = new List(); - var dto = (await repository.GetAllAsync(idWell, token)).ToArray(); + var dto = (await repository.GetAsync(idWell, token)).ToArray(); var prevData = dto[0]; + var prevCoordinates = new TrajectoryVisualizationDto(); for (var i = 1; i < dto.Length; i++) { var data = dto[i]; - var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.Zenith); - var x = data.X = GetX(data.Azimuth, flat, prevData.X); - var y = data.Y = GetY(data.Azimuth, flat, prevData.Y); - var z = data.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.Zenith, prevData.Z); + var flat = GetFlat(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle); + var x = prevCoordinates.X = GetX(data.AzimuthGeo, flat, prevCoordinates.X); + var y = prevCoordinates.Y = GetY(data.AzimuthGeo, flat, prevCoordinates.Y); + var z = prevCoordinates.Z = GetZ(data.WellboreDepth, prevData.WellboreDepth, data.ZenithAngle, prevCoordinates.Z); prevData = data; var coordinates = new TrajectoryVisualizationDto { - IdWell = idWell, - Flat = flat, X = x, Y = y, Z = z diff --git a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs index cd1c1ed6..d396618f 100644 --- a/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs +++ b/AsbCloudWebApi/Controllers/PlannedTrajectoryController.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Repositories; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -21,13 +22,13 @@ namespace AsbCloudWebApi.Controllers { private readonly IWellService wellService; private readonly IPlannedTrajectoryImportService plannedTrajectoryImportService; - private readonly IPlannedTrajectoryService plannedTrajectoryService; + private readonly IPlannedTrajectoryRepository plannedTrajectoryRepository; - public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryService plannedTrajectoryService) + public PlannedTrajectoryController(IWellService wellService, IPlannedTrajectoryImportService plannedTrajectoryImportService, IPlannedTrajectoryRepository plannedTrajectoryRepository) { this.plannedTrajectoryImportService = plannedTrajectoryImportService; this.wellService = wellService; - this.plannedTrajectoryService = plannedTrajectoryService; + this.plannedTrajectoryRepository = plannedTrajectoryRepository; } /// @@ -121,7 +122,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - var result = await plannedTrajectoryService.GetAsync(idWell, token); + var result = await plannedTrajectoryRepository.GetAsync(idWell, token); return Ok(result); } @@ -146,7 +147,7 @@ namespace AsbCloudWebApi.Controllers return Forbid(); row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.AddAsync(row, token); + var result = await plannedTrajectoryRepository.AddAsync(row, token); return Ok(result); } @@ -174,7 +175,7 @@ namespace AsbCloudWebApi.Controllers item.IdUser = idUser.Value; item.IdWell = idWell; } - var result = await plannedTrajectoryService.AddRangeAsync(rows, token); + var result = await plannedTrajectoryRepository.AddRangeAsync(rows, token); return Ok(result); } @@ -200,7 +201,7 @@ namespace AsbCloudWebApi.Controllers row.Id = idRow; row.IdUser = idUser.Value; row.IdWell = idWell; - var result = await plannedTrajectoryService.UpdateAsync(row, token); + var result = await plannedTrajectoryRepository.UpdateAsync(row, token); return Ok(result); } @@ -220,7 +221,7 @@ namespace AsbCloudWebApi.Controllers token).ConfigureAwait(false)) return Forbid(); - var result = await plannedTrajectoryService.DeleteRangeAsync(new int[] { idRow }, token); + var result = await plannedTrajectoryRepository.DeleteRangeAsync(new int[] { idRow }, token); return Ok(result); }