From 99d242101e0e81946434143ab196e06f3dc1487c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Tue, 24 Aug 2021 10:59:10 +0500 Subject: [PATCH] remove efModel wellSection. Cleanup. Split categories lastData and files --- AsbCloudApp/Services/IWellSectionService.cs | 3 +- AsbCloudDb/Model/AsbCloudDbContext.cs | 7 - AsbCloudDb/Model/IAsbCloudDbContext.cs | 1 - AsbCloudDb/Model/LastData.cs | 2 +- AsbCloudDb/Model/LastDataCategory.cs | 20 ++ AsbCloudDb/Model/Well.cs | 30 -- AsbCloudDb/Model/WellSection.cs | 75 ----- AsbCloudDb/Model/WellSectionType.cs | 4 - AsbCloudInfrastructure/DependencyInjection.cs | 2 +- AsbCloudInfrastructure/Helper.cs | 55 ++++ .../Services/AuthService.cs | 4 +- .../Services/Cache/CacheTable.cs | 10 +- .../Services/ClusterService.cs | 38 +-- .../Services/DataService.cs | 14 +- .../Services/FileService.cs | 13 +- .../Services/LastDataService.cs | 6 +- .../Services/ReportService.cs | 22 +- .../Services/TelemetryAnalyticsService.cs | 46 +-- .../Services/TelemetryService.cs | 4 +- .../Services/WellOperationService.cs | 22 +- .../Services/WellOperationsStatService.cs | 276 ++++++++++++++++++ .../Services/WellSectionService.cs | 56 +--- .../Services/WellService.cs | 4 +- AsbCloudWebApi/Controllers/AuthController.cs | 4 +- .../Controllers/ClusterController.cs | 6 +- AsbCloudWebApi/Controllers/CrudController.cs | 2 +- AsbCloudWebApi/Controllers/DataController.cs | 6 +- .../Controllers/DepositController.cs | 4 +- AsbCloudWebApi/Controllers/FileController.cs | 10 +- .../Controllers/LastDataController.cs | 16 +- .../Controllers/MessageController.cs | 12 +- .../Controllers/ReportController.cs | 28 +- .../TelemetryAnalyticsController.cs | 28 +- AsbCloudWebApi/Controllers/WellController.cs | 10 +- .../Controllers/WellOperationController.cs | 20 +- .../Controllers/WellSectionController.cs | 19 +- 36 files changed, 518 insertions(+), 361 deletions(-) create mode 100644 AsbCloudDb/Model/LastDataCategory.cs delete mode 100644 AsbCloudDb/Model/WellSection.cs create mode 100644 AsbCloudInfrastructure/Helper.cs create mode 100644 AsbCloudInfrastructure/Services/WellOperationsStatService.cs diff --git a/AsbCloudApp/Services/IWellSectionService.cs b/AsbCloudApp/Services/IWellSectionService.cs index 46a6b949..33efd931 100644 --- a/AsbCloudApp/Services/IWellSectionService.cs +++ b/AsbCloudApp/Services/IWellSectionService.cs @@ -9,7 +9,6 @@ namespace AsbCloudApp.Services { Task> GetSectionsByWellIdAsync(int idWell, CancellationToken token = default); - Task GetSectionByWellIdAsync(int id, - CancellationToken token = default); + } } diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 7a2a15ba..f18ad85d 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -29,7 +29,6 @@ namespace AsbCloudDb.Model public virtual DbSet TelemetryUsers { get; set; } public virtual DbSet TelemetryOperations { get; set; } public virtual DbSet TelemetryAnalysis { get; set; } - public virtual DbSet WellSections { get; set; } public virtual DbSet WellSectionTypes { get; set; } public virtual DbSet WellOperations { get; set; } public virtual DbSet WellTypes { get; set; } @@ -141,12 +140,6 @@ namespace AsbCloudDb.Model .HasConstraintName("t_well_t_telemetry_id_fk"); }); - modelBuilder.Entity(entity => - { - entity.HasIndex(e => e.WellDepthPlan) - .HasDatabaseName("IX_t_well_section_well_depth_plan"); - }); - modelBuilder.Entity(entity => { diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 0d3b2f45..66025b0b 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -25,7 +25,6 @@ namespace AsbCloudDb.Model DbSet TelemetryOperations { get; set; } DbSet TelemetryAnalysis { get; set; } DbSet Wells { get; set; } - DbSet WellSections { get; set; } DbSet WellSectionTypes { get; set; } DbSet WellOperations { get; set; } DbSet WellTypes { get; set; } diff --git a/AsbCloudDb/Model/LastData.cs b/AsbCloudDb/Model/LastData.cs index c9679c78..b045df89 100644 --- a/AsbCloudDb/Model/LastData.cs +++ b/AsbCloudDb/Model/LastData.cs @@ -27,6 +27,6 @@ namespace AsbCloudDb.Model [JsonIgnore] [ForeignKey(nameof(IdCategory))] - public virtual FileCategory FileCategory { get; set; } + public virtual LastDataCategory LastDataCategory { get; set; } } } diff --git a/AsbCloudDb/Model/LastDataCategory.cs b/AsbCloudDb/Model/LastDataCategory.cs new file mode 100644 index 00000000..d0b75682 --- /dev/null +++ b/AsbCloudDb/Model/LastDataCategory.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AsbCloudDb.Model +{ + [Table("t_last_data_category"), Comment("Категория последних данных")] + public class LastDataCategory : IId + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("name"), Comment("Название категории")] + public string Name { get; set; } + + [Column("short_name"), Comment("Короткое название категории")] + public string ShortName { get; set; } + } +} \ No newline at end of file diff --git a/AsbCloudDb/Model/Well.cs b/AsbCloudDb/Model/Well.cs index 9fb0651d..bdadc398 100644 --- a/AsbCloudDb/Model/Well.cs +++ b/AsbCloudDb/Model/Well.cs @@ -35,40 +35,10 @@ namespace AsbCloudDb.Model [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(RelationCompanyWell.Well))] public virtual ICollection RelationCompaniesWells { get; set; } diff --git a/AsbCloudDb/Model/WellSection.cs b/AsbCloudDb/Model/WellSection.cs deleted file mode 100644 index a38b74e7..00000000 --- a/AsbCloudDb/Model/WellSection.cs +++ /dev/null @@ -1,75 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using System.Text.Json.Serialization; -#nullable disable - -namespace AsbCloudDb.Model -{ - - [Table("t_well_section"), Comment("секция скважины")] - public class WellSection: IId, IIdWell - { - [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.Sections))] - public virtual Well Well { get; set; } - - [JsonIgnore] - [ForeignKey(nameof(IdWellSectionType))] - [InverseProperty(nameof(Model.WellSectionType.WellSections))] - public virtual WellSectionType WellSectionType { get; set; } - } -} diff --git a/AsbCloudDb/Model/WellSectionType.cs b/AsbCloudDb/Model/WellSectionType.cs index 6c6b930d..708994db 100644 --- a/AsbCloudDb/Model/WellSectionType.cs +++ b/AsbCloudDb/Model/WellSectionType.cs @@ -18,10 +18,6 @@ namespace AsbCloudDb.Model [StringLength(255)] public string Caption { get; set; } - [JsonIgnore] - [InverseProperty(nameof(WellSection.WellSectionType))] - public virtual ICollection WellSections { get; set; } - [JsonIgnore] [InverseProperty(nameof(WellOperation.WellSectionType))] public virtual ICollection WellOperations { get; set; } diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs index 2289e979..9a1d7e97 100644 --- a/AsbCloudInfrastructure/DependencyInjection.cs +++ b/AsbCloudInfrastructure/DependencyInjection.cs @@ -42,7 +42,7 @@ namespace AsbCloudInfrastructure services.AddTransient, LastDataService>(); services.AddTransient, LastDataService>(); services.AddTransient, LastDataService>(); - + return services; } } diff --git a/AsbCloudInfrastructure/Helper.cs b/AsbCloudInfrastructure/Helper.cs new file mode 100644 index 00000000..d5d11b8d --- /dev/null +++ b/AsbCloudInfrastructure/Helper.cs @@ -0,0 +1,55 @@ +using System; + +namespace AsbCloudInfrastructure +{ + public static class Helper + { + public static T Max(params T[] items) + where T : IComparable + { + var count = items.Length; + if (count < 1) + throw new ArgumentException("Count of params must be greater than 1"); + + var max = items[0]; + for (var i = 1; i < count; i++) + if (max.CompareTo(items[i]) > 0) + max = items[i]; + + return max; + } + + public static T Min(params T[] items) + where T : IComparable + { + var count = items.Length; + if (count < 1) + throw new ArgumentException("Count of params must be greater than 1"); + + var min = items[0]; + for (var i = 1; i < count; i++) + if (min.CompareTo(items[i]) < 0) + min = items[i]; + + return min; + } + + public static (T min, T max) MinMax(params T[] items) + where T : IComparable + { + var count = items.Length; + if (count < 1) + throw new ArgumentException("Count of params must be greater than 1"); + + var min = items[0]; + var max = items[0]; + for (var i = 1; i < count; i++) + if (max.CompareTo(items[i]) > 0) + max = items[i]; + else if (min.CompareTo(items[i]) < 0) + min = items[i]; + + return (min, max); + } + } +} diff --git a/AsbCloudInfrastructure/Services/AuthService.cs b/AsbCloudInfrastructure/Services/AuthService.cs index d54c3f2e..7215b15d 100644 --- a/AsbCloudInfrastructure/Services/AuthService.cs +++ b/AsbCloudInfrastructure/Services/AuthService.cs @@ -1,6 +1,7 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using System; using System.Collections.Generic; @@ -9,7 +10,6 @@ using System.Linq; using System.Security.Claims; using System.Security.Cryptography; using System.Text; -using Microsoft.EntityFrameworkCore; using System.Threading; using System.Threading.Tasks; @@ -141,7 +141,7 @@ namespace AsbCloudInfrastructure.Services return new JwtSecurityTokenHandler().WriteToken(jwt); } - private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login, + private async Task<(ClaimsIdentity Identity, User User)> GetClaimsUserAsync(string login, string password, CancellationToken token = default) { var user = await db diff --git a/AsbCloudInfrastructure/Services/Cache/CacheTable.cs b/AsbCloudInfrastructure/Services/Cache/CacheTable.cs index 445fb8cc..905ff2c1 100644 --- a/AsbCloudInfrastructure/Services/Cache/CacheTable.cs +++ b/AsbCloudInfrastructure/Services/Cache/CacheTable.cs @@ -43,7 +43,7 @@ namespace AsbCloudInfrastructure.Services.Cache if (cached.Any()) { await semaphore.WaitAsync(token).ConfigureAwait(true); - cached.Clear(); + cached.Clear(); } var dbEntities = await context.Set().AsNoTracking().ToListAsync(token).ConfigureAwait(false); cached.AddRange(dbEntities); @@ -167,12 +167,12 @@ namespace AsbCloudInfrastructure.Services.Cache return result; } - public async Task> WhereAsync(Func predicate = default, + public async Task> WhereAsync(Func predicate = default, RefreshMode refreshMode = RefreshMode.IfResultEmpty, CancellationToken token = default) { - bool isUpdated = await CheckRefreshAsync(refreshMode, token); - var result = (predicate != default) - ? cached.Where(predicate) + bool isUpdated = await CheckRefreshAsync(refreshMode, token); + var result = (predicate != default) + ? cached.Where(predicate) : cached; if (!result.Any() && refreshMode == RefreshMode.IfResultEmpty && !isUpdated) { diff --git a/AsbCloudInfrastructure/Services/ClusterService.cs b/AsbCloudInfrastructure/Services/ClusterService.cs index e398becb..b2e16cdb 100644 --- a/AsbCloudInfrastructure/Services/ClusterService.cs +++ b/AsbCloudInfrastructure/Services/ClusterService.cs @@ -26,8 +26,8 @@ namespace AsbCloudInfrastructure.Services .Include(w => w.WellType) .Include(w => w.Cluster) .ThenInclude(c => c.Deposit) - where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) - select well).ToListAsync(token) + where well.RelationCompaniesWells.Any(r => r.IdCompany == idCompany) + select well).ToListAsync(token) .ConfigureAwait(false); var gDepositEntities = wellEntities @@ -85,7 +85,7 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public async Task> GetClustersAsync(int idCompany, + public async Task> GetClustersAsync(int idCompany, int depositId, CancellationToken token = default) { var entities = await db.GetWellsForCompany(idCompany) @@ -107,7 +107,7 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public async Task> GetWellsAsync(int idCompany, + public async Task> GetWellsAsync(int idCompany, int idCluster, CancellationToken token = default) { var entities = await db.GetWellsForCompany(idCompany) @@ -129,7 +129,7 @@ namespace AsbCloudInfrastructure.Services return dtos; } - public async Task GetStatAsync(int idCompany, + public async Task GetStatAsync(int idCompany, int idCluster, CancellationToken token = default) { var wellEntities = from w in db.Wells @@ -144,33 +144,7 @@ namespace AsbCloudInfrastructure.Services Deposit = e.Cluster.Deposit.Caption, Latitude = e.Latitude, Longitude = e.Longitude, - FactEnd = e.FactEnd, - FactStart = e.FactStart, - 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, - DurationFact = s.BuildDaysFact, - DurationPlan = s.BuildDaysPlan, - CasingDownSpeedFact = s.CasingDownSpeedFact, - CasingDownSpeedPlan = s.CasingDownSpeedPlan, - MechSpeedFact = s.RateOfPenetrationFact, - MechSpeedPlan = s.RateOfPenetrationPlan, - RouteSpeedFact = s.RouteSpeedFact, - RouteSpeedPlan = s.RouteSpeedPlan, - SectionType = s.WellSectionType.Caption, - WellDepthFact = s.WellDepthFact, - WellDepthPlan = s.WellDepthPlan, - }), - UnProductiveDays = e.UnProductiveDays, + //TODO: Fill data from operations service Companies = e.RelationCompaniesWells.Select(c => new CompanyDto { Id = c.Company.Id, diff --git a/AsbCloudInfrastructure/Services/DataService.cs b/AsbCloudInfrastructure/Services/DataService.cs index 7d657144..0e5fd2f9 100644 --- a/AsbCloudInfrastructure/Services/DataService.cs +++ b/AsbCloudInfrastructure/Services/DataService.cs @@ -1,9 +1,9 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; -using Microsoft.EntityFrameworkCore; using AsbCloudInfrastructure.Services.Cache; using Mapster; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -30,8 +30,8 @@ namespace AsbCloudInfrastructure.Services cacheWells = cacheDb.GetCachedTable((AsbCloudDbContext)db); } - public async Task> GetAsync(int idWell, - DateTime dateBegin = default, double intervalSec = 600d, + public async Task> GetAsync(int idWell, + DateTime dateBegin = default, double intervalSec = 600d, int approxPointsCount = 1024, CancellationToken token = default) { var well = cacheWells.FirstOrDefault(w => w.Id == idWell); @@ -84,10 +84,10 @@ namespace AsbCloudInfrastructure.Services var dtoMaxDate = dtos.Max(d => d.Date); var oldDataSaubBase = await (from d in db.DataSaubBases - where d.IdTelemetry == telemetryId - && d.Date > dtoMinDate - && d.Date < dtoMaxDate - select d).AsNoTracking() + where d.IdTelemetry == telemetryId + && d.Date > dtoMinDate + && d.Date < dtoMaxDate + select d).AsNoTracking() .ToListAsync(token) .ConfigureAwait(false); diff --git a/AsbCloudInfrastructure/Services/FileService.cs b/AsbCloudInfrastructure/Services/FileService.cs index b5103589..74185a11 100644 --- a/AsbCloudInfrastructure/Services/FileService.cs +++ b/AsbCloudInfrastructure/Services/FileService.cs @@ -5,10 +5,10 @@ using Mapster; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using System.IO; namespace AsbCloudInfrastructure.Services { @@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services return fileIdsToNames; } - public async Task SaveFile(int idWell, int idCategory, int fileId, + public async Task SaveFile(int idWell, int idCategory, int fileId, string fileExtension, Stream fileStream) { var relativePath = Path.Combine(RootPath, $"{idWell}", @@ -62,7 +62,7 @@ namespace AsbCloudInfrastructure.Services } public async Task> GetFilesInfoAsync(int idWell, - int idCategory, IEnumerable companies = default, DateTime begin = default, + int idCategory, IEnumerable companies = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32, CancellationToken token = default) { var query = db.Files @@ -84,8 +84,9 @@ namespace AsbCloudInfrastructure.Services var count = await query.CountAsync(token).ConfigureAwait(false); - var result = new PaginationContainer(count) { - Skip = skip, + var result = new PaginationContainer(count) + { + Skip = skip, Take = take, Count = count, }; @@ -131,7 +132,7 @@ namespace AsbCloudInfrastructure.Services return dto; } - public async Task DeleteFileAsync(int idFile, + public async Task DeleteFileAsync(int idFile, CancellationToken token = default) { var fileInfo = db.Files.FirstOrDefault(f => f.Id == idFile); diff --git a/AsbCloudInfrastructure/Services/LastDataService.cs b/AsbCloudInfrastructure/Services/LastDataService.cs index 00016790..bb8f86f0 100644 --- a/AsbCloudInfrastructure/Services/LastDataService.cs +++ b/AsbCloudInfrastructure/Services/LastDataService.cs @@ -1,10 +1,10 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using Mapster; +using Microsoft.EntityFrameworkCore; using System.Text.Json; using System.Threading; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; namespace AsbCloudInfrastructure.Services { @@ -17,7 +17,7 @@ namespace AsbCloudInfrastructure.Services this.db = db; } - public async Task GetAsync(int idWell, int idCategory, + public async Task GetAsync(int idWell, int idCategory, CancellationToken token = default) { var entity = await db.LastData.AsNoTracking().FirstOrDefaultAsync(e => @@ -31,7 +31,7 @@ namespace AsbCloudInfrastructure.Services return dto; } - public async Task UpsertAsync(int idWell, int idCategory, + public async Task UpsertAsync(int idWell, int idCategory, Tdto value, CancellationToken token = default) { var model = value.Adapt(); diff --git a/AsbCloudInfrastructure/Services/ReportService.cs b/AsbCloudInfrastructure/Services/ReportService.cs index 4ec86b0d..9d86141e 100644 --- a/AsbCloudInfrastructure/Services/ReportService.cs +++ b/AsbCloudInfrastructure/Services/ReportService.cs @@ -92,10 +92,10 @@ namespace AsbCloudInfrastructure.Services return generator.GetPagesCount(); } - public async Task> GetSuitableReportsAsync(int idWell, + public async Task> GetSuitableReportsAsync(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token = default) { - var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell, + var suitableReportsFromDb = await GetSuitableReportsFromDbAsync(idWell, begin, end, stepSeconds, format, token).ConfigureAwait(false); var suitableReportsProperties = suitableReportsFromDb.Select(r => new ReportPropertiesDto @@ -145,17 +145,17 @@ namespace AsbCloudInfrastructure.Services }; } - private async Task> GetSuitableReportsFromDbAsync(int idWell, + private async Task> GetSuitableReportsFromDbAsync(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, CancellationToken token = default) { - var suitableReportsNames = await(from r in db.ReportProperties.Include(r => r.File) - where r.IdWell == idWell - && r.Begin >= begin - && r.End <= end - && r.Step <= stepSeconds - && r.Format == format - select r).OrderBy(o => o.File.UploadDate) + var suitableReportsNames = await (from r in db.ReportProperties.Include(r => r.File) + where r.IdWell == idWell + && r.Begin >= begin + && r.End <= end + && r.Step <= stepSeconds + && r.Format == format + select r).OrderBy(o => o.File.UploadDate) .AsNoTracking() .Take(512).ToListAsync(token) .ConfigureAwait(false); @@ -163,7 +163,7 @@ namespace AsbCloudInfrastructure.Services return suitableReportsNames; } - private IReportGenerator GetReportGenerator(int idWell, DateTime begin, + private IReportGenerator GetReportGenerator(int idWell, DateTime begin, DateTime end, int stepSeconds, int format, AsbCloudDbContext context) { var dataSource = new ReportDataSourcePgCloud(context, idWell); diff --git a/AsbCloudInfrastructure/Services/TelemetryAnalyticsService.cs b/AsbCloudInfrastructure/Services/TelemetryAnalyticsService.cs index 29a7363f..b761a5a0 100644 --- a/AsbCloudInfrastructure/Services/TelemetryAnalyticsService.cs +++ b/AsbCloudInfrastructure/Services/TelemetryAnalyticsService.cs @@ -165,16 +165,16 @@ namespace AsbCloudInfrastructure.Services var unixEnd = (end - new DateTime(1970, 1, 1)).TotalSeconds; return await (from a in db.TelemetryAnalysis - where a.IdTelemetry == telemetryId && - a.UnixDate > unixBegin && a.UnixDate < unixEnd - join o in db.TelemetryOperations on a.IdOperation equals o.Id - group a by new { a.IdOperation, o.Name } into g - select new TelemetryOperationDurationDto - { - OperationName = g.Key.Name, - Duration = g.Where(g => g.DurationSec > 0) - .Sum(a => a.DurationSec) - }).AsNoTracking().ToListAsync(token) + where a.IdTelemetry == telemetryId && + a.UnixDate > unixBegin && a.UnixDate < unixEnd + join o in db.TelemetryOperations on a.IdOperation equals o.Id + group a by new { a.IdOperation, o.Name } into g + select new TelemetryOperationDurationDto + { + OperationName = g.Key.Name, + Duration = g.Where(g => g.DurationSec > 0) + .Sum(a => a.DurationSec) + }).AsNoTracking().ToListAsync(token) .ConfigureAwait(false); } @@ -194,19 +194,19 @@ namespace AsbCloudInfrastructure.Services // Get'n'Group all operations only by start date and by name (if there were several operations in interval). // Without dividing these operations duration by given interval var ops = await (from a in db.TelemetryAnalysis - where a.IdTelemetry == telemetryId - join o in db.TelemetryOperations on a.IdOperation equals o.Id - group a by new - { - Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds), - o.Name - } into g - select new - { - IntervalStart = g.Min(d => d.UnixDate), - OperationName = g.Key.Name, - OperationDuration = g.Sum(an => an.DurationSec) - }).AsNoTracking() + where a.IdTelemetry == telemetryId + join o in db.TelemetryOperations on a.IdOperation equals o.Id + group a by new + { + Interval = Math.Floor((a.UnixDate - workBeginSeconds + timezoneOffset) / intervalSeconds), + o.Name + } into g + select new + { + IntervalStart = g.Min(d => d.UnixDate), + OperationName = g.Key.Name, + OperationDuration = g.Sum(an => an.DurationSec) + }).AsNoTracking() .OrderBy(op => op.IntervalStart) .ToListAsync(token) .ConfigureAwait(false); diff --git a/AsbCloudInfrastructure/Services/TelemetryService.cs b/AsbCloudInfrastructure/Services/TelemetryService.cs index a8382a90..d3d495b2 100644 --- a/AsbCloudInfrastructure/Services/TelemetryService.cs +++ b/AsbCloudInfrastructure/Services/TelemetryService.cs @@ -3,8 +3,6 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using Mapster; -using System.Threading; -using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { @@ -49,7 +47,7 @@ namespace AsbCloudInfrastructure.Services var tele = cacheTelemetry.FirstOrDefault(t => t.RemoteUid == uid, RefreshMode.IfResultEmpty); if (tele is null) return null; - + return cacheWells.FirstOrDefault(w => w?.IdTelemetry == tele.Id); } diff --git a/AsbCloudInfrastructure/Services/WellOperationService.cs b/AsbCloudInfrastructure/Services/WellOperationService.cs index 8dbabeb7..2be323fd 100644 --- a/AsbCloudInfrastructure/Services/WellOperationService.cs +++ b/AsbCloudInfrastructure/Services/WellOperationService.cs @@ -1,14 +1,14 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using Mapster; +using Microsoft.EntityFrameworkCore; using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { @@ -99,7 +99,7 @@ namespace AsbCloudInfrastructure.Services return result; } - public async Task GetAsync(int id, + public async Task GetAsync(int id, CancellationToken token = default) { var entity = await context.WellOperations @@ -117,11 +117,11 @@ namespace AsbCloudInfrastructure.Services return dto; } - public async Task InsertRangeAsync(int idWell, - IEnumerable wellOperationDtos, + public async Task InsertRangeAsync(int idWell, + IEnumerable wellOperationDtos, CancellationToken token = default) { - foreach(var operationDto in wellOperationDtos) + foreach (var operationDto in wellOperationDtos) { var entity = operationDto.Adapt(); entity.Id = default; @@ -133,7 +133,7 @@ namespace AsbCloudInfrastructure.Services .ConfigureAwait(false); } - public async Task UpdateAsync(int idWell, int idOperation, + public async Task UpdateAsync(int idWell, int idOperation, WellOperationDto item, CancellationToken token = default) { var entity = item.Adapt(); diff --git a/AsbCloudInfrastructure/Services/WellOperationsStatService.cs b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs new file mode 100644 index 00000000..1ea83c53 --- /dev/null +++ b/AsbCloudInfrastructure/Services/WellOperationsStatService.cs @@ -0,0 +1,276 @@ +using AsbCloudApp.Data; +using AsbCloudDb.Model; +using AsbCloudInfrastructure.Services.Cache; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; + +namespace AsbCloudInfrastructure.Services +{ + class OperationParams + { + public OperationParams() { } + + public OperationParams(WellOperation operation) + { + Id = operation.Id; + IdWellSectionType = operation.IdWellSectionType; + IdCategory = operation.IdCategory; + + WellDepth = operation.WellDepth; + StartDate = operation.StartDate; + DurationHours = operation.DurationHours; + + WellDepthReal = operation.WellDepth; + DeltaDepth = 0; + DurationToNextOperationHours = operation.DurationHours; + } + + public int Id { get; } + public int IdWellSectionType { get; } + public int IdCategory { get; } + public double WellDepth { get; } + public DateTime StartDate { get; } + public double DurationHours { get; } + public double WellDepthReal { get; set; } + public double DeltaDepth { get; set; } + public double DurationToNextOperationHours { get; set; } + } + + class Race + { + public DateTime StartDate { get; set; } + public double StartWellDepth { get; set; } + public DateTime EndDate { get; set; } + public double EndWellDepth { get; set; } + public double DrillingTime { get; set; } + public double NonProductiveHours { get; set; } + public double DeltaDepth => EndWellDepth - StartWellDepth; + public double DeltaHoursTimeNoNpt => (EndDate - StartDate).TotalHours - NonProductiveHours; + public double Speed => DeltaDepth / (DeltaHoursTimeNoNpt + double.Epsilon); + } + + class SectionStat + { + public DateTime StartDate { get; set; } + public double StartWellDepth { get; set; } + public DateTime EndDate { get; set; } + public double EndWellDepth { get; set; } + public double AvgRaceSpeed { get; set; } + public double Rop { get; set; } + public double BhaDownSpeed { get; set; } + public double BhaUpSpeed { get; set; } + public double CasingDownSpeed { get; set; } + public int IdSectionType { get; internal set; } + public double Hours => (EndDate - StartDate).TotalHours; + } + + public class WellOperationsStatService + { + private readonly IAsbCloudDbContext db; + private readonly CacheTable cachedSectionsTypes; + const int idOperationBhaAssembly = 1025; + const int idOperationBhaDisassembly = 1026; + private const int idOperationNonProductiveTime = 1043; + private const int idOperationDrilling = 1001; + private const int idOperationBhaDown = 1046; + private const int idOperationBhaUp = 1047; + private const int IdOperationCasingDown = 1048; + + public WellOperationsStatService(IAsbCloudDbContext db, Cache.CacheDb cache) + { + this.db = db; + cachedSectionsTypes = cache.GetCachedTable((DbContext)db); + } + + public async Task> GetSectionsByWellIdAsync(int idWell, + CancellationToken token = default) + { + var operationsAll = await db.WellOperations + .Where(o => o.IdWell == idWell) + .OrderBy(o => o.StartDate) // ускорит дальнейшие сортировки + .AsNoTracking() + .ToListAsync(token); + + var operationsPlan = operationsAll + .Where(o => o.IdType == 0); + + var sectionsPlan = CalcSectionsStats(operationsPlan); + + var operationsFact = operationsAll + .Where(o => o.IdType == 1); + + var sectionsFact = CalcSectionsStats(operationsFact); + var sectionTypesIds = operationsAll.Select(o => o.IdWellSectionType).Distinct(); + var sections = new List(sectionTypesIds.Count()); + foreach (var idSectionType in sectionTypesIds) + { + var statPlan = sectionsPlan.FirstOrDefault(s => s.IdSectionType == idSectionType); + var statFact = sectionsFact.FirstOrDefault(s => s.IdSectionType == idSectionType); + WellSectionDto section = MakeWellSectionDto(idSectionType, statPlan, statFact); + sections.Add(section); + } + return sections; + } + + private WellSectionDto MakeWellSectionDto(int idSectionType, SectionStat statPlan, SectionStat statFact) + { + return new WellSectionDto + { + Id = idSectionType, + SectionType = cachedSectionsTypes.FirstOrDefault(s => s.Id == idSectionType)?.Caption, + + BhaDownSpeedPlan = statPlan?.BhaDownSpeed ?? double.NaN, + BhaUpSpeedPlan = statPlan?.BhaUpSpeed ?? double.NaN, + MechSpeedPlan = statPlan?.Rop ?? double.NaN, + CasingDownSpeedPlan = statPlan?.CasingDownSpeed ?? double.NaN, + RouteSpeedPlan = statPlan?.AvgRaceSpeed ?? double.NaN, + WellDepthPlan = statPlan?.EndWellDepth ?? double.NaN, + DurationPlan = statPlan?.Hours ?? double.NaN, + + BhaDownSpeedFact = statFact?.BhaDownSpeed ?? double.NaN, + BhaUpSpeedFact = statFact?.BhaUpSpeed ?? double.NaN, + MechSpeedFact = statFact?.Rop ?? double.NaN, + CasingDownSpeedFact = statFact?.CasingDownSpeed ?? double.NaN, + RouteSpeedFact = statFact?.AvgRaceSpeed ?? double.NaN, + WellDepthFact = statFact?.EndWellDepth ?? double.NaN, + DurationFact = statFact?.Hours ?? double.NaN, + }; + } + + private static IEnumerable CalcSectionsStats(IEnumerable wellOperations) + { + var operations = MakeOperationsExt(wellOperations); + var sectionTypesIds = operations.Select(o => o.IdWellSectionType).Distinct(); + var sectionsStats = new List(sectionTypesIds.Count()); + foreach (var idSection in sectionTypesIds) + { + var section = CalcSectionStat(operations, idSection); + sectionsStats.Add(section); + } + return sectionsStats; + } + + private static SectionStat CalcSectionStat(IEnumerable allOperations, int idSectionType) + { + var sectionOperations = allOperations + .Where(o => o.IdWellSectionType == idSectionType) + .OrderBy(o => o.StartDate) + .ThenBy(o => o.WellDepth); + var section = new SectionStat + { + IdSectionType = idSectionType, + StartDate = sectionOperations.First().StartDate, + EndDate = sectionOperations.Max(o => (o.StartDate.AddHours(o.DurationHours))), + StartWellDepth = sectionOperations.Min(o => o.WellDepthReal), + EndWellDepth = sectionOperations.Max(o => o.WellDepthReal), + AvgRaceSpeed = CalcAvgRaceSpeed(sectionOperations), + Rop = CalcROP(sectionOperations), + BhaDownSpeed = CalcSpeedByOperation(sectionOperations, idOperationBhaDown), + BhaUpSpeed = CalcSpeedByOperation(sectionOperations, idOperationBhaUp), + CasingDownSpeed = CalcSpeedByOperation(sectionOperations, IdOperationCasingDown), + }; + return section; + } + + private static double CalcSpeedByOperation(IEnumerable operationsProps, int idOperation) + { + var ops = operationsProps.Where(o => o.IdCategory == idOperation); + var maxDepth = 0d; + var dHours = 0d; + foreach (var operation in ops) + { + if (maxDepth > operation.WellDepthReal) + maxDepth = operation.WellDepthReal; + dHours += operation.DurationHours; + } + return maxDepth / (dHours + double.Epsilon); + } + + private static double CalcROP(IEnumerable operationsProps) + { + var drillingOperations = operationsProps.Where(o => o.IdCategory == idOperationDrilling); + var dDepth = 0d; + var dHours = 0d; + foreach (var operation in drillingOperations) + { + dDepth += operation.DeltaDepth; + dHours += operation.DurationHours; + } + return dDepth / (dHours + double.Epsilon); + } + + // Метры в час + private static double CalcAvgRaceSpeed(IEnumerable operations) + { + var races = GetCompleteRaces(operations); + var dDepth = 0d; + var dHours = 0d; + foreach (var race in races) + { + dHours += race.DeltaHoursTimeNoNpt; + dDepth += race.DeltaDepth; + } + return dDepth / (dHours + double.Epsilon); + } + + private static IEnumerable MakeOperationsExt(IEnumerable operations) + { + var count = operations.Count(); + var ops = new List(count); + var item = operations.ElementAt(0); + var wellDepth = item.WellDepth; + var pre = new OperationParams(item); + var current = new OperationParams(item); + for (int i = 1; i < count; i++) + { + item = operations.ElementAt(i); + current = new OperationParams(item) + { + WellDepthReal = Helper.Max(wellDepth, item.WellDepth) // TODO: учесть операциии с уменьшение глубины ствола. + }; + pre.DeltaDepth = current.WellDepthReal - wellDepth; + pre.DurationToNextOperationHours = (current.StartDate - pre.StartDate).TotalHours; + ops.Add(pre); + pre = current; + } + ops.Add(current); + return ops; + } + + private static IEnumerable GetCompleteRaces(IEnumerable operations) + { + var races = new List(4); + var iterator = operations.GetEnumerator(); + while (iterator.MoveNext()) + { + if (iterator.Current.IdCategory == idOperationBhaAssembly) + { + var race = new Race + { + StartDate = iterator.Current.StartDate.AddHours(iterator.Current.DurationHours), + StartWellDepth = iterator.Current.WellDepthReal + }; + while (iterator.MoveNext()) + { + if (iterator.Current.IdCategory == idOperationNonProductiveTime) + { + race.NonProductiveHours += iterator.Current.DurationHours; + } + if (iterator.Current.IdCategory == idOperationBhaDisassembly) + { + race.EndDate = iterator.Current.StartDate.AddHours(iterator.Current.DurationHours); + race.EndWellDepth = iterator.Current.WellDepthReal; + races.Add(race); + } + } + } + } + return races; + } + + } +} diff --git a/AsbCloudInfrastructure/Services/WellSectionService.cs b/AsbCloudInfrastructure/Services/WellSectionService.cs index 979d3fba..0ae33aac 100644 --- a/AsbCloudInfrastructure/Services/WellSectionService.cs +++ b/AsbCloudInfrastructure/Services/WellSectionService.cs @@ -1,26 +1,22 @@ using AsbCloudApp.Data; using AsbCloudApp.Services; using AsbCloudDb.Model; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; -using Mapster; -using Microsoft.EntityFrameworkCore; -using System.Threading.Tasks; using System.Threading; -using AsbCloudInfrastructure.Services.Cache; +using System.Threading.Tasks; namespace AsbCloudInfrastructure.Services { - public class WellSectionService: IWellSectionService + public class WellSectionService : IWellSectionService { private readonly IAsbCloudDbContext db; - private readonly CacheTable cachedSectionsTypes; - public WellSectionService(IAsbCloudDbContext db, Cache.CacheDb cache) + public WellSectionService(IAsbCloudDbContext db) { this.db = db; - cachedSectionsTypes = cache.GetCachedTable((DbContext)db); } public async Task> GetSectionsByWellIdAsync(int idWell, @@ -81,7 +77,7 @@ namespace AsbCloudInfrastructure.Services var dtos = new List(); - for(int i = 0; i < wellOperationsGroupedBySections.Count; i++) + for (int i = 0; i < wellOperationsGroupedBySections.Count; i++) { var dto = new WellSectionDto { @@ -109,28 +105,13 @@ namespace AsbCloudInfrastructure.Services return dtos.OrderBy(d => d.WellDepthPlan); } - public async Task GetSectionByWellIdAsync(int id, CancellationToken token = default) - { - var entity = await db.WellSections - .Include(s => s.WellSectionType) - .FirstOrDefaultAsync(e => e.Id == id, token) - .ConfigureAwait(false); - - if (entity is null) - return null; - - var dto = entity.Adapt(); - dto.SectionType = entity.WellSectionType.Caption; - return dto; - } - private static IEnumerable GetWellDepthStats( IEnumerable> groupedOperations, int type) { return groupedOperations.Select(group => group.Where(o => o.IdType == type) .DefaultIfEmpty().Max(w => w?.WellDepth ?? 0.0)); } - + private static IEnumerable GetWellDurationStats( IEnumerable> groupedOperations, int type) @@ -165,7 +146,7 @@ namespace AsbCloudInfrastructure.Services private static IEnumerable GetWellRouteSpeedStats( IEnumerable> groupedOperations, int type) { - var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecrease, + var bhaRaiseDecreaseCollection = new List<(WellOperation FirstBhaPositionDecrease, WellOperation LastBhaPositionIncrease)>(); foreach (var group in groupedOperations) @@ -182,10 +163,10 @@ namespace AsbCloudInfrastructure.Services } var routeSpeedsBase = bhaRaiseDecreaseCollection.Select(el => - ( + ( RouteDepth: (el.LastBhaPositionIncrease?.WellDepth - el.FirstBhaPositionDecrease?.WellDepth) ?? 0, - RouteDuration: (el.LastBhaPositionIncrease?.StartDate + - TimeSpan.FromHours(el.LastBhaPositionIncrease?.DurationHours ?? 0) - + RouteDuration: (el.LastBhaPositionIncrease?.StartDate + + TimeSpan.FromHours(el.LastBhaPositionIncrease?.DurationHours ?? 0) - el.FirstBhaPositionDecrease?.StartDate)?.TotalHours ?? 0 )); @@ -202,22 +183,5 @@ namespace AsbCloudInfrastructure.Services ); } - private async Task GetWellSectionTypeFromCacheAndAssertAsync(string wellSectionType, CancellationToken token = default) - { - if (string.IsNullOrEmpty(wellSectionType)) - throw new ArgumentException("Тип секции должен быть указан", nameof(WellSectionDto.SectionType)); - - var sectionType = await cachedSectionsTypes - .FirstOrDefaultAsync(s => s.Caption.Equals(wellSectionType, StringComparison.OrdinalIgnoreCase), token) - .ConfigureAwait(false); - - if (sectionType is null) - { - throw new ArgumentException($"Тип секции '{wellSectionType}' отсутствует в справочнике", nameof(WellSectionDto.SectionType)); - //sectionType = await cachedSectionsTypes.InsertAsync(new WellSectionType { Caption = item.SectionType}, token); - } - - return sectionType; - } } } diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs index de706f14..3be51a77 100644 --- a/AsbCloudInfrastructure/Services/WellService.cs +++ b/AsbCloudInfrastructure/Services/WellService.cs @@ -3,12 +3,12 @@ using AsbCloudApp.Services; using AsbCloudDb.Model; using AsbCloudInfrastructure.Services.Cache; using Mapster; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; namespace AsbCloudInfrastructure.Services { @@ -47,7 +47,7 @@ namespace AsbCloudInfrastructure.Services } public async Task IsCompanyInvolvedInWellAsync(int idCompany, int idWell, CancellationToken token) - => await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell && + => await cacheRelationCompaniesWells.ContainsAsync(r => r.IdWell == idWell && r.IdCompany == idCompany, token).ConfigureAwait(false); public async Task> GetOperationsAsync(int idWell, CancellationToken token) diff --git a/AsbCloudWebApi/Controllers/AuthController.cs b/AsbCloudWebApi/Controllers/AuthController.cs index 6c3b48d7..f082dc8e 100644 --- a/AsbCloudWebApi/Controllers/AuthController.cs +++ b/AsbCloudWebApi/Controllers/AuthController.cs @@ -2,9 +2,9 @@ using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Swashbuckle.AspNetCore.Annotations; using System.Threading; using System.Threading.Tasks; -using Swashbuckle.AspNetCore.Annotations; namespace AsbCloudWebApi.Controllers { @@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(UserTokenDto), (int)System.Net.HttpStatusCode.OK)] public async Task LoginAsync([FromBody] AuthDto auth, CancellationToken token = default) { - var userToken = await authService.LoginAsync(auth.Login, + var userToken = await authService.LoginAsync(auth.Login, auth.Password, token).ConfigureAwait(false); if (userToken is null) diff --git a/AsbCloudWebApi/Controllers/ClusterController.cs b/AsbCloudWebApi/Controllers/ClusterController.cs index 000df459..74c7cbf2 100644 --- a/AsbCloudWebApi/Controllers/ClusterController.cs +++ b/AsbCloudWebApi/Controllers/ClusterController.cs @@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetClustersAsync((int)idCompany, + var result = await clusterService.GetClustersAsync((int)idCompany, token).ConfigureAwait(false); return Ok(result); } @@ -57,7 +57,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetWellsAsync((int)idCompany, + var result = await clusterService.GetWellsAsync((int)idCompany, idCluster, token).ConfigureAwait(false); return Ok(result); } @@ -77,7 +77,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetStatAsync((int)idCompany, + var result = await clusterService.GetStatAsync((int)idCompany, idCluster, token).ConfigureAwait(false); return Ok(result); } diff --git a/AsbCloudWebApi/Controllers/CrudController.cs b/AsbCloudWebApi/Controllers/CrudController.cs index 1b54b829..1ba261c5 100644 --- a/AsbCloudWebApi/Controllers/CrudController.cs +++ b/AsbCloudWebApi/Controllers/CrudController.cs @@ -10,7 +10,7 @@ namespace AsbCloudWebApi.Controllers [ApiController] public abstract class CrudController : ControllerBase where T : IId - where TService: ICrudService + where TService : ICrudService { protected readonly TService service; diff --git a/AsbCloudWebApi/Controllers/DataController.cs b/AsbCloudWebApi/Controllers/DataController.cs index 4e6165d0..ec534106 100644 --- a/AsbCloudWebApi/Controllers/DataController.cs +++ b/AsbCloudWebApi/Controllers/DataController.cs @@ -39,12 +39,12 @@ namespace AsbCloudWebApi.Controllers /// [HttpGet] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetDataAsync(int idWell, DateTime begin = default, + public async Task GetDataAsync(int idWell, DateTime begin = default, int intervalSec = 600, int approxPointsCount = 1024, CancellationToken token = default) { if (begin == default) begin = DateTime.Now.AddSeconds(-intervalSec); - var content = await telemetryDataService.GetAsync(idWell, begin, + var content = await telemetryDataService.GetAsync(idWell, begin, intervalSec, approxPointsCount, token).ConfigureAwait(false); if (content is null || !content.Any()) @@ -70,7 +70,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false); if (!isCompanyOwnsWell) diff --git a/AsbCloudWebApi/Controllers/DepositController.cs b/AsbCloudWebApi/Controllers/DepositController.cs index 617357dd..4fadce32 100644 --- a/AsbCloudWebApi/Controllers/DepositController.cs +++ b/AsbCloudWebApi/Controllers/DepositController.cs @@ -37,7 +37,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetDepositsAsync((int)idCompany, + var result = await clusterService.GetDepositsAsync((int)idCompany, token).ConfigureAwait(false); return Ok(result); } @@ -58,7 +58,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - var result = await clusterService.GetClustersAsync((int)idCompany, + var result = await clusterService.GetClustersAsync((int)idCompany, depositId, token).ConfigureAwait(false); return Ok(result); } diff --git a/AsbCloudWebApi/Controllers/FileController.cs b/AsbCloudWebApi/Controllers/FileController.cs index 635c35de..c974d709 100644 --- a/AsbCloudWebApi/Controllers/FileController.cs +++ b/AsbCloudWebApi/Controllers/FileController.cs @@ -4,8 +4,8 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using System; -using System.IO; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -50,9 +50,9 @@ namespace AsbCloudWebApi.Controllers return Forbid(); var fileInfoCollection = files.Select(f => new FileInfoDto - { - Name = f.FileName, - IdCategory = idCategory, + { + Name = f.FileName, + IdCategory = idCategory, UploadDate = DateTime.Now }); @@ -91,7 +91,7 @@ namespace AsbCloudWebApi.Controllers [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public async Task GetFilesInfoAsync([FromRoute] int idWell, int skip = 0, int take = 32, int idCategory = default, - DateTime begin = default, DateTime end = default, + DateTime begin = default, DateTime end = default, CancellationToken token = default, [FromQuery] IEnumerable companies = default) { int? idCompany = User.GetCompanyId(); diff --git a/AsbCloudWebApi/Controllers/LastDataController.cs b/AsbCloudWebApi/Controllers/LastDataController.cs index 0dcdfc16..90a143ac 100644 --- a/AsbCloudWebApi/Controllers/LastDataController.cs +++ b/AsbCloudWebApi/Controllers/LastDataController.cs @@ -20,31 +20,31 @@ namespace AsbCloudWebApi.Controllers } [HttpGet] - public async Task GetAsync([FromRoute] int idWell, + public async Task GetAsync([FromRoute] int idWell, [FromQuery] int idCategory, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - var result = await lastDataService.GetAsync(idWell, + var result = await lastDataService.GetAsync(idWell, idCategory, token).ConfigureAwait(false); return Ok(result); } [HttpPost] - public async Task PutAsync([FromRoute] int idWell, + public async Task PutAsync([FromRoute] int idWell, [FromQuery] int idCategory, T data, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - await lastDataService.UpsertAsync(idWell, + await lastDataService.UpsertAsync(idWell, idCategory, data, token).ConfigureAwait(false); return Ok(); } diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index 66c8d409..f63fcd1d 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -35,9 +35,9 @@ namespace AsbCloudWebApi.Controllers /// список сообщений по скважине [HttpGet] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public async Task GetMessagesAsync(int idWell, int skip = 0, int take = 32, - [FromQuery] IEnumerable categoryids = default, - DateTime begin = default, DateTime end = default, + public async Task GetMessagesAsync(int idWell, int skip = 0, int take = 32, + [FromQuery] IEnumerable categoryids = default, + DateTime begin = default, DateTime end = default, string searchString = default, CancellationToken token = default) { @@ -47,8 +47,8 @@ namespace AsbCloudWebApi.Controllers if (begin > DateTime.Now) begin = default; - var result = await messageService.GetMessagesAsync(idWell, - categoryids, begin, end, searchString, + var result = await messageService.GetMessagesAsync(idWell, + categoryids, begin, end, searchString, skip, take, token).ConfigureAwait(false); if (result is null || result.Count == 0) @@ -74,7 +74,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + bool isCompanyOwnsWell = await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false); if (!isCompanyOwnsWell) diff --git a/AsbCloudWebApi/Controllers/ReportController.cs b/AsbCloudWebApi/Controllers/ReportController.cs index a42e6710..67e05734 100644 --- a/AsbCloudWebApi/Controllers/ReportController.cs +++ b/AsbCloudWebApi/Controllers/ReportController.cs @@ -74,9 +74,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); var id = reportService.CreateReport(idWell, idUser, stepSeconds, format, begin, end, HandleReportProgressAsync, HandleReportNameAsync); @@ -94,7 +94,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{reportName}")] [ProducesResponseType(typeof(PhysicalFileResult), (int)System.Net.HttpStatusCode.OK)] - public async Task GetReportAsync([FromRoute] int idWell, + public async Task GetReportAsync([FromRoute] int idWell, string reportName, CancellationToken token = default) { try @@ -104,9 +104,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); // TODO: словарь content typoв var relativePath = Path.Combine(fileService.RootPath, $"{idWell}", @@ -137,7 +137,7 @@ namespace AsbCloudWebApi.Controllers DateTime begin = default, DateTime end = default, CancellationToken token = default) { - var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell, + var suitableReportsNames = await reportService.GetSuitableReportsAsync(idWell, begin, end, stepSeconds, format, token).ConfigureAwait(false); if (suitableReportsNames is null || !suitableReportsNames.Any()) @@ -159,8 +159,8 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("reportSize")] [ProducesResponseType(typeof(string), (int)System.Net.HttpStatusCode.OK)] - public async Task GetReportSizeAsync(int idWell, - int stepSeconds, int format, DateTime begin = default, + public async Task GetReportSizeAsync(int idWell, + int stepSeconds, int format, DateTime begin = default, DateTime end = default, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); @@ -168,11 +168,11 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - int reportSize = reportService.GetReportPagesCount(idWell, + int reportSize = reportService.GetReportPagesCount(idWell, begin, end, stepSeconds, format); return Ok(reportSize); @@ -187,7 +187,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("datesRange")] [ProducesResponseType(typeof(DatesRangeDto), (int)System.Net.HttpStatusCode.OK)] - public async Task GetReportsDateRangeAsync(int idWell, + public async Task GetReportsDateRangeAsync(int idWell, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); @@ -195,9 +195,9 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return Forbid(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); DatesRangeDto wellReportsDatesRange = await reportService.GetReportsDatesRangeAsync(idWell, token).ConfigureAwait(false); diff --git a/AsbCloudWebApi/Controllers/TelemetryAnalyticsController.cs b/AsbCloudWebApi/Controllers/TelemetryAnalyticsController.cs index 578b8842..4650705c 100644 --- a/AsbCloudWebApi/Controllers/TelemetryAnalyticsController.cs +++ b/AsbCloudWebApi/Controllers/TelemetryAnalyticsController.cs @@ -39,14 +39,14 @@ namespace AsbCloudWebApi.Controllers [Route("operationsByWell")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public async Task GetOperationsByWellAsync(int idWell, int skip = 0, int take = 32, - [FromQuery] IEnumerable categoryIds = default, DateTime begin = default, DateTime end = default, + [FromQuery] IEnumerable categoryIds = default, DateTime begin = default, DateTime end = default, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); var analytics = await analyticsService.GetOperationsByWellAsync(idWell, categoryIds, begin, end, skip, take, token) .ConfigureAwait(false); @@ -71,9 +71,9 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); var wellDepthToDayData = await analyticsService.GetWellDepthToDayAsync(idWell, token) .ConfigureAwait(false); @@ -100,9 +100,9 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); var wellDepthToIntervalData = await analyticsService.GetWellDepthToIntervalAsync(idWell, intervalSeconds, workBeginSeconds, token).ConfigureAwait(false); @@ -124,16 +124,16 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("operationsSummary")] [ProducesResponseType(typeof(IEnumerable), (int)System.Net.HttpStatusCode.OK)] - public async Task GetOperationsSummaryAsync(int idWell, DateTime begin = default, + public async Task GetOperationsSummaryAsync(int idWell, DateTime begin = default, DateTime end = default, CancellationToken token = default) { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - var analytics = await analyticsService .GetOperationsSummaryAsync(idWell, + var analytics = await analyticsService.GetOperationsSummaryAsync(idWell, begin, end, token).ConfigureAwait(false); if (analytics is null || !analytics.Any()) @@ -158,11 +158,11 @@ namespace AsbCloudWebApi.Controllers { int? idCompany = User.GetCompanyId(); - if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync ((int)idCompany, + if (idCompany is null || !await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, + var analytics = await analyticsService.GetOperationsToIntervalAsync(idWell, intervalSeconds, workBeginSeconds, token).ConfigureAwait(false); if (analytics is null || !analytics.Any()) diff --git a/AsbCloudWebApi/Controllers/WellController.cs b/AsbCloudWebApi/Controllers/WellController.cs index af7c2e21..edf7b4a0 100644 --- a/AsbCloudWebApi/Controllers/WellController.cs +++ b/AsbCloudWebApi/Controllers/WellController.cs @@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers return NoContent(); } - var wells = await wellService.GetWellsByCompanyAsync((int)idCompany, + var wells = await wellService.GetWellsByCompanyAsync((int)idCompany, token).ConfigureAwait(false); if (wells is null || !wells.Any()) @@ -50,11 +50,11 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return NoContent(); - if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, + if (!await wellService.IsCompanyInvolvedInWellAsync((int)idCompany, idWell, token).ConfigureAwait(false)) - return Forbid(); + return Forbid(); - var dto = await wellService.GetOperationsAsync(idWell, + var dto = await wellService.GetOperationsAsync(idWell, token).ConfigureAwait(false); return Ok(dto); @@ -69,7 +69,7 @@ namespace AsbCloudWebApi.Controllers if (idCompany is null) return NoContent(); - var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany, + var transmittingWells = await wellService.GetTransmittingWellsAsync((int)idCompany, token).ConfigureAwait(false); if (transmittingWells is null || !transmittingWells.Any()) diff --git a/AsbCloudWebApi/Controllers/WellOperationController.cs b/AsbCloudWebApi/Controllers/WellOperationController.cs index 2c606631..9a0a7317 100644 --- a/AsbCloudWebApi/Controllers/WellOperationController.cs +++ b/AsbCloudWebApi/Controllers/WellOperationController.cs @@ -1,11 +1,11 @@ -using System.Collections.Generic; +using AsbCloudApp.Data; +using AsbCloudApp.Services; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using AsbCloudApp.Data; -using AsbCloudApp.Services; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Authorization; -using System; namespace AsbCloudWebApi.Controllers { @@ -57,15 +57,15 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] public async Task GetOperationsAsync( - int idWell, + int idWell, int? opertaionType = default, [FromQuery] IEnumerable sectionTypeIds = default, [FromQuery] IEnumerable operationCategoryIds = default, DateTime begin = default, DateTime end = default, - double minDepth = double.MinValue, + double minDepth = double.MinValue, double maxDepth = double.MaxValue, - int skip = 0, + int skip = 0, int take = 32, CancellationToken token = default) { @@ -138,7 +138,7 @@ namespace AsbCloudWebApi.Controllers /// Количество обновленных в БД строк [HttpPut("{idOperation}")] [ProducesResponseType(typeof(WellOperationDto), (int)System.Net.HttpStatusCode.OK)] - public async Task UpdateAsync(int idWell, int idOperation, + public async Task UpdateAsync(int idWell, int idOperation, [FromBody] WellOperationDto value, CancellationToken token = default) { if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) diff --git a/AsbCloudWebApi/Controllers/WellSectionController.cs b/AsbCloudWebApi/Controllers/WellSectionController.cs index 34cc02a5..963490f5 100644 --- a/AsbCloudWebApi/Controllers/WellSectionController.cs +++ b/AsbCloudWebApi/Controllers/WellSectionController.cs @@ -1,8 +1,8 @@ -using System.Collections.Generic; -using AsbCloudApp.Data; +using AsbCloudApp.Data; using AsbCloudApp.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; @@ -30,7 +30,7 @@ namespace AsbCloudWebApi.Controllers public async Task GetSectionsByWellIdAsync(int idWell, CancellationToken token = default) { - if(!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) + if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) return Forbid(); var result = await sectionsService.GetSectionsByWellIdAsync(idWell, token) @@ -38,19 +38,6 @@ namespace AsbCloudWebApi.Controllers return Ok(result); } - [HttpGet] - [Route("{idSection}")] - [ProducesResponseType(typeof(WellSectionDto), (int)System.Net.HttpStatusCode.OK)] - public async Task GetAsync(int idWell, int idSection, - CancellationToken token = default) - { - if (!await CanUserAccessToWellAsync(idWell, token).ConfigureAwait(false)) - return Forbid(); - - var result = await sectionsService.GetSectionByWellIdAsync(idSection, token).ConfigureAwait(false); - return Ok(result); - } - private async Task CanUserAccessToWellAsync(int idWell, CancellationToken token = default) { int? idCompany = User.GetCompanyId();