From 9926d3fcf21383528fd018cbaae211eb9d8bf521 Mon Sep 17 00:00:00 2001 From: Olga Nemt Date: Mon, 22 Apr 2024 15:31:04 +0500 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=81=D0=B5=D0=BA=D1=86=D0=B8=D0=B9=20=D0=B8=20?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D0=B5=D0=B3=D0=BE=D1=80=D0=B8=D0=B9=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B7=20Lazy=20+=20=D0=BA=D0=BE=D0=BF=D0=B8?= =?UTF-8?q?=D1=80=D1=83=D1=8E=D1=89=D0=B8=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=81?= =?UTF-8?q?=D1=82=D1=80=D1=83=D0=BA=D1=82=D0=BE=D1=80=20=D0=B2=D0=BD=D1=83?= =?UTF-8?q?=D1=82=D1=80=D0=B8=20WellOperationRequestBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Requests/WellOperationRequest.cs | 43 ++++++++++----- .../Repository/WellOperationRepository.cs | 53 +++++++++---------- 2 files changed, 55 insertions(+), 41 deletions(-) diff --git a/AsbCloudApp/Requests/WellOperationRequest.cs b/AsbCloudApp/Requests/WellOperationRequest.cs index 2dc6405b..71f5e7d0 100644 --- a/AsbCloudApp/Requests/WellOperationRequest.cs +++ b/AsbCloudApp/Requests/WellOperationRequest.cs @@ -47,6 +47,34 @@ public class WellOperationRequestBase : RequestBase /// Идентификаторы конструкций секции /// public IEnumerable? SectionTypeIds { get; set; } + + /// + /// + /// + public WellOperationRequestBase() + { + + } + + /// + /// + /// + /// + public WellOperationRequestBase(WellOperationRequestBase request) + { + GeDepth = request.GeDepth; + LeDepth = request.LeDepth; + GeDate = request.GeDate; + LeDate = request.LeDate; + + OperationCategoryIds = request.OperationCategoryIds; + OperationType = request.OperationType; + SectionTypeIds = request.SectionTypeIds; + + Skip = request.Skip; + Take = request.Take; + SortFields = request.SortFields; + } } /// @@ -62,20 +90,9 @@ public class WellOperationRequest : WellOperationRequestBase /// public WellOperationRequest(WellOperationRequestBase request, IEnumerable idsWell) - : this(idsWell) + : base(request) { - GeDepth = request.GeDepth; - LeDepth = request.LeDepth; - GeDate = request.GeDate; - LeDate = request.LeDate; - - OperationCategoryIds = request.OperationCategoryIds; - OperationType = request.OperationType; - SectionTypeIds = request.SectionTypeIds; - - Skip = request.Skip; - Take = request.Take; - SortFields = request.SortFields; + IdsWell = idsWell; } /// diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 959ad0d9..ba457362 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -23,6 +23,8 @@ public class WellOperationRepository : CrudRepositoryBase> LazyWellCategories { get; } + private Lazy> LazyWellSectionTypes { get; } public WellOperationRepository(IAsbCloudDbContext context, IMemoryCache memoryCache, @@ -33,6 +35,9 @@ public class WellOperationRepository : CrudRepositoryBase wellOperationCategoryRepository.Get(true, false).ToDictionary(c => c.Id)); + LazyWellSectionTypes = new(() => GetSectionTypes().ToDictionary(c => c.Id)); } public IEnumerable GetSectionTypes() => @@ -43,7 +48,7 @@ public class WellOperationRepository : CrudRepositoryBase> GetAsync(WellOperationRequest request, CancellationToken token) { - var (items, _) = await GetAsyncWithDaysAndNpv(request, token); + var (items, _) = await GetWithDaysAndNpvAsync(request, token); return items; } @@ -52,7 +57,7 @@ public class WellOperationRepository : CrudRepositoryBase { @@ -165,27 +170,24 @@ public class WellOperationRepository : CrudRepositoryBase> GetByIdsWells(IEnumerable idsWells, CancellationToken token) { var query = GetQuery() - .Include(e => e.WellSectionType) - .Include(e => e.OperationCategory) .Where(e => idsWells.Contains(e.IdWell)) .OrderBy(e => e.DateStart); var entities = await query.ToArrayAsync(token); return entities; } - private async Task<(IEnumerable items, int count)> GetAsyncWithDaysAndNpv(WellOperationRequest request, CancellationToken token) + private async Task<(IEnumerable items, int count)> GetWithDaysAndNpvAsync(WellOperationRequest request, CancellationToken token) { var skip = request.Skip ?? 0; var take = request.Take ?? 32; var entities = await GetByIdsWells(request.IdsWell, token); - var entitiesByWellAndType = entities - .GroupBy(e => new { e.IdWell, e.IdType }) - .Select(grp => grp.ToArray()); + var groupedByWellAndType = entities + .GroupBy(e => new { e.IdWell, e.IdType }); var result = new List(); var count = 0; - foreach (var wellOperationsWithType in entitiesByWellAndType) + foreach (var wellOperationsWithType in groupedByWellAndType) { var firstWellOperation = wellOperationsWithType .OrderBy(e => e.DateStart) @@ -201,8 +203,16 @@ public class WellOperationRepository : CrudRepositoryBase ConvertWithDrillingDaysAndNpvHours(o, firstWellOperation, operationsWithNpt)); - + .Select(entity => + { + var dto = Convert(entity); + dto.Day = (entity.DateStart - firstWellOperation.DateStart).TotalDays; + dto.NptHours = operationsWithNpt + .Where(o => o.DateStart <= entity.DateStart) + .Sum(e => e.DurationHours); + return dto; + }); + result.AddRange(dtos); count += filteredWellOperations.Count(); } @@ -336,20 +346,6 @@ public class WellOperationRepository : CrudRepositoryBase wellOperationsWithNtp) - { - var dto = Convert(entity); - dto.Day = (entity.DateStart - firstOperation.DateStart).TotalDays; - dto.NptHours = wellOperationsWithNtp - .Where(o => o.DateStart <= entity.DateStart) - .Sum(e => e.DurationHours); - - return dto; - } - protected override WellOperation Convert(WellOperationDto src) { var entity = src.Adapt(); @@ -361,13 +357,14 @@ public class WellOperationRepository : CrudRepositoryBase e.WellSectionType) - // .Include(e => e.OperationCategory) var timeZoneOffset = wellService.GetTimezone(src.IdWell).Offset; + var dto = src.Adapt(); dto.DateStart = src.DateStart.ToOffset(timeZoneOffset); dto.LastUpdateDate = src.LastUpdateDate.ToOffset(timeZoneOffset); + + dto.OperationCategoryName = LazyWellCategories.Value.TryGetValue(src.IdCategory, out WellOperationCategoryDto? category) ? category.Name : string.Empty; + dto.WellSectionTypeCaption = LazyWellSectionTypes.Value.TryGetValue(src.IdWellSectionType, out WellSectionTypeDto? sectionType) ? sectionType.Caption : string.Empty; return dto; } } \ No newline at end of file