diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index dacd8f4f..66952f21 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -9,6 +9,8 @@ namespace AsbCloudApp.Services { Task> GetDepositsAsync(int idCompany, CancellationToken token); + Task> GetDepositsDrillParamsAsync(int idCompany, + CancellationToken token = default); Task> GetClustersAsync(int idCompany, int depositId, CancellationToken token); Task> GetClustersAsync(int idCompany, diff --git a/AsbCloudInfrastructure/Services/ClusterService.cs b/AsbCloudInfrastructure/Services/ClusterService.cs index e04e8ea9..88e8515e 100644 --- a/AsbCloudInfrastructure/Services/ClusterService.cs +++ b/AsbCloudInfrastructure/Services/ClusterService.cs @@ -31,36 +31,30 @@ namespace AsbCloudInfrastructure.Services select well).ToListAsync(token) .ConfigureAwait(false); - var gDepositEntities = wellEntities - .GroupBy(w => w.Cluster) - .GroupBy(c => c.Key.Deposit); + var gDepositEntities = groupWells(wellEntities); - var dtos = gDepositEntities.Select(gDeposit => new DepositDto - { - Id = gDeposit.Key.Id, - Caption = gDeposit.Key.Caption, - Latitude = gDeposit.Key.Latitude, - Longitude = gDeposit.Key.Longitude, - Description = "", - Clusters = gDeposit.Select(gCluster => new ClusterDto - { - Id = gCluster.Key.Id, - Caption = gCluster.Key.Caption, - Latitude = gCluster.Key.Latitude, - Longitude = gCluster.Key.Longitude, - Description = "", - Wells = gCluster.Select(well => new WellDto - { - Id = well.Id, - Caption = well.Caption, - Latitude = well.Latitude, - Longitude = well.Longitude, - WellType = well.WellType?.Caption, - Cluster = gCluster.Key.Caption, - Deposit = gDeposit.Key.Caption, - }), - }), - }); + var dtos = CreateDepositDto(gDepositEntities); + + return dtos; + } + + public async Task> GetDepositsDrillParamsAsync(int idCompany, + CancellationToken token = default) + { + var wellEntities = await (from well in db.Wells + .Include(w => w.RelationCompaniesWells) + .Include(w => w.WellType) + .Include(w => w.Cluster) + .ThenInclude(c => c.Deposit) + from p in db.DrillParams + where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) && + well.Id == p.IdWell + select well).ToListAsync(token) + .ConfigureAwait(false); + + var gDepositEntities = groupWells(wellEntities); + + var dtos = CreateDepositDto(gDepositEntities); return dtos; } @@ -117,5 +111,42 @@ namespace AsbCloudInfrastructure.Services return dtos; } + + private IEnumerable>> groupWells(IEnumerable wellEntities) + { + return wellEntities + .GroupBy(w => w.Cluster) + .GroupBy(c => c.Key.Deposit); + } + + private IEnumerable CreateDepositDto(IEnumerable>>gDepositEntities) + { + return gDepositEntities.Select(gDeposit => new DepositDto + { + Id = gDeposit.Key.Id, + Caption = gDeposit.Key.Caption, + Latitude = gDeposit.Key.Latitude, + Longitude = gDeposit.Key.Longitude, + Description = "", + Clusters = gDeposit.Select(gCluster => new ClusterDto + { + Id = gCluster.Key.Id, + Caption = gCluster.Key.Caption, + Latitude = gCluster.Key.Latitude, + Longitude = gCluster.Key.Longitude, + Description = "", + Wells = gCluster.Select(well => new WellDto + { + Id = well.Id, + Caption = well.Caption, + Latitude = well.Latitude, + Longitude = well.Longitude, + WellType = well.WellType?.Caption, + Cluster = gCluster.Key.Caption, + Deposit = gDeposit.Key.Caption, + }), + }), + }); + } } } diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index 4fadce32..6bfac7f9 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -41,6 +41,25 @@ namespace AsbCloudWebApi.Controllers token).ConfigureAwait(false); return Ok(result); } + + /// + /// Получает список доступных пользователю месторождений (только скважины с параметрами бурения) + /// + /// Токен отмены задачи + /// + [HttpGet("drillParamsWells")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public async Task GetDepositsDrillParamsAsync(CancellationToken token = default) + { + int? idCompany = User.GetCompanyId(); + + if (idCompany is null) + return Forbid(); + + var result = await clusterService.GetDepositsDrillParamsAsync((int)idCompany, + token).ConfigureAwait(false); + return Ok(result); + } /// /// Получает список доступных пользователю кустов месторождения