Customer to company. Db model opt.

This commit is contained in:
Фролов 2021-07-21 15:22:58 +05:00
commit d0378e4f1d
35 changed files with 256 additions and 222 deletions

View File

@ -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<WellSectionDto> Sections { get; set; }
public IEnumerable<ContractorDto> Contractors { get; set; }
}
}

View File

@ -11,8 +11,8 @@ namespace AsbCloudApp.Data
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public double Latitude { get; set; } public double? Latitude { get; set; }
public double Longitude { get; set; } public double? Longitude { get; set; }
//public IEnumerable<WellDto> Wells { get; set; } //public IEnumerable<WellDto> Wells { get; set; }
} }

View File

@ -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; }
}
}

View File

@ -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; }
}
}

View File

@ -5,8 +5,8 @@
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public double Latitude { get; set; } public double? Latitude { get; set; }
public double Longitude { get; set; } public double? Longitude { get; set; }
//public IEnumerable<ClusterDto> Clusters { get; set; } //public IEnumerable<ClusterDto> Clusters { get; set; }
} }

View File

@ -8,8 +8,7 @@ namespace AsbCloudApp.Data
{ {
public interface IMapPoint public interface IMapPoint
{ {
double Latitude { get; set; } double? Latitude { get; set; }
double? Longitude { get; set; }
double Longitude { get; set; }
} }
} }

View File

@ -3,7 +3,7 @@
public class UserTokenDto : UserBaseDto public class UserTokenDto : UserBaseDto
{ {
public int Id { get; set; } public int Id { get; set; }
public string CustomerName { get; set; } public string CompanyName { get; set; }
public string RoleName { get; set; } public string RoleName { get; set; }
public string Token { get; set; } public string Token { get; set; }
} }

View File

@ -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<WellSectionDto> Sections { get; set; }
public IEnumerable<CompanyDto> Companies { get; set; }
}
}

View File

@ -5,9 +5,8 @@
{ {
public int Id { get; set; } public int Id { get; set; }
public object LastData { get; set; }//DataSaubBaseDto public object LastData { get; set; }//DataSaubBaseDto
public double Latitude { get; set; } public double? Latitude { get; set; }
public double Longitude { get; set; } public double? Longitude { get; set; }
public string WellType { get; set; }
public int WellType { get; set; }
} }
} }

View File

@ -1,4 +1,4 @@
namespace AsbCloudApp.Data.Analytics namespace AsbCloudApp.Data
{ {
public class WellSectionDto public class WellSectionDto
{ {

View File

@ -1,5 +1,4 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.Analytics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -10,10 +9,10 @@ namespace AsbCloudApp.Services
{ {
public interface IClusterService public interface IClusterService
{ {
IEnumerable<DepositDto> GetDeposits(int idCustomer); IEnumerable<DepositDto> GetDeposits(int idCompany);
IEnumerable<ClusterDto> GetClusters(int idCustomer, int depositId); IEnumerable<ClusterDto> GetClusters(int idCompany, int depositId);
IEnumerable<ClusterDto> GetClusters(int idCustomer); IEnumerable<ClusterDto> GetClusters(int idCompany);
IEnumerable<WellDto> GetWells(int idCustomer, int clusterId); IEnumerable<WellDto> GetWells(int idCompany, int clusterId);
IEnumerable<WellDrillingStatDto> GetStat(int idCustomer, int clusterId); IEnumerable<WellDrillingStatDto> GetStat(int idCompany, int clusterId);
} }
} }

View File

@ -6,8 +6,8 @@ namespace AsbCloudApp.Services
{ {
public interface IWellService public interface IWellService
{ {
IEnumerable<WellDto> GetWellsByCustomer(int idCustomer); IEnumerable<WellDto> GetWellsByCompany(int idCompany);
IEnumerable<WellDto> GetTransmittingWells(int idCustomer); IEnumerable<WellDto> GetTransmittingWells(int idCompany);
bool CheckWellOwnership(int idCustomer, int wellId); bool CheckWellOwnership(int idCompany, int wellId);
} }
} }

View File

@ -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; }
}
}

View File

@ -1,5 +1,4 @@
using AsbCloudDb.Model.Analytics; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -29,7 +28,7 @@ namespace AsbCloudDb.Model
public virtual DbSet<Operation> Operations { get; set; } public virtual DbSet<Operation> Operations { get; set; }
public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; } public virtual DbSet<TelemetryAnalysis> TelemetryAnalysis { get; set; }
public virtual DbSet<WellSection> SectionAnalysis { get; set; } public virtual DbSet<WellSection> SectionAnalysis { get; set; }
public virtual DbSet<WellDrillingStat> WellDrillingStats { get; set; } public virtual DbSet<WellType> WellTypes { get; set; }
//public AsbCloudDbContext(string connectionString = "Host=localhost;Database=postgres;Username=postgres;Password=q;Persist Security Info=True") //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) entity.HasOne(d => d.Company)
.WithMany(p => p.Users) .WithMany(p => p.Users)
.HasForeignKey(d => d.IdCompany) .HasForeignKey(d => d.IdCompany)
.HasConstraintName("t_user_t_customer_id_fk"); .HasConstraintName("t_user_t_company_id_fk");
entity.HasIndex(d => d.Login) entity.HasIndex(d => d.Login)
.IsUnique(); .IsUnique();

View File

@ -34,9 +34,9 @@ namespace AsbCloudDb.Model
public virtual ICollection<Well> Wells { get; set; } public virtual ICollection<Well> Wells { get; set; }
[Column("latitude")] [Column("latitude")]
public double Latitude { get; set; } public double? Latitude { get; set; }
[Column("longitude")] [Column("longitude")]
public double Longitude { get; set; } public double? Longitude { get; set; }
} }
} }

View File

@ -27,9 +27,9 @@ namespace AsbCloudDb.Model
public virtual ICollection<Cluster> Clusters { get; set; } public virtual ICollection<Cluster> Clusters { get; set; }
[Column("latitude")] [Column("latitude")]
public double Latitude { get; set; } public double? Latitude { get; set; }
[Column("longitude")] [Column("longitude")]
public double Longitude { get; set; } public double? Longitude { get; set; }
} }
} }

View File

@ -28,7 +28,7 @@ namespace AsbCloudDb.Model
int SaveChanges(bool acceptAllChangesOnSuccess); int SaveChanges(bool acceptAllChangesOnSuccess);
Task<int> SaveChangesAsync(CancellationToken cancellationToken); Task<int> SaveChangesAsync(CancellationToken cancellationToken);
IQueryable<Well> GetWellsForCompany(int idCustomer); IQueryable<Well> GetWellsForCompany(int idCompany);
IQueryable<User> GetUsersByLogin(string login); IQueryable<User> GetUsersByLogin(string login);
(DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate; (DateTime From, DateTime To) GetDatesRange<T>(int idTelemetry) where T : class, IIdTelemetryDate;
IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId, IEnumerable<(double? MinDepth, double? MaxDepth, DateTime BeginPeriodDate)> GetDepthToInterval(int telemetryId,

View File

@ -8,8 +8,8 @@ namespace AsbCloudDb.Model
{ {
public interface IMapPoint public interface IMapPoint
{ {
double Latitude { get; set; } double? Latitude { get; set; }
double Longitude { get; set; } double? Longitude { get; set; }
} }
} }

View File

@ -1,4 +1,4 @@
namespace AsbCloudDb.Model.Analytics namespace AsbCloudDb.Model
{ {
public enum SectionType public enum SectionType
{ {

View File

@ -1,5 +1,5 @@
using AsbCloudDb.Model.Analytics; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations.Schema;
@ -25,6 +25,53 @@ namespace AsbCloudDb.Model
[Column("id_telemetry")] [Column("id_telemetry")]
public int? IdTelemetry { get; set; } 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<WellSection> Sections { get; set; }
[InverseProperty(nameof(Company.Wells))]
public virtual ICollection<Company> Companies { get; set; }
[ForeignKey(nameof(IdCluster))] [ForeignKey(nameof(IdCluster))]
[InverseProperty(nameof(Model.Cluster.Wells))] [InverseProperty(nameof(Model.Cluster.Wells))]
public virtual Cluster Cluster { get; set; } public virtual Cluster Cluster { get; set; }
@ -32,20 +79,5 @@ namespace AsbCloudDb.Model
[ForeignKey(nameof(IdTelemetry))] [ForeignKey(nameof(IdTelemetry))]
[InverseProperty(nameof(Model.Telemetry.Well))] [InverseProperty(nameof(Model.Telemetry.Well))]
public virtual Telemetry Telemetry { get; set; } 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<WellSection> SectionAnalysis { get; set; }
[InverseProperty(nameof(Analytics.WellDrillingStat.Well))]
public virtual WellDrillingStat WellDrillingStat { get; set; }
[Column("companines"), Comment("участники (заказчик, подрядчики и субподрядчики)")]
public virtual ICollection<Company> Companies { get; set; }
} }
} }

View File

@ -5,7 +5,7 @@ using System;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
#nullable disable #nullable disable
namespace AsbCloudDb.Model.Analytics namespace AsbCloudDb.Model
{ {
[Table("t_well_section"), Comment("секция скважины")] [Table("t_well_section"), Comment("секция скважины")]
@ -65,12 +65,12 @@ namespace AsbCloudDb.Model.Analytics
[JsonIgnore] [JsonIgnore]
[ForeignKey(nameof(IdWell))] [ForeignKey(nameof(IdWell))]
[InverseProperty(nameof(Model.Well.SectionAnalysis))] [InverseProperty(nameof(Model.Well.Sections))]
public virtual Well Well { get; set; } public virtual Well Well { get; set; }
[JsonIgnore] [JsonIgnore]
[ForeignKey(nameof(IdWellSectionType))] [ForeignKey(nameof(IdWellSectionType))]
[InverseProperty(nameof(Analytics.WellSectionType.WellSections))] [InverseProperty(nameof(Model.WellSectionType.WellSections))]
public virtual WellSectionType WellSectionType { get; set; } public virtual WellSectionType WellSectionType { get; set; }
} }
} }

View File

@ -6,9 +6,8 @@ using System.Text.Json.Serialization;
using System.Collections.Generic; using System.Collections.Generic;
#nullable disable #nullable disable
namespace AsbCloudDb.Model.Analytics namespace AsbCloudDb.Model
{ {
[Table("t_well_section_type"), Comment("конструкция секции скважины")] [Table("t_well_section_type"), Comment("конструкция секции скважины")]
public class WellSectionType public class WellSectionType
{ {
@ -21,7 +20,7 @@ namespace AsbCloudDb.Model.Analytics
public string Caption { get; set; } public string Caption { get; set; }
[JsonIgnore] [JsonIgnore]
[InverseProperty(nameof(Analytics.WellSection.WellSectionType))] [InverseProperty(nameof(WellSection.WellSectionType))]
public virtual ICollection<WellSection> WellSections { get; set; } public virtual ICollection<WellSection> WellSections { get; set; }
} }
} }

View File

@ -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<Well> Wells { get; set; }
}
}

View File

@ -45,7 +45,7 @@ namespace AsbCloudInfrastructure.Services
{ {
Id = identity.User.Id, Id = identity.User.Id,
Name = identity.User.Name, Name = identity.User.Name,
CustomerName = identity.User.Company.Caption, CompanyName = identity.User.Company.Caption,
Level = identity.User.Level, Level = identity.User.Level,
Login = identity.User.Login, Login = identity.User.Login,
Patronymic = identity.User.Patronymic, Patronymic = identity.User.Patronymic,
@ -68,15 +68,6 @@ namespace AsbCloudInfrastructure.Services
if (userDto.Password.Length < 3) if (userDto.Password.Length < 3)
return -2; 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 salt = GenerateSalt();
var user = new User var user = new User

View File

@ -34,7 +34,7 @@ namespace AsbCloudInfrastructure.Services
return wells.Select(w => From(w)); return wells.Select(w => From(w));
} }
public IEnumerable<WellDto> GetWellsByCustomer(int idCompany) public IEnumerable<WellDto> GetWellsByCompany(int idCompany)
{ {
var wells = db.GetWellsForCompany(idCompany).ToList(); var wells = db.GetWellsForCompany(idCompany).ToList();
return wells.Select(w => From(w)); return wells.Select(w => From(w));

View File

@ -1,8 +1,6 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.Analytics;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model; using AsbCloudDb.Model;
using AsbCloudDb.Model.Analytics;
using AsbCloudInfrastructure.Services.Cache; using AsbCloudInfrastructure.Services.Cache;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
@ -77,10 +75,10 @@ namespace AsbCloudInfrastructure.Services
return dtos; return dtos;
} }
public IEnumerable<WellDto> GetWells(int idCompany, int clusterId) public IEnumerable<WellDto> GetWells(int idCompany, int idCluster)
{ {
var entities = db.GetWellsForCompany(idCompany) var entities = db.GetWellsForCompany(idCompany)
.Where(e => e.IdCluster == clusterId) .Where(e => e.IdCluster == idCluster)
.ToList(); .ToList();
var dtos = entities.Select(e => new WellDto var dtos = entities.Select(e => new WellDto
@ -96,9 +94,60 @@ namespace AsbCloudInfrastructure.Services
return dtos; return dtos;
} }
public IEnumerable<WellDrillingStatDto> GetStat(int idCompany, int clusterId) public IEnumerable<WellDrillingStatDto> 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;
} }
} }
} }

View File

@ -42,7 +42,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{ {
new Claim("idCustomer", "1"), new Claim("idCompany", "1"),
}, "mock")); }, "mock"));
controller.ControllerContext = new ControllerContext() controller.ControllerContext = new ControllerContext()
@ -71,7 +71,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
} }
[Fact] [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, var emptyUserController = new AnalyticsController(analyticsService.Object,
wellService.Object); wellService.Object);
@ -102,7 +102,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{ {
new Claim("idCustomer", "1"), new Claim("idCompany", "1"),
}, "mock")); }, "mock"));
newControllerInstance.ControllerContext = new ControllerContext() newControllerInstance.ControllerContext = new ControllerContext()
@ -129,7 +129,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{ {
new Claim("idCustomer", "1"), new Claim("idCompany", "1"),
}, "mock")); }, "mock"));
newControllerInstance.ControllerContext = new ControllerContext() newControllerInstance.ControllerContext = new ControllerContext()
@ -156,7 +156,7 @@ namespace AsbCloudWebApi.Tests.ControllersTests
var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[] var user = new ClaimsPrincipal(new ClaimsIdentity(new Claim[]
{ {
new Claim("idCustomer", "1"), new Claim("idCompany", "1"),
}, "mock")); }, "mock"));
newControllerInstance.ControllerContext = new ControllerContext() newControllerInstance.ControllerContext = new ControllerContext()

View File

@ -32,9 +32,9 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<OperationDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperations(int wellId) 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(); return Forbid();
var analytics = analyticsService.GetOperations(wellId); var analytics = analyticsService.GetOperations(wellId);
@ -55,9 +55,9 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDepthToDayDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWellDepthToDay(int wellId) 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(); return Forbid();
var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId); var wellDepthToDayData = analyticsService.GetWellDepthToDay(wellId);
@ -81,9 +81,9 @@ namespace AsbCloudWebApi.Controllers
public IActionResult GetWellDepthToInterval(int wellId, public IActionResult GetWellDepthToInterval(int wellId,
int intervalSeconds, int workBeginSeconds) 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(); return Forbid();
var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId, var wellDepthToIntervalData = analyticsService.GetWellDepthToInterval(wellId,
@ -107,9 +107,9 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<OperationDurationDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetOperationsSummary(int wellId, DateTime begin = default, DateTime end = default) 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(); return Forbid();
var analytics = analyticsService.GetOperationsSummary(wellId, begin, end); var analytics = analyticsService.GetOperationsSummary(wellId, begin, end);
@ -133,9 +133,9 @@ namespace AsbCloudWebApi.Controllers
public IActionResult GetOperationsToInterval(int wellId, public IActionResult GetOperationsToInterval(int wellId,
int intervalSeconds, int workBeginSeconds) 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(); return Forbid();
var analytics = analyticsService.GetOperationsToInterval(wellId, intervalSeconds, workBeginSeconds); var analytics = analyticsService.GetOperationsToInterval(wellId, intervalSeconds, workBeginSeconds);

View File

@ -1,7 +1,5 @@
using AsbCloudApp.Data; using AsbCloudApp.Data;
using AsbCloudApp.Data.Analytics;
using AsbCloudApp.Services; using AsbCloudApp.Services;
using AsbCloudDb.Model.Analytics;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@ -35,12 +33,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetClusters() public IActionResult GetClusters()
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
var result = clusterService.GetClusters((int)idCustomer); var result = clusterService.GetClusters((int)idCompany);
return Ok(result); return Ok(result);
} }
@ -53,12 +51,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWells(int clusterId) public IActionResult GetWells(int clusterId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
var result = clusterService.GetWells((int)idCustomer, clusterId); var result = clusterService.GetWells((int)idCompany, clusterId);
return Ok(result); return Ok(result);
} }
@ -71,12 +69,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellDrillingStatDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDrillingStatDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetAnalysis(int clusterId) public IActionResult GetAnalysis(int clusterId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
var result = clusterService.GetStat((int)idCustomer, clusterId); var result = clusterService.GetStat((int)idCompany, clusterId);
return Ok(result); return Ok(result);
} }
} }

View File

@ -54,14 +54,14 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetDataDatesRange(int wellId) public IActionResult GetDataDatesRange(int wellId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId);
if (!isCustomerOwnsWell) if (!isCompanyOwnsWell)
return Forbid(); return Forbid();
DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(wellId); DatesRangeDto dataDatesRange = telemetryDataService.GetDataDatesRange(wellId);

View File

@ -33,12 +33,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<DepositDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetDeposits() public IActionResult GetDeposits()
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
var result = clusterService.GetDeposits((int)idCustomer); var result = clusterService.GetDeposits((int)idCompany);
return Ok(result); return Ok(result);
} }
@ -51,12 +51,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<ClusterDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetClusters(int depositId) public IActionResult GetClusters(int depositId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
var result = clusterService.GetClusters((int)idCustomer, depositId); var result = clusterService.GetClusters((int)idCompany, depositId);
return Ok(result); return Ok(result);
} }

View File

@ -53,14 +53,14 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessagesDateRange(int wellId) public IActionResult GetMessagesDateRange(int wellId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
bool isCustomerOwnsWell = wellService.CheckWellOwnership((int)idCustomer, wellId); bool isCompanyOwnsWell = wellService.CheckWellOwnership((int)idCompany, wellId);
if (!isCustomerOwnsWell) if (!isCompanyOwnsWell)
return Forbid(); return Forbid();
DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId); DatesRangeDto wellMessagesDatesRange = messageService.GetMessagesDatesRange(wellId);

View File

@ -61,12 +61,12 @@ namespace AsbCloudWebApi.Controllers
public IActionResult CreateReport(int wellId, int stepSeconds, int format, public IActionResult CreateReport(int wellId, int stepSeconds, int format,
DateTime begin = default, DateTime end = default) DateTime begin = default, DateTime end = default)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid(); return Forbid();
var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync); var id = reportService.CreateReport(wellId, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync);
@ -87,12 +87,12 @@ namespace AsbCloudWebApi.Controllers
{ {
try try
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid(); return Forbid();
// TODO: словарь content typoв // TODO: словарь content typoв
var relativePath = Path.Combine(reportService.RootPath, $"{wellId}", reportName); var relativePath = Path.Combine(reportService.RootPath, $"{wellId}", reportName);
@ -142,12 +142,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetReportSize(int wellId, int stepSeconds, int format, DateTime begin = default, DateTime end = default) 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(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid(); return Forbid();
int reportSize = reportService.GetReportPagesCount(wellId, begin, end, stepSeconds, format); int reportSize = reportService.GetReportPagesCount(wellId, begin, end, stepSeconds, format);
@ -165,12 +165,12 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetReportsDateRange(int wellId) public IActionResult GetReportsDateRange(int wellId)
{ {
int? idCustomer = User.GetCustomerId(); int? idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
return Forbid(); return Forbid();
if (!wellService.CheckWellOwnership((int)idCustomer, wellId)) if (!wellService.CheckWellOwnership((int)idCompany, wellId))
return Forbid(); return Forbid();
DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(wellId); DatesRangeDto wellReportsDatesRange = reportService.GetReportsDatesRange(wellId);

View File

@ -23,14 +23,14 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetWells() public IActionResult GetWells()
{ {
var idCustomer = User.GetCustomerId(); var idCompany = User.GetCompanyId();
if (idCustomer is null) if (idCompany is null)
{ {
return NoContent(); return NoContent();
} }
var wells = wellService.GetWellsByCustomer((int)idCustomer); var wells = wellService.GetWellsByCompany((int)idCompany);
if (wells is null || !wells.Any()) if (wells is null || !wells.Any())
return NoContent(); return NoContent();
@ -42,14 +42,14 @@ namespace AsbCloudWebApi.Controllers
[ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)] [ProducesResponseType(typeof(IEnumerable<WellDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetTransmittingWells() public IActionResult GetTransmittingWells()
{ {
var idCustomer = User.GetCustomerId(); var idCompany = User.GetCompanyId();
if(idCustomer is null) if(idCompany is null)
{ {
return NoContent(); return NoContent();
} }
var transmittingWells = wellService.GetTransmittingWells((int)idCustomer); var transmittingWells = wellService.GetTransmittingWells((int)idCompany);
if (transmittingWells is null || !transmittingWells.Any()) if (transmittingWells is null || !transmittingWells.Any())
return NoContent(); return NoContent();

View File

@ -5,13 +5,13 @@ namespace AsbCloudWebApi
{ {
public static class Extensions 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)); var claimIdCompany = user.FindFirst(nameof(User.IdCompany));
if (claimIdCustomer is null) if (claimIdCompany is null)
return null; return null;
return int.TryParse(claimIdCustomer.Value, out int uid) return int.TryParse(claimIdCompany.Value, out int uid)
? uid ? uid
: null; : null;
} }