From 28a12953328b82cab50d880350560bcee2c5123d 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 12:30:51 +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.=20=D0=A0=D0=B0=D0=B7=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=D0=BD=D0=B0=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8C=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Data/Analytics/WellDrillingStatDto.cs | 22 ++++++ AsbCloudApp/Data/Analytics/WellSectionDto.cs | 21 +++++ AsbCloudApp/Data/ClusterAnalysisDto.cs | 7 -- AsbCloudApp/Data/ContractorDto.cs | 9 +++ AsbCloudApp/Data/UserDto.cs | 2 +- AsbCloudApp/Data/WellDto.cs | 2 + AsbCloudApp/Services/IClusterService.cs | 3 +- AsbCloudDb/Model/Analytics/SectionType.cs | 15 ++++ .../Model/Analytics/WellDrillingStat.cs | 55 ++++++++++++++ AsbCloudDb/Model/Analytics/WellSection.cs | 76 +++++++++++++++++++ AsbCloudDb/Model/Analytics/WellSectionType.cs | 27 +++++++ AsbCloudDb/Model/AsbCloudDbContext.cs | 63 ++++++++------- AsbCloudDb/Model/Company.cs | 41 ++++++++++ AsbCloudDb/Model/CompanyType.cs | 24 ++++++ AsbCloudDb/Model/Customer.cs | 31 -------- AsbCloudDb/Model/IAsbCloudDbContext.cs | 4 +- AsbCloudDb/Model/Report.cs | 11 ++- AsbCloudDb/Model/User.cs | 10 +-- AsbCloudDb/Model/Well.cs | 20 +++-- .../ReportDataSourcePgCloud.cs | 4 +- .../Services/AuthService.cs | 10 +-- .../Services/ReportService.cs | 6 +- .../Services/WellService.cs | 12 +-- .../Services/СlusterService.cs | 20 ++--- .../Controllers/ClusterController.cs | 6 +- AsbCloudWebApi/Extensions.cs | 2 +- DataTable/Program.cs | 56 +++++++------- 27 files changed, 421 insertions(+), 138 deletions(-) create mode 100644 AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs create mode 100644 AsbCloudApp/Data/Analytics/WellSectionDto.cs delete mode 100644 AsbCloudApp/Data/ClusterAnalysisDto.cs create mode 100644 AsbCloudApp/Data/ContractorDto.cs create mode 100644 AsbCloudDb/Model/Analytics/SectionType.cs create mode 100644 AsbCloudDb/Model/Analytics/WellDrillingStat.cs create mode 100644 AsbCloudDb/Model/Analytics/WellSection.cs create mode 100644 AsbCloudDb/Model/Analytics/WellSectionType.cs create mode 100644 AsbCloudDb/Model/Company.cs create mode 100644 AsbCloudDb/Model/CompanyType.cs delete mode 100644 AsbCloudDb/Model/Customer.cs diff --git a/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs b/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs new file mode 100644 index 00000000..b31e326b --- /dev/null +++ b/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; + +namespace AsbCloudApp.Data.Analytics +{ + public class WellDrillingStatDto + { + public int Id { get; set; } + public WellDto Well { get; set; } + public DateTime PlanStart { get; set; } + public DateTime PlanEnd { get; set; } + public DateTime FactStart { get; set; } + public DateTime FactEnd { get; set; } + public double UnProductiveTimeDays { get; set; } + public double RateOfPenetrationPlan { get; set; } + public double RateOfPenetrationFact { get; set; } + public double RouteSpeedPlan { get; set; } + public double RouteSpeedFact { get; set; } + public IEnumerable Sections { get; set; } + public IEnumerable Contractors { get; set; } + } +} diff --git a/AsbCloudApp/Data/Analytics/WellSectionDto.cs b/AsbCloudApp/Data/Analytics/WellSectionDto.cs new file mode 100644 index 00000000..8b648d0c --- /dev/null +++ b/AsbCloudApp/Data/Analytics/WellSectionDto.cs @@ -0,0 +1,21 @@ +namespace AsbCloudApp.Data.Analytics +{ + public class WellSectionDto + { + public string SectionType { get; set; } + public double WellDepthPlan { get; set; } + public double WellDepthFact { get; set; } + public double BuildDaysPlan { get; set; } + public double BuildDaysFact { get; set; } + public double RateOfPenetrationPlan { get; set; } + public double RateOfPenetrationFact { get; set; } + public double RouteSpeedPlan { get; set; } + public double RouteSpeedFact { get; set; } + public double BhaUpSpeedPlan { get; set; } + public double BhaUpSpeedFact { get; set; } + public double BhaDownSpeedPlan { get; set; } + public double BhaDownSpeedFact { get; set; } + public double CasingDownSpeedPlan { get; set; } + public double CasingDownSpeedFact { get; set; } + } +} diff --git a/AsbCloudApp/Data/ClusterAnalysisDto.cs b/AsbCloudApp/Data/ClusterAnalysisDto.cs deleted file mode 100644 index 082bb59c..00000000 --- a/AsbCloudApp/Data/ClusterAnalysisDto.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace AsbCloudApp.Data -{ - public class ClusterAnalysisDto - { - public int Id { get; set; } - } -} diff --git a/AsbCloudApp/Data/ContractorDto.cs b/AsbCloudApp/Data/ContractorDto.cs new file mode 100644 index 00000000..bb2f31a0 --- /dev/null +++ b/AsbCloudApp/Data/ContractorDto.cs @@ -0,0 +1,9 @@ +namespace AsbCloudApp.Data +{ + public class ContractorDto + { + public int Id { get; set; } + public string Name { get; set; } + public string Service { get; set; } + } +} diff --git a/AsbCloudApp/Data/UserDto.cs b/AsbCloudApp/Data/UserDto.cs index a2603315..dd9234c6 100644 --- a/AsbCloudApp/Data/UserDto.cs +++ b/AsbCloudApp/Data/UserDto.cs @@ -4,7 +4,7 @@ { public int Id { get; set; } - public int? IdCustomer { get; set; } + public int? IdCompany { get; set; } public int? IdRole { get; set; } diff --git a/AsbCloudApp/Data/WellDto.cs b/AsbCloudApp/Data/WellDto.cs index 11fd4a6a..f96db114 100644 --- a/AsbCloudApp/Data/WellDto.cs +++ b/AsbCloudApp/Data/WellDto.cs @@ -7,5 +7,7 @@ public object LastData { get; set; }//DataSaubBaseDto public double Latitude { get; set; } public double Longitude { get; set; } + + public int WellType { get; set; } } } diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index 50b51288..4b238dbd 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -1,4 +1,5 @@ using AsbCloudApp.Data; +using AsbCloudApp.Data.Analytics; using System; using System.Collections.Generic; using System.Linq; @@ -13,6 +14,6 @@ namespace AsbCloudApp.Services IEnumerable GetClusters(int idCustomer, int depositId); IEnumerable GetClusters(int idCustomer); IEnumerable GetWells(int idCustomer, int clusterId); - IEnumerable GetAnalysis(int idCustomer, int clusterId); + IEnumerable GetStat(int idCustomer, int clusterId); } } diff --git a/AsbCloudDb/Model/Analytics/SectionType.cs b/AsbCloudDb/Model/Analytics/SectionType.cs new file mode 100644 index 00000000..46009f0a --- /dev/null +++ b/AsbCloudDb/Model/Analytics/SectionType.cs @@ -0,0 +1,15 @@ +namespace AsbCloudDb.Model.Analytics +{ + public enum SectionType + { + MeanSeaLevel, + MudLine, + ConductorCasing, + SurfaceCasing, + InjectionCasing, + IntermediateCasing, + ProtectiveCasing, + ProductionCasing, + ProductionLiner, + } +} diff --git a/AsbCloudDb/Model/Analytics/WellDrillingStat.cs b/AsbCloudDb/Model/Analytics/WellDrillingStat.cs new file mode 100644 index 00000000..cf8143d3 --- /dev/null +++ b/AsbCloudDb/Model/Analytics/WellDrillingStat.cs @@ -0,0 +1,55 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.Text.Json.Serialization; +using System.Collections.Generic; + +#nullable disable + +namespace AsbCloudDb.Model.Analytics +{ + + [Table("t_well_drilling_stat"), Comment("статистика бурения скважины")] + public class WellDrillingStat + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("id_well")] + public int IdWell { get; set; } + + [JsonIgnore] + [ForeignKey(nameof(IdWell))] + [InverseProperty(nameof(Model.Well.WellDrillingStat))] + public virtual Well Well { get; set; } + + [Column("plan_start", TypeName = "timestamp with time zone")] + public DateTime PlanStart { get; set; } + + [Column("plan_end", TypeName = "timestamp with time zone")] + public DateTime PlanEnd { get; set; } + + [Column("fact_start", TypeName = "timestamp with time zone")] + public DateTime FactStart { get; set; } + + [Column("fact_end", TypeName = "timestamp with time zone")] + public DateTime FactEnd { get; set; } + + [Column("un_productive_time_days"), Comment("НПВ, сут")] + public double UnProductiveDays { get; set; } + + [Column("rate_of_penetration_plan"), Comment("МСП план")] + public double RateOfPenetrationPlan { get; set; } + + [Column("rate_of_penetration_fact"), Comment("МСП факт")] + public double RateOfPenetrationFact { get; set; } + + [Column("route_speed_plan"), Comment("Рейсовая скорость план")] + public double RouteSpeedPlan { get; set; } + + [Column("route_speed_fact"), Comment("Рейсовая скорость факт")] + public double RouteSpeedFact { get; set; } + } +} diff --git a/AsbCloudDb/Model/Analytics/WellSection.cs b/AsbCloudDb/Model/Analytics/WellSection.cs new file mode 100644 index 00000000..91522be0 --- /dev/null +++ b/AsbCloudDb/Model/Analytics/WellSection.cs @@ -0,0 +1,76 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.Text.Json.Serialization; +#nullable disable + +namespace AsbCloudDb.Model.Analytics +{ + + [Table("t_well_section"), Comment("секция скважины")] + public class WellSection + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("id_well_section_type")] + public int IdWellSectionType { get; set; } + + [Column("id_well")] + public int IdWell{ get; set; } + + [Column("well_depth_plan"), Comment("глубина план")] + public double WellDepthPlan { get; set; } + + [Column("well_depth_fact"), Comment("глубина факт")] + public double WellDepthFact { get; set; } + + [Column("build_days_plan"), Comment("период план")] + public double BuildDaysPlan { get; set; } + + [Column("build_days_fact"), Comment("период факт")] + public double BuildDaysFact { get; set; } + + [Column("rate_of_penetration_plan"), Comment("Механическая скорость проходки план")] + public double RateOfPenetrationPlan { get; set; } + + [Column("rate_of_penetration_fact"), Comment("Механическая скорость проходки факт")] + public double RateOfPenetrationFact { get; set; } + + [Column("route_speed_plan"), Comment("Рейсовая скорость план")] + public double RouteSpeedPlan { get; set; } + + [Column("route_speed_fact"), Comment("Рейсовая скорость факт")] + public double RouteSpeedFact { get; set; } + + [Column("bha_down_speed_plan"), Comment("Скорость спуска КНБК план")] + public double BhaDownSpeedPlan { get; set; } + + [Column("bha_down_speed_fact"), Comment("Скорость спуска КНБК факт")] + public double BhaDownSpeedFact { get; set; } + + [Column("bha_up_speed_plan"), Comment("Скорость подъема КНБК план")] + public double BhaUpSpeedPlan { get; set; } + + [Column("bha_up_speed_fact"), Comment("Скорость подъема КНБК факт")] + public double BhaUpSpeedFact { get; set; } + + [Column("casing_down_speed_plan"), Comment("Скорость спуска ОК план")] + public double CasingDownSpeedPlan { get; set; } + + [Column("casing_down_speed_fact"), Comment("Скорость спуска ОК факт")] + public double CasingDownSpeedFact { get; set; } + + [JsonIgnore] + [ForeignKey(nameof(IdWell))] + [InverseProperty(nameof(Model.Well.SectionAnalysis))] + public virtual Well Well { get; set; } + + [JsonIgnore] + [ForeignKey(nameof(IdWellSectionType))] + [InverseProperty(nameof(Analytics.WellSectionType.WellSections))] + public virtual WellSectionType WellSectionType { get; set; } + } +} diff --git a/AsbCloudDb/Model/Analytics/WellSectionType.cs b/AsbCloudDb/Model/Analytics/WellSectionType.cs new file mode 100644 index 00000000..e92747c6 --- /dev/null +++ b/AsbCloudDb/Model/Analytics/WellSectionType.cs @@ -0,0 +1,27 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System; +using System.Text.Json.Serialization; +using System.Collections.Generic; +#nullable disable + +namespace AsbCloudDb.Model.Analytics +{ + + [Table("t_well_section_type"), Comment("конструкция секции скважины")] + public class WellSectionType + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("caption"), Comment("Название")] + [StringLength(255)] + public string Caption { get; set; } + + [JsonIgnore] + [InverseProperty(nameof(Analytics.WellSection.WellSectionType))] + public virtual ICollection WellSections { get; set; } + } +} diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 19ab9024..f9da758d 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -1,4 +1,5 @@ -using Microsoft.EntityFrameworkCore; +using AsbCloudDb.Model.Analytics; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -14,7 +15,7 @@ namespace AsbCloudDb.Model { //private readonly string connectionString; public virtual DbSet Clusters { get; set; } - public virtual DbSet Customers { get; set; } + public virtual DbSet Companies { get; set; } public virtual DbSet DataSaubBases { get; set; } public virtual DbSet Deposits { get; set; } public virtual DbSet Events { get; set; } @@ -26,7 +27,9 @@ namespace AsbCloudDb.Model public virtual DbSet Wells { get; set; } public virtual DbSet Reports { get; set; } public virtual DbSet Operations { get; set; } - public virtual DbSet TelemetryAnalysis { get; set; } + public virtual DbSet TelemetryAnalysis { get; set; } + public virtual DbSet SectionAnalysis { get; set; } + public virtual DbSet WellDrillingStats { get; set; } //public AsbCloudDbContext(string connectionString = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") //{ @@ -118,18 +121,27 @@ namespace AsbCloudDb.Model }); }); - modelBuilder.Entity(entity => + modelBuilder.Entity(entity => { - entity.HasData(new List{ - new Customer{ Id = 1, Caption = "\"ООО\" АСБ", }, + entity.HasData(new List{ + new CompanyType{ Id = 1, Caption = "Недрапользователь", }, + new CompanyType{ Id = 2, Caption = "Буровой подрядчик", }, + new CompanyType{ Id = 3, Caption = "Сервис автоматизации бурения", }, + }); + }); + + modelBuilder.Entity(entity => + { + entity.HasData(new List{ + new Company{ Id = 1, Caption = "\"ООО\" АСБ", IdCompanyType = 3}, }); }); modelBuilder.Entity(entity => { - entity.HasOne(d => d.Customer) + entity.HasOne(d => d.Company) .WithMany(p => p.Users) - .HasForeignKey(d => d.IdCustomer) + .HasForeignKey(d => d.IdCompany) .HasConstraintName("t_user_t_customer_id_fk"); entity.HasIndex(d => d.Login) @@ -138,7 +150,7 @@ namespace AsbCloudDb.Model entity.HasData(new List{ new User{ Id = 1, - IdCustomer = 1, + IdCompany = 1, IdRole = 1, Level = int.MaxValue, Login = "dev", @@ -155,10 +167,9 @@ namespace AsbCloudDb.Model .HasForeignKey(d => d.IdCluster) .HasConstraintName("t_well_t_cluster_id_fk"); - entity.HasOne(d => d.Customer) - .WithMany(p => p.Wells) - .HasForeignKey(d => d.IdCustomer) - .HasConstraintName("t_well_t_customer_id_fk"); + // Todo: Setup relation table names (https://stackoverflow.com/questions/11769864/many-to-many-relationships-in-ef5-code-first-how-can-i-specify-table-name) + entity.HasMany(d => d.Companies) + .WithMany(p => p.Wells); entity.HasOne(d => d.Telemetry) .WithOne(p => p.Well) @@ -194,15 +205,15 @@ namespace AsbCloudDb.Model modelBuilder.Entity(entity => { entity.HasData(new List { - new Well{Id = 1, IdCluster = 1, IdCustomer = 1, Caption = "скв 42669", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, - new Well{Id = 2, IdCluster = 1, IdCustomer = 1, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, - new Well{Id = 3, IdCluster = 2, IdCustomer = 1, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, - new Well{Id = 4, IdCluster = 2, IdCustomer = 1, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, - new Well{Id = 5, IdCluster = 3, IdCustomer = 1, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889}, - new Well{Id = 6, IdCluster = 4, IdCustomer = 1, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556}, - new Well{Id = 7, IdCluster = 5, IdCustomer = 1, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, - new Well{Id = 8, IdCluster = 5, IdCustomer = 1, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, - new Well{Id = 9, IdCluster = 5, IdCustomer = 1, Caption = "скв 16314", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, + new Well{Id = 1, IdCluster = 1, Caption = "скв 42669", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, + new Well{Id = 2, IdCluster = 1, Caption = "скв 16311", Latitude = 60.8705722222222, Longitude = 70.3811888888889}, + new Well{Id = 3, IdCluster = 2, Caption = "скв 16315", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, + new Well{Id = 4, IdCluster = 2, Caption = "скв 16318", Latitude = 60.8205750000000, Longitude = 70.1343833333334}, + new Well{Id = 5, IdCluster = 3, Caption = "скв 16310", Latitude = 60.8100666666667, Longitude = 69.7778388888889}, + new Well{Id = 6, IdCluster = 4, Caption = "скв 16316", Latitude = 60.8928805555556, Longitude = 70.3272055555556}, + new Well{Id = 7, IdCluster = 5, Caption = "скв 16312", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, + new Well{Id = 8, IdCluster = 5, Caption = "скв 16313", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, + new Well{Id = 9, IdCluster = 5, Caption = "скв 16314", Latitude = 60.6672055555556, Longitude = 69.6603861111111}, }); }); @@ -230,20 +241,20 @@ namespace AsbCloudDb.Model }); } - public IQueryable GetWellsByCustomer(int idCustomer) + public IQueryable GetWellsForCompany(int idCompany) { return from well in Wells - .Include(w => w.Customer) + .Include(w => w.Companies) .Include(w => w.Cluster) .ThenInclude(c => c.Deposit) - where well.IdCustomer == idCustomer + where well.Companies.Any(c => c.Id == idCompany) select well; } public IQueryable GetUsersByLogin(string login) => Users .Include(e => e.Role) - .Include(e => e.Customer) + .Include(e => e.Company) .Where(e => e.Login == login); public (DateTime From, DateTime To) GetDatesRange(int idTelemetry) diff --git a/AsbCloudDb/Model/Company.cs b/AsbCloudDb/Model/Company.cs new file mode 100644 index 00000000..98269519 --- /dev/null +++ b/AsbCloudDb/Model/Company.cs @@ -0,0 +1,41 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable + +namespace AsbCloudDb.Model +{ + [Table("t_company")] + public partial class Company : IId + { + public Company() + { + Users = new HashSet(); + Wells = new HashSet(); + } + + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("caption")] + [StringLength(255)] + public string Caption { get; set; } + + [Column("id_company_type"), Comment("вид деятельности")] + [StringLength(255)] + public int IdCompanyType { get; set; } + + [ForeignKey(nameof(IdCompanyType))] + [InverseProperty(nameof(Model.CompanyType.Companies))] + public virtual CompanyType CompanyType { get; set; } + + [InverseProperty(nameof(User.Company))] + public virtual ICollection Users { get; set; } + + [InverseProperty(nameof(Well.Companies))] + public virtual ICollection Wells { get; set; } + } +} diff --git a/AsbCloudDb/Model/CompanyType.cs b/AsbCloudDb/Model/CompanyType.cs new file mode 100644 index 00000000..10e78ec9 --- /dev/null +++ b/AsbCloudDb/Model/CompanyType.cs @@ -0,0 +1,24 @@ +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable + +namespace AsbCloudDb.Model +{ + [Table("t_company_type")] + public partial class CompanyType + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("caption")] + [StringLength(255)] + public string Caption { get; set; } + + [InverseProperty(nameof(Company.CompanyType))] + public virtual ICollection Companies { get; set; } + } +} diff --git a/AsbCloudDb/Model/Customer.cs b/AsbCloudDb/Model/Customer.cs deleted file mode 100644 index cb4f2e9e..00000000 --- a/AsbCloudDb/Model/Customer.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; - -#nullable disable - -namespace AsbCloudDb.Model -{ - [Table("t_customer")] - public partial class Customer : IId - { - public Customer() - { - Users = new HashSet(); - Wells = new HashSet(); - } - - [Key] - [Column("id")] - public int Id { get; set; } - [Column("caption")] - [StringLength(255)] - public string Caption { get; set; } - - [InverseProperty(nameof(User.Customer))] - public virtual ICollection Users { get; set; } - - [InverseProperty(nameof(Well.Customer))] - public virtual ICollection Wells { get; set; } - } -} diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index c429966e..871e4bd4 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -10,7 +10,7 @@ namespace AsbCloudDb.Model public interface IAsbCloudDbContext { DbSet Clusters { get; set; } - DbSet Customers { get; set; } + DbSet Companies { get; set; } DbSet DataSaubBases { get; set; } DbSet Deposits { get; set; } DbSet Events { get; set; } @@ -28,7 +28,7 @@ namespace AsbCloudDb.Model int SaveChanges(bool acceptAllChangesOnSuccess); Task SaveChangesAsync(CancellationToken cancellationToken); - IQueryable GetWellsByCustomer(int idCustomer); + IQueryable GetWellsForCompany(int idCustomer); IQueryable GetUsersByLogin(string login); (DateTime From, DateTime To) GetDatesRange(int idTelemetry) where T : class, IIdTelemetryDate; IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId, diff --git a/AsbCloudDb/Model/Report.cs b/AsbCloudDb/Model/Report.cs index 2f63aa66..5e09a075 100644 --- a/AsbCloudDb/Model/Report.cs +++ b/AsbCloudDb/Model/Report.cs @@ -11,20 +11,29 @@ namespace AsbCloudDb.Model [Key] [Column("id")] public int Id { get; set; } + [Column("name"), Comment("Название отчета (файла)")] public string Name { get; set; } + [Column("id_well"), Comment("id скважины")] - public int WellId { get; set; } + public int IdWell { get; set; } + [Column("date", TypeName = "timestamp with time zone")] public DateTime Date { get; set; } + [Column("begin", TypeName = "timestamp with time zone")] public DateTimeOffset Begin { get; set; } + [Column("end"), Comment("timestamp with time zone")] public DateTimeOffset End { get; set; } + [Column("step"), Comment("размер шага в секундах")] public int Step { get; set; } + [Column("format"), Comment("Формат отчета")] public int Format { get; set; } + [ForeignKey(nameof(IdWell))] + public virtual Well Well { get; set; } } } diff --git a/AsbCloudDb/Model/User.cs b/AsbCloudDb/Model/User.cs index 3108aa44..284b1cfa 100644 --- a/AsbCloudDb/Model/User.cs +++ b/AsbCloudDb/Model/User.cs @@ -13,8 +13,8 @@ namespace AsbCloudDb.Model [Column("id")] public int Id { get; set; } - [Column("id_customer")] - public int? IdCustomer { get; set; } + [Column("id_company")] + public int? IdCompany { get; set; } [Column("id_role")] public int? IdRole { get; set; } @@ -46,9 +46,9 @@ namespace AsbCloudDb.Model [StringLength(255)] public string Patronymic { get; set; } - [ForeignKey(nameof(IdCustomer))] - [InverseProperty(nameof(Model.Customer.Users))] - public virtual Customer Customer { get; set; } + [ForeignKey(nameof(IdCompany))] + [InverseProperty(nameof(Model.Company.Users))] + public virtual Company Company { get; set; } [ForeignKey(nameof(IdRole))] [InverseProperty(nameof(Model.UserRole.Users))] diff --git a/AsbCloudDb/Model/Well.cs b/AsbCloudDb/Model/Well.cs index 394eba4f..fc9d2c02 100644 --- a/AsbCloudDb/Model/Well.cs +++ b/AsbCloudDb/Model/Well.cs @@ -1,4 +1,6 @@ -using Microsoft.EntityFrameworkCore; +using AsbCloudDb.Model.Analytics; +using Microsoft.EntityFrameworkCore; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -20,9 +22,6 @@ namespace AsbCloudDb.Model [Column("id_cluster")] public int? IdCluster { get; set; } - [Column("id_customer")] - public int? IdCustomer { get; set; } - [Column("id_telemetry")] public int? IdTelemetry { get; set; } @@ -30,10 +29,6 @@ namespace AsbCloudDb.Model [InverseProperty(nameof(Model.Cluster.Wells))] public virtual Cluster Cluster { get; set; } - [ForeignKey(nameof(IdCustomer))] - [InverseProperty(nameof(Model.Customer.Wells))] - public virtual Customer Customer { get; set; } - [ForeignKey(nameof(IdTelemetry))] [InverseProperty(nameof(Model.Telemetry.Well))] public virtual Telemetry Telemetry { get; set; } @@ -43,5 +38,14 @@ namespace AsbCloudDb.Model [Column("longitude")] public double Longitude { get; set; } + + [InverseProperty(nameof(Analytics.WellSection.Well))] + public virtual ICollection SectionAnalysis { get; set; } + + [InverseProperty(nameof(Analytics.WellDrillingStat.Well))] + public virtual WellDrillingStat WellDrillingStat { get; set; } + + [Column("companines"), Comment("участники (заказчик, подрядчики и субподрядчики)")] + public virtual ICollection Companies { get; set; } } } diff --git a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs index ffdde63d..2d230cbb 100644 --- a/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs +++ b/AsbCloudInfrastructure/ReportDataSourcePgCloud.cs @@ -29,7 +29,7 @@ namespace AsbSaubReport var well = context.Wells .Include(w=>w.Cluster) .ThenInclude(c=>c.Deposit) - .Include(w=>w.Customer) + .Include(w=>w.Companies) .Include(w => w.Telemetry) .FirstOrDefault(w => w.Id == wellId); @@ -50,7 +50,7 @@ namespace AsbSaubReport Deposit = well.Cluster.Deposit.Caption, Cluster = well.Cluster.Caption, Well = well.Caption, - Customer = well.Customer.Caption, + Customer = well.Companies.First(c=>c.IdCompanyType == 1)?.Caption, DrillingStartDate = well.Telemetry?.Info?.DrillingStartDate??default, TimeZoneId = well.Telemetry?.Info?.TimeZoneId??default, }; diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index 531355d8..07bf9fe2 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -24,7 +24,7 @@ namespace AsbCloudInfrastructure.Services private static readonly TimeSpan expiresTimespan = TimeSpan.FromDays(365.25); private static readonly Encoding encoding = Encoding.UTF8; private const int PasswordSaltLength = 5; - private const string claimNameIdCustomer = "IdCustomer"; + private const string claimNameidCompany = "idCompany"; private readonly HashAlgorithm hashAlgoritm; private readonly Random rnd; @@ -45,7 +45,7 @@ namespace AsbCloudInfrastructure.Services { Id = identity.User.Id, Name = identity.User.Name, - CustomerName = identity.User.Customer.Caption, + CustomerName = identity.User.Company.Caption, Level = identity.User.Level, Login = identity.User.Login, Patronymic = identity.User.Patronymic, @@ -68,7 +68,7 @@ namespace AsbCloudInfrastructure.Services if (userDto.Password.Length < 3) return -2; - //if (db.Customers.FirstOrDefault(c=>c.Id == userDto.IdCustomer) is null) + //if (db.Customers.FirstOrDefault(c=>c.Id == userDto.idCompany) is null) // return -3; //if (db.UserRoles.FirstOrDefault(c => c.Id == userDto.IdRole) is null) @@ -81,7 +81,7 @@ namespace AsbCloudInfrastructure.Services var user = new User { - IdCustomer = userDto.IdCustomer, + IdCompany = userDto.IdCompany, IdRole = userDto.IdRole, Name = userDto.Name, Surname = userDto.Surname, @@ -159,7 +159,7 @@ namespace AsbCloudInfrastructure.Services { new Claim(ClaimsIdentity.DefaultNameClaimType, user.Login), new Claim(ClaimsIdentity.DefaultRoleClaimType, user.Role?.Caption??"GUEST"), - new Claim(claimNameIdCustomer, user.IdCustomer.ToString()), + new Claim(claimNameidCompany, user.IdCompany.ToString()), }; var claimsIdentity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); return (claimsIdentity, user); diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 2c998fe8..55cc730a 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -50,7 +50,7 @@ namespace AsbCloudInfrastructure.Services var newReportProperties = new Report { Name = newReportName, - WellId = wellId, + IdWell = wellId, Date = DateTime.Now, Begin = begin, End = end, @@ -81,7 +81,7 @@ namespace AsbCloudInfrastructure.Services Id = r.Id, Name = Path.GetFileName(r.Name), FullName = r.Name, - WellId = r.WellId, + WellId = r.IdWell, Date = r.Date, Begin = r.Begin, End = r.End, @@ -120,7 +120,7 @@ namespace AsbCloudInfrastructure.Services private IEnumerable GetSuitableReportsFromDb(int wellId, DateTime begin, DateTime end, int stepSeconds, int format) { var suitableReportsNames = (from r in db.Reports - where r.WellId == wellId + where r.IdWell == wellId && r.Begin >= begin && r.End <= end && r.Step <= stepSeconds diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index f6956cf8..767b24bc 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -21,27 +21,27 @@ namespace AsbCloudInfrastructure.Services cacheWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } - public IEnumerable GetTransmittingWells(int idCustomer) + public IEnumerable GetTransmittingWells(int idCompany) { var wells = new List(); IEnumerable activeTelemetriesUids = telemetryTracker.GetTransmittingTelemetryUids(); if (activeTelemetriesUids.Any()) { - wells = db.GetWellsByCustomer(idCustomer) + wells = db.GetWellsForCompany(idCompany) .Where(w => activeTelemetriesUids.Contains(w.Telemetry.RemoteUid)) .ToList(); } return wells.Select(w => From(w)); } - public IEnumerable GetWellsByCustomer(int idCustomer) + public IEnumerable GetWellsByCustomer(int idCompany) { - var wells = db.GetWellsByCustomer(idCustomer).ToList(); + var wells = db.GetWellsForCompany(idCompany).ToList(); return wells.Select(w => From(w)); } - public bool CheckWellOwnership(int idCustomer, int wellId) - => cacheWells.Contains(w => w.Id == wellId && w.IdCustomer == idCustomer); + public bool CheckWellOwnership(int idCompany, int wellId) + => cacheWells.Contains(w => w.Id == wellId && (w.Companies.FirstOrDefault(c => c.Id == idCompany) != null)); private static WellDto From(Well well) diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs index 8060484e..05d2daa6 100644 --- a/AsbCloudInfrastructure/Services/СlusterService.cs +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -1,6 +1,8 @@ using AsbCloudApp.Data; +using AsbCloudApp.Data.Analytics; using AsbCloudApp.Services; using AsbCloudDb.Model; +using AsbCloudDb.Model.Analytics; using AsbCloudInfrastructure.Services.Cache; using Microsoft.EntityFrameworkCore; using System; @@ -20,9 +22,9 @@ namespace AsbCloudInfrastructure.Services this.db = db; } - public IEnumerable GetDeposits(int idCustomer) + public IEnumerable GetDeposits(int idCompany) { - var entities = db.GetWellsByCustomer(idCustomer) + var entities = db.GetWellsForCompany(idCompany) .Select(e=>e.Cluster.Deposit) .Distinct() .ToList(); @@ -38,9 +40,9 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetClusters(int idCustomer) + public IEnumerable GetClusters(int idCompany) { - var entities = db.GetWellsByCustomer(idCustomer) + var entities = db.GetWellsForCompany(idCompany) .Select(e => e.Cluster) .Distinct() .ToList(); @@ -56,9 +58,9 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetClusters(int idCustomer, int depositId) + public IEnumerable GetClusters(int idCompany, int depositId) { - var entities = db.GetWellsByCustomer(idCustomer) + var entities = db.GetWellsForCompany(idCompany) .Select(e => e.Cluster) .Where(e=>e.IdDeposit == depositId) .Distinct() @@ -75,9 +77,9 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetWells(int idCustomer, int clusterId) + public IEnumerable GetWells(int idCompany, int clusterId) { - var entities = db.GetWellsByCustomer(idCustomer) + var entities = db.GetWellsForCompany(idCompany) .Where(e => e.IdCluster == clusterId) .ToList(); @@ -94,7 +96,7 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetAnalysis(int idCustomer, int clusterId) + public IEnumerable GetStat(int idCompany, int clusterId) { throw new NotImplementedException(); } diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index f81e7b28..b9b10427 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -1,5 +1,7 @@ using AsbCloudApp.Data; +using AsbCloudApp.Data.Analytics; using AsbCloudApp.Services; +using AsbCloudDb.Model.Analytics; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -66,7 +68,7 @@ namespace AsbCloudWebApi.Controllers /// /// [HttpGet("{clusterId}/Analysis")] - [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] + [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetAnalysis(int clusterId) { int? idCustomer = User.GetCustomerId(); @@ -74,7 +76,7 @@ namespace AsbCloudWebApi.Controllers if (idCustomer is null) return Forbid(); - var result = clusterService.GetAnalysis((int)idCustomer, clusterId); + var result = clusterService.GetStat((int)idCustomer, clusterId); return Ok(result); } } diff --git a/AsbCloudWebApi/Extensions.cs b/AsbCloudWebApi/Extensions.cs index 3197eb85..e0f9224e 100644 --- a/AsbCloudWebApi/Extensions.cs +++ b/AsbCloudWebApi/Extensions.cs @@ -7,7 +7,7 @@ namespace AsbCloudWebApi { public static int? GetCustomerId(this ClaimsPrincipal user) { - var claimIdCustomer = user.FindFirst(nameof(User.IdCustomer)); + var claimIdCustomer = user.FindFirst(nameof(User.IdCompany)); if (claimIdCustomer is null) return null; diff --git a/DataTable/Program.cs b/DataTable/Program.cs index 323f75c6..061ba1ea 100644 --- a/DataTable/Program.cs +++ b/DataTable/Program.cs @@ -10,9 +10,9 @@ namespace DataTable { class Program { - static void Main(string[] args) + static void Main(/*string[] args*/) { - var listDtos = new List(100); + //var listDtos = new List(100); /* *** Size of TestDto calc *** * @@ -52,40 +52,40 @@ namespace DataTable * listBinBytes: 4366 (by dangerous BinaryFormatter) */ - for (int i = 0; i < 100; i++) - listDtos.Add(new TestDto{ - Date = DateTime.Now.AddSeconds(i), - Mode = 1, - WellDepth = i * Math.PI - }); + //for (int i = 0; i < 100; i++) + // listDtos.Add(new TestDto{ + // Date = DateTime.Now.AddSeconds(i), + // Mode = 1, + // WellDepth = i * Math.PI + // }); - var tMapper = new TableMapper(); + //var tMapper = new TableMapper(); - var tab = tMapper.MakeTable(listDtos); + //var tab = tMapper.MakeTable(listDtos); - var e = tMapper.AsEnumerable(tab); + //var e = tMapper.AsEnumerable(tab); - var tabJson = JsonSerializer.Serialize(tab); - var listJson = JsonSerializer.Serialize(listDtos); + //var tabJson = JsonSerializer.Serialize(tab); + //var listJson = JsonSerializer.Serialize(listDtos); - var tabJsonBytes = JsonSerializer.SerializeToUtf8Bytes(tab); - var listJsonBytes = JsonSerializer.SerializeToUtf8Bytes(listDtos); + //var tabJsonBytes = JsonSerializer.SerializeToUtf8Bytes(tab); + //var listJsonBytes = JsonSerializer.SerializeToUtf8Bytes(listDtos); - var formatter = new BinaryFormatter(); - var mem = new MemoryStream(); - formatter.Serialize(mem, tab); - var tabBinBytes = new byte[mem.Length]; - Array.Copy(mem.GetBuffer(), tabBinBytes, mem.Length); + //var formatter = new BinaryFormatter(); + //var mem = new MemoryStream(); + //formatter.Serialize(mem, tab); + //var tabBinBytes = new byte[mem.Length]; + //Array.Copy(mem.GetBuffer(), tabBinBytes, mem.Length); - mem = new MemoryStream(); - formatter.Serialize(mem, listDtos); - var listBinBytes = new byte[mem.Length]; - Array.Copy(mem.GetBuffer(), listBinBytes, mem.Length); + //mem = new MemoryStream(); + //formatter.Serialize(mem, listDtos); + //var listBinBytes = new byte[mem.Length]; + //Array.Copy(mem.GetBuffer(), listBinBytes, mem.Length); - Console.WriteLine($"tabJsonBytes:{tabJsonBytes.Length}"); - Console.WriteLine($"listJsonBytes:{listJsonBytes.Length}"); - Console.WriteLine($"tabBinBytes:{tabBinBytes.Length}"); - Console.WriteLine($"listBinBytes:{listBinBytes.Length}"); + //Console.WriteLine($"tabJsonBytes:{tabJsonBytes.Length}"); + //Console.WriteLine($"listJsonBytes:{listJsonBytes.Length}"); + //Console.WriteLine($"tabBinBytes:{tabBinBytes.Length}"); + //Console.WriteLine($"listBinBytes:{listBinBytes.Length}"); } } }