diff --git a/AsbCloudApp/Repositories/IWellOperationRepository.cs b/AsbCloudApp/Repositories/IWellOperationRepository.cs index f8d3c8ff..5f2979a9 100644 --- a/AsbCloudApp/Repositories/IWellOperationRepository.cs +++ b/AsbCloudApp/Repositories/IWellOperationRepository.cs @@ -28,9 +28,10 @@ namespace AsbCloudApp.Repositories /// /// список плановых операций для сопоставления /// + /// /// /// - Task> GetOperationsPlan(int idWell); + Task> GetOperationsPlanAsync(int idWell, CancellationToken token); /// /// дата/время первой операции по скважине diff --git a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs index 971172ad..a2b449d5 100644 --- a/AsbCloudInfrastructure/Repository/WellOperationRepository.cs +++ b/AsbCloudInfrastructure/Repository/WellOperationRepository.cs @@ -58,34 +58,37 @@ namespace AsbCloudInfrastructure.Repository .GetOrCreateBasic(db) .ToDictionary(s => s.Id, s => s.Caption); - public async Task> GetOperationsPlan(int idWell) + public async Task> GetOperationsPlanAsync(int idWell, CancellationToken token) { var lastFactOperation = await db.WellOperations .Where(x => x.IdType == WellOperation.IdOperationTypeFact) .Where(x => x.IdPlan != null) .OrderByDescending(x => x.DateStart) - .FirstOrDefaultAsync() + .FirstOrDefaultAsync(token) .ConfigureAwait(false); - var query = await db.WellOperations + var query = db.WellOperations .Include(x => x.OperationCategory) .Where(x => x.IdWell == idWell) - .Where(x => x.IdType == WellOperation.IdOperationTypePlan) - .AsNoTracking() - .ToListAsync() - .ConfigureAwait(false); + .Where(x => x.IdType == WellOperation.IdOperationTypePlan); + if (lastFactOperation is not null) { var dateStart = lastFactOperation?.DateStart!; - query = query.Where(x => x.DateStart >= dateStart).ToList(); + query = query.Where(x => x.DateStart >= dateStart); } var timezone = wellService.GetTimezone(idWell); var timeZoneOffset = TimeSpan.FromHours(timezone.Hours); - var result = query. - Select(o => new WellOperationDto() + var entities = await query + .AsNoTracking() + .ToArrayAsync(token) + .ConfigureAwait(false); + + var result = entities + .Select(o => new WellOperationDto() { IdWell = o.IdWell, CategoryName = o.OperationCategory.Name, @@ -94,8 +97,7 @@ namespace AsbCloudInfrastructure.Repository DepthStart = o.DepthStart, DateStart = DateTime.SpecifyKind(o.DateStart.UtcDateTime + timeZoneOffset, DateTimeKind.Unspecified), Id = o.Id - }) - .ToList(); + }); return result; } diff --git a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs index 2b6699a7..3ce07394 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/OperationsStatService.cs @@ -236,7 +236,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService BhaUpSpeed = CalcBhaUpSpeed(races), CasingDownSpeed = CalcCasingDownSpeed(operations), NonProductiveHours = operations - .Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains( o.IdCategory)) + .Where(o => WellOperationCategory.NonProductiveTimeSubIds.Contains(o.IdCategory)) .Sum(o => o.DurationHours), }; return section; @@ -330,7 +330,7 @@ namespace AsbCloudInfrastructure.Services.WellOperationService { if (race.Operations[i].IdCategory == WellOperationCategory.IdBhaDown) dHours += race.Operations[i].DurationHours; - if (WellOperationCategory.MechanicalDrillingSubIds.Contains( race.Operations[i].IdCategory)) + if (WellOperationCategory.MechanicalDrillingSubIds.Contains(race.Operations[i].IdCategory)) break; } } @@ -492,7 +492,10 @@ namespace AsbCloudInfrastructure.Services.WellOperationService result.AddRange(oparationsFactWithPlan); result.AddRange(oparationsPlanWithNoFact); - result = result.OrderBy(x => x.Item1?.DateStart).ToList(); + result = result + .OrderBy(x => x.Item1?.DateStart) + .ThenBy(x => x.Item2?.DateStart) + .ToList(); return result; } diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 678fbca4..e8e5d2d6 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -64,15 +64,18 @@ namespace AsbCloudWebApi.Controllers /// Возвращает список плановых операций для сопоставления /// /// id скважины + /// /// [HttpGet] [Route("operationsPlan")] - [Permission] - [ProducesResponseType(typeof(List), (int)System.Net.HttpStatusCode.OK)] - public async Task GetOperationsPlan([FromRoute] int idWell) + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetOperationsPlanAsync([FromRoute] int idWell, CancellationToken token) { + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) + return Forbid(); + var result = await operationRepository - .GetOperationsPlan(idWell) + .GetOperationsPlanAsync(idWell, token) .ConfigureAwait(false); return Ok(result); } @@ -167,8 +170,8 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - foreach(var value in values) - value.IdWell= idWell; + foreach (var value in values) + value.IdWell = idWell; var result = await operationRepository.InsertRangeAsync(values, token) .ConfigureAwait(false); @@ -193,7 +196,7 @@ namespace AsbCloudWebApi.Controllers if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); - value.IdWell= idWell; + value.IdWell = idWell; value.Id = idOperation; var result = await operationRepository.UpdateAsync(value, token)