From 9c5c1fc9c5ba350f9eb16d73e3b78cddca3eca9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Wed, 21 Jul 2021 17:23:57 +0500 Subject: [PATCH] fix WellService controller --- AsbCloudApp/Data/ClusterDto.cs | 2 +- AsbCloudApp/Data/ClusterStatDto.cs | 13 ++++++++++ ...{WellDrillingStatDto.cs => WellStatDto.cs} | 2 +- AsbCloudApp/Services/IClusterService.cs | 2 +- .../Services/WellService.cs | 11 ++++---- .../Services/СlusterService.cs | 26 ++++++++++++++----- .../Controllers/ClusterController.cs | 2 +- .../Controllers/DepositController.cs | 2 +- 8 files changed, 42 insertions(+), 18 deletions(-) create mode 100644 AsbCloudApp/Data/ClusterStatDto.cs rename AsbCloudApp/Data/{WellDrillingStatDto.cs => WellStatDto.cs} (93%) diff --git a/AsbCloudApp/Data/ClusterDto.cs b/AsbCloudApp/Data/ClusterDto.cs index 3e757ea8..10d92106 100644 --- a/AsbCloudApp/Data/ClusterDto.cs +++ b/AsbCloudApp/Data/ClusterDto.cs @@ -3,7 +3,7 @@ public class ClusterDto : IMapPoint { public int Id { get; set; } - public string Name { get; set; } + public string Caption { get; set; } public string Description { get; set; } public double? Latitude { get; set; } public double? Longitude { get; set; } diff --git a/AsbCloudApp/Data/ClusterStatDto.cs b/AsbCloudApp/Data/ClusterStatDto.cs new file mode 100644 index 00000000..32731cf1 --- /dev/null +++ b/AsbCloudApp/Data/ClusterStatDto.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudApp.Data +{ + public class ClusterStatDto: ClusterDto + { + public IEnumerable WellsStat { get; set; } + } +} diff --git a/AsbCloudApp/Data/WellDrillingStatDto.cs b/AsbCloudApp/Data/WellStatDto.cs similarity index 93% rename from AsbCloudApp/Data/WellDrillingStatDto.cs rename to AsbCloudApp/Data/WellStatDto.cs index e38cb10e..ed6e74e5 100644 --- a/AsbCloudApp/Data/WellDrillingStatDto.cs +++ b/AsbCloudApp/Data/WellStatDto.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; namespace AsbCloudApp.Data { - public class WellDrillingStatDto : WellDto + public class WellStatDto : WellDto { public DateTime? PlanStart { get; set; } public DateTime? PlanEnd { get; set; } diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index 8c7ce9ad..7b121401 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -9,6 +9,6 @@ namespace AsbCloudApp.Services IEnumerable GetClusters(int idCompany, int depositId); IEnumerable GetClusters(int idCompany); IEnumerable GetWells(int idCompany, int clusterId); - IEnumerable GetStat(int idCompany, int clusterId); + ClusterStatDto GetStat(int idCompany, int clusterId); } } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 2192bbb6..1fd70b44 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -12,13 +12,13 @@ namespace AsbCloudInfrastructure.Services { private readonly IAsbCloudDbContext db; private readonly ITelemetryTracker telemetryTracker; - private readonly CacheTable cacheWells; + private readonly CacheTable cacheRelationCompaniesWells; public WellService(IAsbCloudDbContext db, ITelemetryTracker telemetryTracker, CacheDb cacheDb) { this.db = db; this.telemetryTracker = telemetryTracker; - cacheWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); + cacheRelationCompaniesWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } public IEnumerable GetTransmittingWells(int idCompany) @@ -40,10 +40,9 @@ namespace AsbCloudInfrastructure.Services return wells.Select(w => From(w)); } - public bool CheckWellOwnership(int idCompany, int wellId) - => cacheWells.Contains(w => w.Id == wellId && w.RelationCompaniesWells.Any(r => r.IdCompany == idCompany)); - - + public bool CheckWellOwnership(int idCompany, int idWell) + => cacheRelationCompaniesWells.Contains(r => r.IdWell == idWell && r.IdCompany == idCompany); + private static WellDto From(Well well) { var wellDto = new WellDto diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs index 20e7e230..81a5f498 100644 --- a/AsbCloudInfrastructure/Services/СlusterService.cs +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -44,7 +44,7 @@ namespace AsbCloudInfrastructure.Services var dtos = entities.Select(e => new ClusterDto { Id = e.Id, - Name = e.Caption, + Caption = e.Caption, Latitude = e.Latitude, Longitude = e.Longitude, }); @@ -63,7 +63,7 @@ namespace AsbCloudInfrastructure.Services var dtos = entities.Select(e => new ClusterDto { Id = e.Id, - Name = e.Caption, + Caption = e.Caption, Latitude = e.Latitude, Longitude = e.Longitude, }); @@ -90,13 +90,13 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetStat(int idCompany, int idCluster) + public ClusterStatDto GetStat(int idCompany, int idCluster) { - var entities = from w in db.Wells + var wellEntities = from w in db.Wells where w.IdCluster == idCluster && w.RelationCompaniesWells.Any(c => c.IdCompany == idCompany) select w; - var dtos = entities.Select(e => new WellDrillingStatDto + var wellStatDtos = wellEntities.Select(e => new WellStatDto { Id = e.Id, Caption = e.Caption, @@ -139,9 +139,21 @@ namespace AsbCloudInfrastructure.Services CompanyType = c.Company.CompanyType.Caption, }), WellType = e.WellType.Caption, - }); + }).ToList(); - return dtos; + if (!wellStatDtos.Any()) + return null; + + var clusterById = db.Clusters.FirstOrDefault(c => c.Id == idCluster); + + return new ClusterStatDto { + Id = clusterById.Id, + Description = "", + Caption = clusterById.Caption, + Latitude = clusterById.Latitude, + Longitude = clusterById.Longitude, + WellsStat = wellStatDtos, + }; } } } diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index ea6ec473..09c5a5d6 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -62,7 +62,7 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet("{idCluster}/Stat")] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetStat(int idCluster) { int? idCompany = User.GetCompanyId(); diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index af26dab9..e38366e8 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -14,7 +14,7 @@ namespace AsbCloudWebApi.Controllers [Authorize] public class DepositController : ControllerBase { - IClusterService clusterService; + private readonly IClusterService clusterService; public DepositController(IClusterService clusterService) {