CS2-84 При формировании статистики по кусту нет фильтра по доступным скважинам

This commit is contained in:
Фролов 2021-10-12 18:06:47 +05:00
parent b800759a09
commit 50c3cca8b8
3 changed files with 15 additions and 11 deletions

View File

@ -7,7 +7,7 @@ namespace AsbCloudApp.Services
{ {
public interface IWellOperationsStatService public interface IWellOperationsStatService
{ {
Task<StatClusterDto> GetStatClusterAsync(int idCluster, CancellationToken token = default); Task<StatClusterDto> GetStatClusterAsync(int idCluster, int idCompany, CancellationToken token = default);
Task<StatWellDto> GetStatWellAsync(int idWell, CancellationToken token = default); Task<StatWellDto> GetStatWellAsync(int idWell, CancellationToken token = default);
Task<IEnumerable<PlanFactPredictBase<WellOperationDto>>> GetTvdAsync(int idWell, CancellationToken token); Task<IEnumerable<PlanFactPredictBase<WellOperationDto>>> GetTvdAsync(int idWell, CancellationToken token);
Task<IEnumerable<StatWellDto>> GetWellsStatAsync(IEnumerable<int> idWells, CancellationToken token); Task<IEnumerable<StatWellDto>> GetWellsStatAsync(IEnumerable<int> idWells, CancellationToken token);

View File

@ -40,21 +40,20 @@ namespace AsbCloudInfrastructure.Services.WellOperationService
cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db); cacheCluster = cache.GetCachedTable<Cluster>((DbContext)db);
} }
public async Task<StatClusterDto> GetStatClusterAsync(int idCluster, CancellationToken token = default) public async Task<StatClusterDto> 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 var wells = await db.Wells
.Include(w => w.WellOperations) .Include(w => w.WellOperations)
.Where(o => o.IdCluster == idCluster) .Where(o => o.IdCluster == idCluster)
.AsNoTracking() .Where(w => idWellsByCompany.Contains(w.Id))
.Select(w => w.Id)
.ToListAsync(token); .ToListAsync(token);
var statsWells = new List<StatWellDto>(wells.Count()); var statsWells = await GetWellsStatAsync(wells, token).ConfigureAwait(false);
foreach (var well in wells)
{
var statWellDto = await CalcStatWellAsync(well, token);
statsWells.Add(statWellDto);
}
var cluster = await cacheCluster.FirstOrDefaultAsync(c => c.Id == idCluster, token); var cluster = await cacheCluster.FirstOrDefaultAsync(c => c.Id == idCluster, token);
var statClusterDto = new StatClusterDto var statClusterDto = new StatClusterDto

View File

@ -38,11 +38,16 @@ namespace AsbCloudWebApi.Controllers
public async Task<IActionResult> GetStatClusterAsync(int idCluster, public async Task<IActionResult> GetStatClusterAsync(int idCluster,
CancellationToken token = default) CancellationToken token = default)
{ {
int? idCompanyOrNull = User.GetCompanyId();
if(idCompanyOrNull is null)
return Forbid();
int idCompany = idCompanyOrNull ?? 0;
// TODO: Fix next commented lines // TODO: Fix next commented lines
//if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false)) //if (!await CanUserAccessToWellAsync(idCluster, token).ConfigureAwait(false))
// return Forbid(); // return Forbid();
var result = await operationsStatService.GetStatClusterAsync(idCluster, token) var result = await operationsStatService.GetStatClusterAsync(idCluster, idCompany, token)
.ConfigureAwait(false); .ConfigureAwait(false);
return Ok(result); return Ok(result);
} }