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); + } + + } +}