diff --git a/AsbCloudDb/Model/AsbCloudDbContext.cs b/AsbCloudDb/Model/AsbCloudDbContext.cs index 25756978..3fcc2ad2 100644 --- a/AsbCloudDb/Model/AsbCloudDbContext.cs +++ b/AsbCloudDb/Model/AsbCloudDbContext.cs @@ -90,6 +90,8 @@ namespace AsbCloudDb.Model public DbSet Contacts => Set(); public DbSet DrillTests => Set(); + + public DbSet ProcessMapDrillingCache => Set(); public AsbCloudDbContext() : base() { Interlocked.Increment(ref referenceCount); diff --git a/AsbCloudDb/Model/IAsbCloudDbContext.cs b/AsbCloudDb/Model/IAsbCloudDbContext.cs index 6934a326..a451fc45 100644 --- a/AsbCloudDb/Model/IAsbCloudDbContext.cs +++ b/AsbCloudDb/Model/IAsbCloudDbContext.cs @@ -80,6 +80,7 @@ namespace AsbCloudDb.Model DbSet DrillTests { get; } DbSet TrajectoriesFact { get; } DbSet WellSectionsPlan { get; } + DbSet ProcessMapDrillingCache { get; } DatabaseFacade Database { get; } Task RefreshMaterializedViewAsync(string mwName, CancellationToken token); diff --git a/AsbCloudDb/Model/ProcessMapDrillingCache.cs b/AsbCloudDb/Model/ProcessMapDrillingCache.cs new file mode 100644 index 00000000..ebaddaa3 --- /dev/null +++ b/AsbCloudDb/Model/ProcessMapDrillingCache.cs @@ -0,0 +1,21 @@ +using Microsoft.EntityFrameworkCore; +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace AsbCloudDb.Model +{ + [Table("t_process_map_drilling_cache"), Comment("Кеш-таблица для хранения данных для РТК-отчета")] + public class ProcessMapDrillingCache : IId + { + [Key] + [Column("id")] + public int Id { get; set; } + + [Column("date_from", TypeName = "timestamp with time zone"), Comment("Дата начала")] + public DateTimeOffset DateFrom { get; set; } + + [Column("date_to", TypeName = "timestamp with time zone"), Comment("Дата окончания")] + public DateTimeOffset DateTo { get; set; } + } +} diff --git a/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCashe.cs b/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs similarity index 86% rename from AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCashe.cs rename to AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs index dbe63510..87e90a32 100644 --- a/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCashe.cs +++ b/AsbCloudInfrastructure/Background/PeriodicWorks/WorkProcessMapDrillingCache.cs @@ -11,12 +11,12 @@ using System.Threading.Tasks; namespace AsbCloudInfrastructure.Background.PeriodicWorks { - internal class WorkProcessMapDrillingCashe : Work + internal class WorkProcessMapDrillingCache : Work { private int MechanicalDrillingCategoryId = 4001; - public WorkProcessMapDrillingCashe() : base("Generate process map drilling cache table") + public WorkProcessMapDrillingCache() : base("Generate process map drilling cache table") { - Timeout = TimeSpan.FromMinutes(1); + Timeout = TimeSpan.FromMinutes(10); } protected override Task Action(string id, IServiceProvider services, Action onProgressCallback, CancellationToken token) @@ -36,13 +36,13 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks //7/ разбивка диапазонов: // параметры метода: массив из - var dateStart = DateTimeOffset.UtcNow.AddDays(-3500); - using var db = services.GetRequiredService(); + var dateFrom = db.ProcessMapDrillingCache.OrderByDescending(c => c.DateTo).FirstOrDefault()?.DateTo ?? DateTimeOffset.MinValue; + //а остальные операции, которые не вошли в 500 первых? var detectedOperations = db.DetectedOperations - .Where(o => o.DateStart > dateStart) + .Where(o => o.DateStart > dateFrom) .Where(o => o.OperationCategory.IdParent == MechanicalDrillingCategoryId) .Take(500) .ToArray(); @@ -57,7 +57,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks .OrderBy(t => t.DateTime) .ToArray(); - var result = new List(); + var result = new List(); foreach (var operation in detectedOperations) { var indexStart = 0; @@ -68,7 +68,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks { length++; } - else if(length > 0) + else if (length > 0) { var subset = telemetryDataSaub.AsSpan(indexStart, length); var ranges = getRanges(subset, operation); @@ -79,13 +79,13 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks } } - return null; + return Task.CompletedTask; } - private List getRanges(Span span, DetectedOperation operation) + private List getRanges(Span span, DetectedOperation operation) { - var result = new List(); - var cacheItem = new CacheItem(); + var result = new List(); + var cacheItem = new ProcessMapDrillingCacheItem(); cacheItem.Elems.Add(span[0]); result.Add(cacheItem); @@ -106,7 +106,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks isNewCacheItem = isNewCacheItem || !(current.IdFeedRegulator == prev.IdFeedRegulator); if (isNewCacheItem) { - cacheItem = new CacheItem(); + cacheItem = new ProcessMapDrillingCacheItem(); result.Add(cacheItem); } cacheItem.Elems.Add(current); @@ -115,7 +115,7 @@ namespace AsbCloudInfrastructure.Background.PeriodicWorks } } - internal class CacheItem + internal class ProcessMapDrillingCacheItem { public List Elems = new List(); } diff --git a/AsbCloudInfrastructure/Startup.cs b/AsbCloudInfrastructure/Startup.cs index f6d2fe47..3561654a 100644 --- a/AsbCloudInfrastructure/Startup.cs +++ b/AsbCloudInfrastructure/Startup.cs @@ -29,7 +29,7 @@ namespace AsbCloudInfrastructure _ = provider.GetRequiredService>(); var backgroundWorker = provider.GetRequiredService(); - backgroundWorker.Add(TimeSpan.FromDays(1)); + backgroundWorker.Add(TimeSpan.FromDays(1)); backgroundWorker.Add(TimeSpan.FromDays(1)); backgroundWorker.Add(TimeSpan.FromMinutes(30)); backgroundWorker.Add(TimeSpan.FromMinutes(15));