From f30cafcb1e31457a49ddd8f40adcceefc1a6db49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 19 Jul 2021 15:11:01 +0500 Subject: [PATCH] =?UTF-8?q?CS2-30=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BA=D0=BE=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5?= =?UTF-8?q?=D1=80=20=D0=BA=D1=83=D1=81=D1=82=D0=B0=20=D0=B8=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BD=D1=82=D1=80=D0=BE=D0=BB=D0=BB=D0=B5=D1=80=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D0=BE=D1=80=D0=BE=D0=B6=D0=B4=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Data/ClusterAnalysisDto.cs | 7 ++ AsbCloudApp/Data/ClusterDto.cs | 19 +++++ AsbCloudApp/Data/DepositDto.cs | 13 +++ AsbCloudApp/Data/IMapPoint.cs | 15 ++++ AsbCloudApp/Data/WellDto.cs | 5 +- AsbCloudApp/Services/IClusterService.cs | 17 ++++ AsbCloudDb/Model/Cluster.cs | 11 ++- AsbCloudDb/Model/Deposit.cs | 9 +- AsbCloudDb/Model/IMapPoint.cs | 15 ++++ AsbCloudDb/Model/Well.cs | 8 +- .../Services/СlusterService.cs | 84 +++++++++++++++++++ .../Controllers/ClusterController.cs | 64 ++++++++++++++ .../Controllers/DepositController.cs | 64 ++++++++++++++ 13 files changed, 327 insertions(+), 4 deletions(-) create mode 100644 AsbCloudApp/Data/ClusterAnalysisDto.cs create mode 100644 AsbCloudApp/Data/ClusterDto.cs create mode 100644 AsbCloudApp/Data/DepositDto.cs create mode 100644 AsbCloudApp/Data/IMapPoint.cs create mode 100644 AsbCloudApp/Services/IClusterService.cs create mode 100644 AsbCloudDb/Model/IMapPoint.cs create mode 100644 AsbCloudInfrastructure/Services/СlusterService.cs create mode 100644 AsbCloudWebApi/Controllers/ClusterController.cs create mode 100644 AsbCloudWebApi/Controllers/DepositController.cs diff --git a/AsbCloudApp/Data/ClusterAnalysisDto.cs b/AsbCloudApp/Data/ClusterAnalysisDto.cs new file mode 100644 index 00000000..082bb59c --- /dev/null +++ b/AsbCloudApp/Data/ClusterAnalysisDto.cs @@ -0,0 +1,7 @@ +namespace AsbCloudApp.Data +{ + public class ClusterAnalysisDto + { + public int Id { get; set; } + } +} diff --git a/AsbCloudApp/Data/ClusterDto.cs b/AsbCloudApp/Data/ClusterDto.cs new file mode 100644 index 00000000..492821e5 --- /dev/null +++ b/AsbCloudApp/Data/ClusterDto.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudApp.Data +{ + public class ClusterDto: IMapPoint + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } + + //public IEnumerable Wells { get; set; } + } +} diff --git a/AsbCloudApp/Data/DepositDto.cs b/AsbCloudApp/Data/DepositDto.cs new file mode 100644 index 00000000..bbd62657 --- /dev/null +++ b/AsbCloudApp/Data/DepositDto.cs @@ -0,0 +1,13 @@ +namespace AsbCloudApp.Data +{ + public class DepositDto: IMapPoint + { + public int Id { get; set; } + public string Name { get; set; } + public string Description { get; set; } + public double Latitude { get; set; } + public double Longitude { get; set; } + + //public IEnumerable Clusters { get; set; } + } +} diff --git a/AsbCloudApp/Data/IMapPoint.cs b/AsbCloudApp/Data/IMapPoint.cs new file mode 100644 index 00000000..6ed1b0d8 --- /dev/null +++ b/AsbCloudApp/Data/IMapPoint.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudApp.Data +{ + public interface IMapPoint + { + double Latitude { get; set; } + + double Longitude { get; set; } + } +} diff --git a/AsbCloudApp/Data/WellDto.cs b/AsbCloudApp/Data/WellDto.cs index 47f63ec6..11fd4a6a 100644 --- a/AsbCloudApp/Data/WellDto.cs +++ b/AsbCloudApp/Data/WellDto.cs @@ -1,8 +1,11 @@ namespace AsbCloudApp.Data { - public class WellDto : WellInfoDto + + public class WellDto : WellInfoDto, IMapPoint { public int Id { get; set; } public object LastData { get; set; }//DataSaubBaseDto + public double Latitude { get; set; } + public double Longitude { get; set; } } } diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs new file mode 100644 index 00000000..8fa0bd11 --- /dev/null +++ b/AsbCloudApp/Services/IClusterService.cs @@ -0,0 +1,17 @@ +using AsbCloudApp.Data; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudApp.Services +{ + public interface IClusterService + { + IEnumerable GetDeposits(int idCustomer); + IEnumerable GetClusters(int idCustomer, int depositId); + IEnumerable GetWells(int idCustomer, int clusterId); + IEnumerable GetAnalysis(int idCustomer, int clusterId); + } +} diff --git a/AsbCloudDb/Model/Cluster.cs b/AsbCloudDb/Model/Cluster.cs index 0723dc39..db6017db 100644 --- a/AsbCloudDb/Model/Cluster.cs +++ b/AsbCloudDb/Model/Cluster.cs @@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model { [Table("t_cluster"), Comment("Кусты")] - public partial class Cluster : IId + public partial class Cluster : IId, IMapPoint { public Cluster() { @@ -18,16 +18,25 @@ namespace AsbCloudDb.Model [Key] [Column("id")] public int Id { get; set; } + [Column("caption"), Comment("Название")] [StringLength(255)] public string Caption { get; set; } + [Column("id_deposit")] public int? IdDeposit { get; set; } [ForeignKey(nameof(IdDeposit))] [InverseProperty(nameof(Model.Deposit.Clusters))] public virtual Deposit Deposit { get; set; } + [InverseProperty(nameof(Well.Cluster))] public virtual ICollection Wells { get; set; } + + [Column("latitude")] + public double Latitude { get; set; } + + [Column("longitude")] + public double Longitude { get; set; } } } diff --git a/AsbCloudDb/Model/Deposit.cs b/AsbCloudDb/Model/Deposit.cs index 61e159e8..385ee1f4 100644 --- a/AsbCloudDb/Model/Deposit.cs +++ b/AsbCloudDb/Model/Deposit.cs @@ -8,7 +8,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model { [Table("t_deposit"), Comment("Месторождение")] - public partial class Deposit : IId + public partial class Deposit : IId, IMapPoint { public Deposit() { @@ -18,11 +18,18 @@ namespace AsbCloudDb.Model [Key] [Column("id")] public int Id { get; set; } + [Column("caption")] [StringLength(255)] public string Caption { get; set; } [InverseProperty(nameof(Cluster.Deposit))] public virtual ICollection Clusters { get; set; } + + [Column("latitude")] + public double Latitude { get; set; } + + [Column("longitude")] + public double Longitude { get; set; } } } diff --git a/AsbCloudDb/Model/IMapPoint.cs b/AsbCloudDb/Model/IMapPoint.cs new file mode 100644 index 00000000..e1df799d --- /dev/null +++ b/AsbCloudDb/Model/IMapPoint.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudDb.Model +{ + public interface IMapPoint + { + double Latitude { get; set; } + + double Longitude { get; set; } + } +} diff --git a/AsbCloudDb/Model/Well.cs b/AsbCloudDb/Model/Well.cs index 8d30880a..394eba4f 100644 --- a/AsbCloudDb/Model/Well.cs +++ b/AsbCloudDb/Model/Well.cs @@ -7,7 +7,7 @@ using System.ComponentModel.DataAnnotations.Schema; namespace AsbCloudDb.Model { [Table("t_well"), Comment("скважины")] - public partial class Well : IId + public partial class Well : IId, IMapPoint { [Key] [Column("id")] @@ -37,5 +37,11 @@ namespace AsbCloudDb.Model [ForeignKey(nameof(IdTelemetry))] [InverseProperty(nameof(Model.Telemetry.Well))] public virtual Telemetry Telemetry { get; set; } + + [Column("latitude")] + public double Latitude { get; set; } + + [Column("longitude")] + public double Longitude { get; set; } } } diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs new file mode 100644 index 00000000..ff8883d9 --- /dev/null +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -0,0 +1,84 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.Cache; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services +{ + public class СlusterService : IClusterService + { + private readonly IAsbCloudDbContext db; + + public СlusterService(IAsbCloudDbContext db) + { + this.db = db; + } + + public IEnumerable GetDeposits(int idCustomer) + { + var entities = db.GetWellsByCustomer(idCustomer) + .Select(e=>e.Cluster.Deposit) + .Distinct() + .ToList(); + + var dtos = entities.Select(e => new DepositDto + { + Id = e.Id, + Name = e.Caption, + Latitude = e.Latitude, + Longitude = e.Longitude, + }); + + return dtos; + } + + public IEnumerable GetClusters(int idCustomer, int depositId) + { + var entities = db.GetWellsByCustomer(idCustomer) + .Select(e => e.Cluster) + .Where(e=>e.IdDeposit == depositId) + .Distinct() + .ToList(); + + var dtos = entities.Select(e => new ClusterDto + { + Id = e.Id, + Name = e.Caption, + Latitude = e.Latitude, + Longitude = e.Longitude, + }); + + return dtos; + } + + public IEnumerable GetWells(int idCustomer, int clusterId) + { + var entities = db.GetWellsByCustomer(idCustomer) + .Where(e => e.IdCluster == clusterId) + .ToList(); + + var dtos = entities.Select(e => new WellDto + { + Id = e.Id, + Caption = e.Caption, + Latitude = e.Latitude, + Longitude = e.Longitude, + Cluster = e.Cluster.Caption, + Deposit = e.Cluster.Deposit.Caption, + }); + + return dtos; + } + + public IEnumerable GetAnalysis(int idCustomer, int clusterId) + { + throw new NotImplementedException(); + } + } +} diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs new file mode 100644 index 00000000..cbca7f05 --- /dev/null +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -0,0 +1,64 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace AsbCloudWebApi.Controllers +{ + /// + /// Контроллер кустов + /// + [Route("api/[controller]")] + [ApiController] + [Authorize] + public class ClusterController : ControllerBase + { + private readonly IClusterService clusterService; + + public ClusterController(IClusterService clusterService) + { + this.clusterService = clusterService; + } + + /// + /// Получение доступных пользователю скважин + /// + /// + /// + [HttpGet("{clusterId}")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetWells(int clusterId) + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null) + return Forbid(); + + var result = clusterService.GetWells((int)idCustomer, clusterId); + return Ok(result); + } + + /// + /// Получение обопщенной аналитики по кусту (лучшая/худшая скважина) + /// + /// + /// + [HttpGet("{clusterId}")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetAnalysis(int clusterId) + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null) + return Forbid(); + + var result = clusterService.GetAnalysis((int)idCustomer, clusterId); + return Ok(result); + } + } +} diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs new file mode 100644 index 00000000..5fc94160 --- /dev/null +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -0,0 +1,64 @@ +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace AsbCloudWebApi.Controllers +{ + /// + /// Контроллер для месторождений + /// + [Route("api/[controller]")] + [ApiController] + [Authorize] + public class DepositController : ControllerBase + { + IClusterService clusterService; + + public DepositController(IClusterService clusterService) + { + this.clusterService = clusterService; + } + + /// + /// Получает список доступных пользователю месторождений + /// + /// + [HttpGet] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetDeposits() + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null) + return Forbid(); + + var result = clusterService.GetDeposits((int)idCustomer); + return Ok(result); + } + + /// + /// Получает список доступных пользователю кустов месторождения + /// + /// + /// + [HttpGet("{depositId}")] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + public IActionResult GetClusters(int depositId) + { + int? idCustomer = User.GetCustomerId(); + + if (idCustomer is null) + return Forbid(); + + var result = clusterService.GetClusters((int)idCustomer, depositId); + return Ok(result); + } + + } +}