From 50c3cca8b83847787a701bc9936fb8b3aad58320 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Tue, 12 Oct 2021 18:06:47 +0500 Subject: [PATCH] =?UTF-8?q?CS2-84=20=D0=9F=D1=80=D0=B8=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B8=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D0=BA=D1=83=D1=81=D1=82=D1=83=20=D0=BD=D0=B5?= =?UTF-8?q?=D1=82=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=B4=D0=BE=D1=81=D1=82=D1=83=D0=BF=D0=BD=D1=8B=D0=BC?= =?UTF-8?q?=20=D1=81=D0=BA=D0=B2=D0=B0=D0=B6=D0=B8=D0=BD=D0=B0=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/IWellOperationsStatService.cs | 2 +- .../WellOperationsStatService.cs | 17 ++++++++--------- .../Controllers/WellOperationStatController.cs | 7 ++++++- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/AsbCloudApp/Services/IWellOperationsStatService.cs b/AsbCloudApp/Services/IWellOperationsStatService.cs index a047f68d..dc71fb33 100644 --- a/AsbCloudApp/Services/IWellOperationsStatService.cs +++ b/AsbCloudApp/Services/IWellOperationsStatService.cs @@ -7,7 +7,7 @@ namespace AsbCloudApp.Services { public interface IWellOperationsStatService { - Task GetStatClusterAsync(int idCluster, CancellationToken token = default); + Task GetStatClusterAsync(int idCluster, int idCompany, CancellationToken token = default); Task GetStatWellAsync(int idWell, CancellationToken token = default); Task>> GetTvdAsync(int idWell, CancellationToken token); Task> GetWellsStatAsync(IEnumerable idWells, CancellationToken token); diff --git a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationsStatService.cs index 5f0e0725..f0082f32 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService/WellOperationsStatService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService/WellOperationsStatService.cs @@ -40,21 +40,20 @@ namespace AsbCloudInfrastructure.Services.WellOperationService cacheCluster = cache.GetCachedTable((DbContext)db); } - public async Task GetStatClusterAsync(int idCluster, CancellationToken token = default) + public async Task GetStatClusterAsync(int idCluster, int idCompany, CancellationToken token = default) { + var allWellsByCompany = await wellService.GetWellsByCompanyAsync(idCompany, token).ConfigureAwait(false); + + var idWellsByCompany = allWellsByCompany.Select(w=>w.Id).Distinct(); + var wells = await db.Wells .Include(w => w.WellOperations) .Where(o => o.IdCluster == idCluster) - .AsNoTracking() + .Where(w => idWellsByCompany.Contains(w.Id)) + .Select(w => w.Id) .ToListAsync(token); - var statsWells = new List(wells.Count()); - - foreach (var well in wells) - { - var statWellDto = await CalcStatWellAsync(well, token); - statsWells.Add(statWellDto); - } + var statsWells = await GetWellsStatAsync(wells, token).ConfigureAwait(false); var cluster = await cacheCluster.FirstOrDefaultAsync(c => c.Id == idCluster, token); var statClusterDto = new StatClusterDto diff --git a/AsbCloudWebApi/Controllers/WellOperationStatController.cs b/AsbCloudWebApi/Controllers/WellOperationStatController.cs index 28a97499..7d71cac3 100644 --- a/AsbCloudWebApi/Controllers/WellOperationStatController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationStatController.cs @@ -38,11 +38,16 @@ namespace AsbCloudWebApi.Controllers public async Task GetStatClusterAsync(int idCluster, CancellationToken token = default) { + int? idCompanyOrNull = User.GetCompanyId(); + if(idCompanyOrNull is null) + return Forbid(); + + int idCompany = idCompanyOrNull ?? 0; // TODO: Fix next commented lines //if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false)) // return Forbid(); - var result = await operationsStatService.GetStatClusterAsync(idCluster, token) + var result = await operationsStatService.GetStatClusterAsync(idCluster, idCompany, token) .ConfigureAwait(false); return Ok(result); }