diff --git a/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs b/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs deleted file mode 100644 index b31e326b..00000000 --- a/AsbCloudApp/Data/Analytics/WellDrillingStatDto.cs +++ /dev/null @@ -1,22 +0,0 @@ -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/ClusterDto.cs b/AsbCloudApp/Data/ClusterDto.cs index 492821e5..4cb189e1 100644 --- a/AsbCloudApp/Data/ClusterDto.cs +++ b/AsbCloudApp/Data/ClusterDto.cs @@ -11,8 +11,8 @@ namespace AsbCloudApp.Data 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 double? Latitude { get; set; } + public double? Longitude { get; set; } //public IEnumerable Wells { get; set; } } diff --git a/AsbCloudApp/Data/CompanyDto.cs b/AsbCloudApp/Data/CompanyDto.cs new file mode 100644 index 00000000..795d4358 --- /dev/null +++ b/AsbCloudApp/Data/CompanyDto.cs @@ -0,0 +1,9 @@ +namespace AsbCloudApp.Data +{ + public class CompanyDto + { + public int Id { get; set; } + public string Caption { get; set; } + public string CompanyType { get; set; } + } +} diff --git a/AsbCloudApp/Data/ContractorDto.cs b/AsbCloudApp/Data/ContractorDto.cs deleted file mode 100644 index bb2f31a0..00000000 --- a/AsbCloudApp/Data/ContractorDto.cs +++ /dev/null @@ -1,9 +0,0 @@ -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/DepositDto.cs b/AsbCloudApp/Data/DepositDto.cs index bbd62657..a8055de2 100644 --- a/AsbCloudApp/Data/DepositDto.cs +++ b/AsbCloudApp/Data/DepositDto.cs @@ -5,8 +5,8 @@ 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 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 index 6ed1b0d8..c38b742c 100644 --- a/AsbCloudApp/Data/IMapPoint.cs +++ b/AsbCloudApp/Data/IMapPoint.cs @@ -8,8 +8,7 @@ namespace AsbCloudApp.Data { public interface IMapPoint { - double Latitude { get; set; } - - double Longitude { get; set; } + double? Latitude { get; set; } + double? Longitude { get; set; } } } diff --git a/AsbCloudApp/Data/UserTokenDto.cs b/AsbCloudApp/Data/UserTokenDto.cs index 4fb4cf04..229e99fa 100644 --- a/AsbCloudApp/Data/UserTokenDto.cs +++ b/AsbCloudApp/Data/UserTokenDto.cs @@ -3,7 +3,7 @@ public class UserTokenDto : UserBaseDto { public int Id { get; set; } - public string CustomerName { get; set; } + public string CompanyName { get; set; } public string RoleName { get; set; } public string Token { get; set; } } diff --git a/AsbCloudApp/Data/WellDrillingStatDto.cs b/AsbCloudApp/Data/WellDrillingStatDto.cs new file mode 100644 index 00000000..3decb785 --- /dev/null +++ b/AsbCloudApp/Data/WellDrillingStatDto.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace AsbCloudApp.Data +{ + public class WellDrillingStatDto: WellDto + { + public DateTime? PlanStart { get; set; } + public DateTime? PlanEnd { get; set; } + public DateTime? FactStart { get; set; } + public DateTime? FactEnd { get; set; } + public double? UnProductiveDays { 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 Companies { get; set; } + } +} diff --git a/AsbCloudApp/Data/WellDto.cs b/AsbCloudApp/Data/WellDto.cs index f96db114..1a8621b9 100644 --- a/AsbCloudApp/Data/WellDto.cs +++ b/AsbCloudApp/Data/WellDto.cs @@ -5,9 +5,8 @@ { public int Id { get; set; } public object LastData { get; set; }//DataSaubBaseDto - public double Latitude { get; set; } - public double Longitude { get; set; } - - public int WellType { get; set; } + public double? Latitude { get; set; } + public double? Longitude { get; set; } + public string WellType { get; set; } } } diff --git a/AsbCloudApp/Data/Analytics/WellSectionDto.cs b/AsbCloudApp/Data/WellSectionDto.cs similarity index 95% rename from AsbCloudApp/Data/Analytics/WellSectionDto.cs rename to AsbCloudApp/Data/WellSectionDto.cs index 8b648d0c..1f86dbe7 100644 --- a/AsbCloudApp/Data/Analytics/WellSectionDto.cs +++ b/AsbCloudApp/Data/WellSectionDto.cs @@ -1,4 +1,4 @@ -namespace AsbCloudApp.Data.Analytics +namespace AsbCloudApp.Data { public class WellSectionDto { diff --git a/AsbCloudApp/Services/IClusterService.cs b/AsbCloudApp/Services/IClusterService.cs index 4b238dbd..4c949b31 100644 --- a/AsbCloudApp/Services/IClusterService.cs +++ b/AsbCloudApp/Services/IClusterService.cs @@ -1,5 +1,4 @@ using AsbCloudApp.Data; -using AsbCloudApp.Data.Analytics; using System; using System.Collections.Generic; using System.Linq; @@ -10,10 +9,10 @@ namespace AsbCloudApp.Services { public interface IClusterService { - IEnumerable GetDeposits(int idCustomer); - IEnumerable GetClusters(int idCustomer, int depositId); - IEnumerable GetClusters(int idCustomer); - IEnumerable GetWells(int idCustomer, int clusterId); - IEnumerable GetStat(int idCustomer, int clusterId); + IEnumerable GetDeposits(int idCompany); + IEnumerable GetClusters(int idCompany, int depositId); + IEnumerable GetClusters(int idCompany); + IEnumerable GetWells(int idCompany, int clusterId); + IEnumerable GetStat(int idCompany, int clusterId); } } diff --git a/AsbCloudApp/Services/IWellService.cs b/AsbCloudApp/Services/IWellService.cs index 88378e6f..421578d7 100644 --- a/AsbCloudApp/Services/IWellService.cs +++ b/AsbCloudApp/Services/IWellService.cs @@ -6,8 +6,8 @@ namespace AsbCloudApp.Services { public interface IWellService { - IEnumerable GetWellsByCustomer(int idCustomer); - IEnumerable GetTransmittingWells(int idCustomer); - bool CheckWellOwnership(int idCustomer, int wellId); + IEnumerable GetWellsByCompany(int idCompany); + IEnumerable GetTransmittingWells(int idCompany); + bool CheckWellOwnership(int idCompany, int wellId); } } diff --git a/AsbCloudDb/Model/Analytics/WellDrillingStat.cs b/AsbCloudDb/Model/Analytics/WellDrillingStat.cs deleted file mode 100644 index cf8143d3..00000000 --- a/AsbCloudDb/Model/Analytics/WellDrillingStat.cs +++ /dev/null @@ -1,55 +0,0 @@ -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/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index f9da758d..a6c830da 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -1,5 +1,4 @@ -using AsbCloudDb.Model.Analytics; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -29,7 +28,7 @@ namespace AsbCloudDb.Model public virtual DbSet Operations { get; set; } public virtual DbSet TelemetryAnalysis { get; set; } public virtual DbSet SectionAnalysis { get; set; } - public virtual DbSet WellDrillingStats { get; set; } + public virtual DbSet WellTypes { get; set; } //public AsbCloudDbContext(string connectionString = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") //{ @@ -142,7 +141,7 @@ namespace AsbCloudDb.Model entity.HasOne(d => d.Company) .WithMany(p => p.Users) .HasForeignKey(d => d.IdCompany) - .HasConstraintName("t_user_t_customer_id_fk"); + .HasConstraintName("t_user_t_company_id_fk"); entity.HasIndex(d => d.Login) .IsUnique(); diff --git a/AsbCloudDb/Model/Cluster.cs b/AsbCloudDb/Model/Cluster.cs index db6017db..971a1c3f 100644 --- a/AsbCloudDb/Model/Cluster.cs +++ b/AsbCloudDb/Model/Cluster.cs @@ -34,9 +34,9 @@ namespace AsbCloudDb.Model public virtual ICollection Wells { get; set; } [Column("latitude")] - public double Latitude { get; set; } + public double? Latitude { get; set; } [Column("longitude")] - public double Longitude { get; set; } + public double? Longitude { get; set; } } } diff --git a/AsbCloudDb/Model/Deposit.cs b/AsbCloudDb/Model/Deposit.cs index 385ee1f4..edb72b8d 100644 --- a/AsbCloudDb/Model/Deposit.cs +++ b/AsbCloudDb/Model/Deposit.cs @@ -27,9 +27,9 @@ namespace AsbCloudDb.Model public virtual ICollection Clusters { get; set; } [Column("latitude")] - public double Latitude { get; set; } + public double? Latitude { get; set; } [Column("longitude")] - public double Longitude { get; set; } + public double? Longitude { get; set; } } } diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 871e4bd4..693e9546 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -28,7 +28,7 @@ namespace AsbCloudDb.Model int SaveChanges(bool acceptAllChangesOnSuccess); Task SaveChangesAsync(CancellationToken cancellationToken); - IQueryable GetWellsForCompany(int idCustomer); + IQueryable GetWellsForCompany(int idCompany); 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/IMapPoint.cs b/AsbCloudDb/Model/IMapPoint.cs index e1df799d..8979fa84 100644 --- a/AsbCloudDb/Model/IMapPoint.cs +++ b/AsbCloudDb/Model/IMapPoint.cs @@ -8,8 +8,8 @@ namespace AsbCloudDb.Model { public interface IMapPoint { - double Latitude { get; set; } + double? Latitude { get; set; } - double Longitude { get; set; } + double? Longitude { get; set; } } } diff --git a/AsbCloudDb/Model/Analytics/SectionType.cs b/AsbCloudDb/Model/SectionType.cs similarity index 86% rename from AsbCloudDb/Model/Analytics/SectionType.cs rename to AsbCloudDb/Model/SectionType.cs index 46009f0a..a529d338 100644 --- a/AsbCloudDb/Model/Analytics/SectionType.cs +++ b/AsbCloudDb/Model/SectionType.cs @@ -1,4 +1,4 @@ -namespace AsbCloudDb.Model.Analytics +namespace AsbCloudDb.Model { public enum SectionType { diff --git a/AsbCloudDb/Model/Well.cs b/AsbCloudDb/Model/Well.cs index fc9d2c02..06b2f338 100644 --- a/AsbCloudDb/Model/Well.cs +++ b/AsbCloudDb/Model/Well.cs @@ -1,5 +1,5 @@ -using AsbCloudDb.Model.Analytics; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; @@ -25,6 +25,53 @@ namespace AsbCloudDb.Model [Column("id_telemetry")] public int? IdTelemetry { get; set; } + [Column("id_well_type")] + public int? IdWellType { get; set; } + + [Column("latitude")] + public double? Latitude { get; set; } + + [Column("longitude")] + public double? Longitude { 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; } + + + [ForeignKey(nameof(IdWellType))] + [InverseProperty(nameof(Model.WellType.Wells))] + public virtual WellType WellType { get; set; } + + [InverseProperty(nameof(WellSection.Well))] + public virtual ICollection Sections { get; set; } + + [InverseProperty(nameof(Company.Wells))] + public virtual ICollection Companies { get; set; } + [ForeignKey(nameof(IdCluster))] [InverseProperty(nameof(Model.Cluster.Wells))] public virtual Cluster Cluster { get; set; } @@ -32,20 +79,5 @@ 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; } - - [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/AsbCloudDb/Model/Analytics/WellSection.cs b/AsbCloudDb/Model/WellSection.cs similarity index 94% rename from AsbCloudDb/Model/Analytics/WellSection.cs rename to AsbCloudDb/Model/WellSection.cs index 91522be0..037d4e40 100644 --- a/AsbCloudDb/Model/Analytics/WellSection.cs +++ b/AsbCloudDb/Model/WellSection.cs @@ -5,7 +5,7 @@ using System; using System.Text.Json.Serialization; #nullable disable -namespace AsbCloudDb.Model.Analytics +namespace AsbCloudDb.Model { [Table("t_well_section"), Comment("секция скважины")] @@ -65,12 +65,12 @@ namespace AsbCloudDb.Model.Analytics [JsonIgnore] [ForeignKey(nameof(IdWell))] - [InverseProperty(nameof(Model.Well.SectionAnalysis))] + [InverseProperty(nameof(Model.Well.Sections))] public virtual Well Well { get; set; } [JsonIgnore] [ForeignKey(nameof(IdWellSectionType))] - [InverseProperty(nameof(Analytics.WellSectionType.WellSections))] + [InverseProperty(nameof(Model.WellSectionType.WellSections))] public virtual WellSectionType WellSectionType { get; set; } } } diff --git a/AsbCloudDb/Model/Analytics/WellSectionType.cs b/AsbCloudDb/Model/WellSectionType.cs similarity index 86% rename from AsbCloudDb/Model/Analytics/WellSectionType.cs rename to AsbCloudDb/Model/WellSectionType.cs index e92747c6..1d2d30b0 100644 --- a/AsbCloudDb/Model/Analytics/WellSectionType.cs +++ b/AsbCloudDb/Model/WellSectionType.cs @@ -6,9 +6,8 @@ using System.Text.Json.Serialization; using System.Collections.Generic; #nullable disable -namespace AsbCloudDb.Model.Analytics +namespace AsbCloudDb.Model { - [Table("t_well_section_type"), Comment("конструкция секции скважины")] public class WellSectionType { @@ -21,7 +20,7 @@ namespace AsbCloudDb.Model.Analytics public string Caption { get; set; } [JsonIgnore] - [InverseProperty(nameof(Analytics.WellSection.WellSectionType))] + [InverseProperty(nameof(WellSection.WellSectionType))] public virtual ICollection WellSections { get; set; } } } diff --git a/AsbCloudDb/Model/WellType.cs b/AsbCloudDb/Model/WellType.cs new file mode 100644 index 00000000..3ac86c96 --- /dev/null +++ b/AsbCloudDb/Model/WellType.cs @@ -0,0 +1,26 @@ +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 +{ + [Table("t_well_type"), Comment("конструкция скважины")] + public class WellType + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("caption"), Comment("Название")] + [StringLength(255)] + public string Caption { get; set; } + + [JsonIgnore] + [InverseProperty(nameof(Well.WellType))] + public virtual ICollection Wells { get; set; } + } +} diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index 07bf9fe2..97a6ceaf 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -45,7 +45,7 @@ namespace AsbCloudInfrastructure.Services { Id = identity.User.Id, Name = identity.User.Name, - CustomerName = identity.User.Company.Caption, + CompanyName = identity.User.Company.Caption, Level = identity.User.Level, Login = identity.User.Login, Patronymic = identity.User.Patronymic, @@ -68,15 +68,6 @@ namespace AsbCloudInfrastructure.Services if (userDto.Password.Length < 3) return -2; - //if (db.Customers.FirstOrDefault(c=>c.Id == userDto.idCompany) is null) - // return -3; - - //if (db.UserRoles.FirstOrDefault(c => c.Id == userDto.IdRole) is null) - // return -4; - - //if (db.Users.FirstOrDefault(c => c.Login == userDto.Login) != null) - // return -5; - var salt = GenerateSalt(); var user = new User diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index 767b24bc..d91c7046 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services return wells.Select(w => From(w)); } - public IEnumerable GetWellsByCustomer(int idCompany) + public IEnumerable GetWellsByCompany(int idCompany) { var wells = db.GetWellsForCompany(idCompany).ToList(); return wells.Select(w => From(w)); diff --git a/AsbCloudInfrastructure/Services/СlusterService.cs b/AsbCloudInfrastructure/Services/СlusterService.cs index 05d2daa6..4e7201cb 100644 --- a/AsbCloudInfrastructure/Services/СlusterService.cs +++ b/AsbCloudInfrastructure/Services/СlusterService.cs @@ -1,8 +1,6 @@ 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; @@ -77,10 +75,10 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetWells(int idCompany, int clusterId) + public IEnumerable GetWells(int idCompany, int idCluster) { var entities = db.GetWellsForCompany(idCompany) - .Where(e => e.IdCluster == clusterId) + .Where(e => e.IdCluster == idCluster) .ToList(); var dtos = entities.Select(e => new WellDto @@ -96,9 +94,60 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public IEnumerable GetStat(int idCompany, int clusterId) + public IEnumerable GetStat(int idCompany, int idCluster) { - throw new NotImplementedException(); + var entities = from w in db.Wells + .Include(e => e.Companies) + .Include(e => e.Sections) + + where w.IdCluster == idCluster && w.Companies.Any(c => c.Id == idCompany) + select w; + + var dtos = entities.Select(e => new WellDrillingStatDto + { + Id = e.Id, + Caption = e.Caption, + Cluster = e.Cluster.Caption, + Deposit = e.Cluster.Deposit.Caption, + Latitude = e.Latitude, + Longitude = e.Longitude, + FactEnd = e.FactEnd, + FactStart = e.FactStart, + LastData = null, + PlanEnd = e.PlanEnd, + PlanStart = e.PlanStart, + RateOfPenetrationFact = e.RateOfPenetrationFact, + RateOfPenetrationPlan = e.RateOfPenetrationPlan, + RouteSpeedFact = e.RouteSpeedFact, + RouteSpeedPlan = e.RouteSpeedPlan, + Sections = e.Sections.Select(s => new WellSectionDto { + BhaDownSpeedFact = s.BhaDownSpeedFact, + BhaDownSpeedPlan = s.BhaDownSpeedPlan, + BhaUpSpeedFact = s.BhaUpSpeedFact, + BhaUpSpeedPlan = s.BhaUpSpeedPlan, + BuildDaysFact = s.BuildDaysFact, + BuildDaysPlan = s.BuildDaysPlan, + CasingDownSpeedFact = s.CasingDownSpeedFact, + CasingDownSpeedPlan = s.CasingDownSpeedPlan, + RateOfPenetrationFact = s.RateOfPenetrationFact, + RateOfPenetrationPlan = s.RateOfPenetrationPlan, + RouteSpeedFact = s.RouteSpeedFact, + RouteSpeedPlan = s.RouteSpeedPlan, + SectionType = s.WellSectionType.Caption, + WellDepthFact = s.WellDepthFact, + WellDepthPlan = s.WellDepthPlan, + }), + UnProductiveDays = e.UnProductiveDays, + Companies = e.Companies.Select(c => new CompanyDto + { + Id = c.Id, + Caption = c.Caption, + CompanyType = c.CompanyType.Caption, + }), + WellType = e.WellType.Caption, + }); + + return dtos; } } } diff --git a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs index b26abf30..eca4ab9a 100644 --- a/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs +++ b/AsbCloudWebApi.Tests/ControllersTests/AnalyticsControllerTests.cs @@ -42,7 +42,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { - new Claim("idCustomer", "1"), + new Claim("idCompany", "1"), }, "mock")); controller.ControllerContext = new ControllerContext() @@ -71,7 +71,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests } [Fact] - public void It_should_return_403_if_no_idCustomer() + public void It_should_return_403_if_no_idCompany() { var emptyUserController = new AnalyticsController(analyticsService.Object, wellService.Object); @@ -102,7 +102,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { - new Claim("idCustomer", "1"), + new Claim("idCompany", "1"), }, "mock")); newControllerInstance.ControllerContext = new ControllerContext() @@ -129,7 +129,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { - new Claim("idCustomer", "1"), + new Claim("idCompany", "1"), }, "mock")); newControllerInstance.ControllerContext = new ControllerContext() @@ -156,7 +156,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] { - new Claim("idCustomer", "1"), + new Claim("idCompany", "1"), }, "mock")); newControllerInstance.ControllerContext = new ControllerContext() diff --git a/AsbCloudWebApi/Controllers/AnalyticsController.cs b/AsbCloudWebApi/Controllers/AnalyticsController.cs index 82c06521..b9680bda 100644 --- a/AsbCloudWebApi/Controllers/AnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/AnalyticsController.cs @@ -32,9 +32,9 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetOperations(int wellId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperations(wellId); @@ -55,9 +55,9 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetWellDepthToDay(int wellId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId); @@ -81,9 +81,9 @@ namespace AsbCloudWebApi.Controllers public IActionResult GetWellDepthToInterval(int wellId, int intervalSeconds, int workBeginSeconds) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, @@ -107,9 +107,9 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperationsSummary(wellId, begin, end); @@ -133,9 +133,9 @@ namespace AsbCloudWebApi.Controllers public IActionResult GetOperationsToInterval(int wellId, int intervalSeconds, int workBeginSeconds) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null || !wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (idCompany is null || !wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var analytics = analyticsService.GetOperationsToInterval(wellId, intervalSeconds, workBeginSeconds); diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index b9b10427..5d798772 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -1,7 +1,5 @@ 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; @@ -35,12 +33,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetClusters() { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - var result = clusterService.GetClusters((int)idCustomer); + var result = clusterService.GetClusters((int)idCompany); return Ok(result); } @@ -53,12 +51,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetWells(int clusterId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - var result = clusterService.GetWells((int)idCustomer, clusterId); + var result = clusterService.GetWells((int)idCompany, clusterId); return Ok(result); } @@ -71,12 +69,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetAnalysis(int clusterId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - var result = clusterService.GetStat((int)idCustomer, clusterId); + var result = clusterService.GetStat((int)idCompany, clusterId); return Ok(result); } } diff --git a/AsbCloudWebApi/Controllers/DataController.cs b/AsbCloudWebApi/Controllers/DataController.cs index 63df6e8c..6ffe0071 100644 --- a/AsbCloudWebApi/Controllers/DataController.cs +++ b/AsbCloudWebApi/Controllers/DataController.cs @@ -54,14 +54,14 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetDataDatesRange(int wellId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); + bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId); - if (!isCustomerOwnsWell) + if (!isCompanyOwnsWell) return Forbid(); DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(wellId); diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index 1a8bef23..fb5f9708 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -33,12 +33,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetDeposits() { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - var result = clusterService.GetDeposits((int)idCustomer); + var result = clusterService.GetDeposits((int)idCompany); return Ok(result); } @@ -51,12 +51,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetClusters(int depositId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - var result = clusterService.GetClusters((int)idCustomer, depositId); + var result = clusterService.GetClusters((int)idCompany, depositId); return Ok(result); } diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index fbce313f..f016272e 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -53,14 +53,14 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetMessagesDateRange(int wellId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); + bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId); - if (!isCustomerOwnsWell) + if (!isCompanyOwnsWell) return Forbid(); DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId); diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index 846b3281..251829b6 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -61,12 +61,12 @@ namespace AsbCloudWebApi.Controllers public IActionResult CreateReport(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (!wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync); @@ -87,12 +87,12 @@ namespace AsbCloudWebApi.Controllers { try { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (!wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); // TODO: словарь content typoв var relativePath = Path.Combine(reportService.RootPath, $"{wellId}", reportName); @@ -142,12 +142,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetReportSize(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (!wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); int reportSize = reportService.GetReportPagesCount(wellId, begin, end, stepSeconds, format); @@ -165,12 +165,12 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetReportsDateRange(int wellId) { - int? idCustomer = User.GetCustomerId(); + int? idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) return Forbid(); - if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) + if (!wellService.CheckWellOwnership((int)idCompany, wellId)) return Forbid(); DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(wellId); diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index 1e16a167..5401f2e5 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -23,14 +23,14 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetWells() { - var idCustomer = User.GetCustomerId(); + var idCompany = User.GetCompanyId(); - if (idCustomer is null) + if (idCompany is null) { return NoContent(); } - var wells = wellService.GetWellsByCustomer((int)idCustomer); + var wells = wellService.GetWellsByCompany((int)idCompany); if (wells is null || !wells.Any()) return NoContent(); @@ -42,14 +42,14 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] public IActionResult GetTransmittingWells() { - var idCustomer = User.GetCustomerId(); + var idCompany = User.GetCompanyId(); - if(idCustomer is null) + if(idCompany is null) { return NoContent(); } - var transmittingWells = wellService.GetTransmittingWells((int)idCustomer); + var transmittingWells = wellService.GetTransmittingWells((int)idCompany); if (transmittingWells is null || !transmittingWells.Any()) return NoContent(); diff --git a/AsbCloudWebApi/Extensions.cs b/AsbCloudWebApi/Extensions.cs index e0f9224e..ffcebc3c 100644 --- a/AsbCloudWebApi/Extensions.cs +++ b/AsbCloudWebApi/Extensions.cs @@ -5,13 +5,13 @@ namespace AsbCloudWebApi { public static class Extensions { - public static int? GetCustomerId(this ClaimsPrincipal user) + public static int? GetCompanyId(this ClaimsPrincipal user) { - var claimIdCustomer = user.FindFirst(nameof(User.IdCompany)); - if (claimIdCustomer is null) + var claimIdCompany = user.FindFirst(nameof(User.IdCompany)); + if (claimIdCompany is null) return null; - return int.TryParse(claimIdCustomer.Value, out int uid) + return int.TryParse(claimIdCompany.Value, out int uid) ? uid : null; }