forked from ddrilling/AsbCloudServer
WellInfoService использует кеш телеметрии вместо долгого запроса.
This commit is contained in:
parent
ed156b1ce8
commit
9347e9610b
@ -125,6 +125,14 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
return items;
|
||||
}
|
||||
|
||||
public TDto? GetLastOrDefault(int idTelemetry)
|
||||
{
|
||||
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
||||
return default;
|
||||
|
||||
return cacheItem.LastData.LastOrDefault();
|
||||
}
|
||||
|
||||
public DatesRangeDto? GetOrDefaultDataDateRange(int idTelemetry)
|
||||
{
|
||||
if (!caches.TryGetValue(idTelemetry, out TelemetryDataCacheItem? cacheItem))
|
||||
|
@ -1,13 +1,14 @@
|
||||
using AsbCloudApp.Data;
|
||||
using AsbCloudApp.Data.ProcessMap;
|
||||
using AsbCloudApp.Data.SAUB;
|
||||
using AsbCloudApp.Repositories;
|
||||
using AsbCloudApp.Requests;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudApp.Services.Subsystems;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Background;
|
||||
using AsbCloudInfrastructure.Services.SAUB;
|
||||
using Mapster;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -46,6 +47,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
var operationsStatService = serviceProvider.GetRequiredService<IOperationsStatService>();
|
||||
var processMapRepository = serviceProvider.GetRequiredService<IProcessMapPlanRepository>();
|
||||
var subsystemOperationTimeService = serviceProvider.GetRequiredService<ISubsystemOperationTimeService>();
|
||||
var telemetryDataSaubCache = serviceProvider.GetRequiredService<TelemetryDataCache<TelemetryDataSaubDto>>();
|
||||
|
||||
var activeWells = await wellService.GetAsync(new() {IdState = 1}, token);
|
||||
|
||||
@ -56,21 +58,6 @@ namespace AsbCloudInfrastructure.Services
|
||||
.Where(w => w.IdTelemetry != null)
|
||||
.Select(t => t.IdTelemetry);
|
||||
|
||||
var lastTelemetryInfo = await db.TelemetryDataSaub
|
||||
.Where(t => idTelemetries.Contains(t.IdTelemetry))
|
||||
.Select(t => new
|
||||
{
|
||||
t.IdTelemetry,
|
||||
t.WellDepth,
|
||||
t.DateTime,
|
||||
})
|
||||
.GroupBy(t => t.IdTelemetry)
|
||||
.Select(g => g.OrderByDescending(t => t.DateTime)
|
||||
.First()
|
||||
)
|
||||
.AsNoTracking()
|
||||
.ToArrayAsync(token);
|
||||
|
||||
var processMapRequests = activeWellsIds.Select(id => new ProcessMapRequest { IdWell = id });
|
||||
var processMaps = await processMapRepository.GetProcessMapAsync(processMapRequests, token);
|
||||
|
||||
@ -83,40 +70,46 @@ namespace AsbCloudInfrastructure.Services
|
||||
});
|
||||
|
||||
var operationsStat = await operationsStatService.GetWellsStatAsync(activeWellsIds, token);
|
||||
|
||||
var subsystemStat = await subsystemOperationTimeService.GetStatByActiveWells(activeWellsIds, token);
|
||||
|
||||
WellMapInfo = activeWells.Select(well => {
|
||||
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
||||
|
||||
var wellLastTelemetryInfo = lastTelemetryInfo.FirstOrDefault(t => t.IdTelemetry == well.IdTelemetry);
|
||||
|
||||
var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id);
|
||||
var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null);
|
||||
|
||||
var wellSubsystemStat = subsystemStat.FirstOrDefault(s => s.Well.Id == well.Id);
|
||||
double? currentDepth = null;
|
||||
DateTime lastTelemetryDate = default;
|
||||
|
||||
double currentDepth = wellLastTelemetryInfo?.WellDepth
|
||||
?? wellLastFactSection?.Fact?.WellDepthEnd
|
||||
?? 0d;
|
||||
if (well.IdTelemetry.HasValue)
|
||||
{
|
||||
var lastSaubTelemetry = telemetryDataSaubCache.GetLastOrDefault(well.IdTelemetry.Value);
|
||||
if(lastSaubTelemetry is not null)
|
||||
{
|
||||
currentDepth = lastSaubTelemetry.WellDepth;
|
||||
lastTelemetryDate = lastSaubTelemetry.DateTime;
|
||||
}
|
||||
}
|
||||
|
||||
currentDepth ??= wellLastFactSection?.Fact?.WellDepthEnd;
|
||||
|
||||
var wellProcessMaps = processMaps
|
||||
.Where(p => p.IdWell == well.Id)
|
||||
.OrderBy(p => p.DepthEnd);
|
||||
|
||||
int? idSection = wellLastFactSection?.Id;
|
||||
ProcessMapPlanDto? welllProcessMap = null;
|
||||
|
||||
ProcessMapPlanDto? welllProcessMap;
|
||||
if (idSection is not null)
|
||||
if (idSection.HasValue)
|
||||
{
|
||||
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection);
|
||||
}
|
||||
else
|
||||
else if(currentDepth.HasValue)
|
||||
{
|
||||
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth && p.DepthEnd >= currentDepth);
|
||||
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value);
|
||||
idSection ??= welllProcessMap?.IdWellSectionType;
|
||||
}
|
||||
|
||||
wellMapInfo.LastTelemetryDate = wellLastTelemetryInfo?.DateTime.ToRemoteDateTime(5) ?? new DateTime();
|
||||
wellMapInfo.WellDepth = new()
|
||||
{
|
||||
Plan = wellDepthByProcessMap.FirstOrDefault(p => p.Id == well.Id)?.DepthEnd,
|
||||
@ -135,6 +128,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
Fact = wellOperationsStat?.Total.Fact?.RouteSpeed,
|
||||
};
|
||||
|
||||
var wellSubsystemStat = subsystemStat.FirstOrDefault(s => s.Well.Id == well.Id);
|
||||
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
|
||||
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
|
||||
wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagDays ?? 0d;
|
||||
|
Loading…
Reference in New Issue
Block a user