diff --git a/AsbCloud.sln b/AsbCloud.sln
index e7a39b41..147d2337 100644
--- a/AsbCloud.sln
+++ b/AsbCloud.sln
@@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudDb", "AsbCloudDb\As
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AsbCloudWebApi.Tests", "AsbCloudWebApi.Tests\AsbCloudWebApi.Tests.csproj", "{9CF6FBB1-9AF5-45AB-A521-24F11A79B540}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignalRTestClient", "SignalRTestClient\SignalRTestClient.csproj", "{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SignalRTestClient", "SignalRTestClient\SignalRTestClient.csproj", "{E6B97963-4CEA-47B6-A0C8-625FFA9B7D69}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/AsbCloudApp/Data/WellMapInfoDto.cs b/AsbCloudApp/Data/WellMapInfoDto.cs
index 1d491644..524fbf72 100644
--- a/AsbCloudApp/Data/WellMapInfoDto.cs
+++ b/AsbCloudApp/Data/WellMapInfoDto.cs
@@ -1,7 +1,44 @@
-using System;
+using AsbCloudApp.Data.SAUB;
+using System;
namespace AsbCloudApp.Data
{
+ ///
+ /// Инфо о скважине для отображения на карте последними данными телеметрии
+ ///
+ public class WellMapInfoWithTelemetryStat : WellMapInfoDto
+ {
+ ///
+ /// Последние полученные данные от АПД
+ ///
+ public TelemetryDataSaubDto? LastDataSaub { get; set; }
+
+ ///
+ /// Последние полученные данные от Осцилляции
+ ///
+ public TelemetryDataSpinDto? LastDataSpin { get; set; }
+
+ ///
+ /// Дата полседнего получения данных от ННБ
+ ///
+ public DateTime? LastDataDdsDate { get; set; }
+
+ ///
+ /// Дата полседнего получения данных от ГТИ
+ ///
+ public DateTime? LastDataGtrDate { get; set; }
+
+ ///
+ /// Дата полседнего получения данных от СКПБ
+ ///
+ public DateTime? LastDataDpcsDate { get; set; }
+
+ ///
+ /// Дата полседнего получения данных от станции контроля параметров цементирования (СКЦ)
+ ///
+ public DateTime? LastDataCpmsDate { get; set; }
+ }
+
///
/// Инфо о скважине для отображения на карте
///
@@ -14,19 +51,6 @@ namespace AsbCloudApp.Data
///
public int IdState { get; set; }
- ///
- /// Режим АПД:
- /// 0 - "РУЧНОЙ"
- /// 1 - "БУРЕНИЕ В РОТОРЕ"
- /// 2 - "ПРОРАБОТКА"
- /// 3 - "БУРЕНИЕ В СЛАЙДЕ"
- /// 4 - "СПУСК СПО"
- /// 5 - "ПОДЪЕМ СПО"
- /// 6 - "ПОДЪЕМ С ПРОРАБОТКОЙ"
- /// 10 - "БЛОКИРОВКА"
- ///
- public int IdMode { get; set; }
-
///
/// Коэф-т использования автоподачи долота (суммарный ротор + слайд)
///
@@ -42,36 +66,6 @@ namespace AsbCloudApp.Data
///
public double TorqueKUsage { get; set; }
- ///
- /// Состояние МСЕ
- ///
- public double IdStateMse { get; set; }
-
- ///
- /// Дата/время получения данных от системы АПД
- ///
- public DateTime LastTelemetrySaubDate { get; set; }
-
- ///
- /// Дата/время получения данных от системы осцилляции
- ///
- public DateTime LastTelemetrySpinDate { get; set; }
-
- ///
- /// Дата/время получения данных от ННБ
- ///
- public DateTime LastTelemetryDdsDate { get; set; }
-
- ///
- /// Дата/время получения данных от ГТИ
- ///
- public DateTime LastTelemetryGtrDate { get; set; }
-
- ///
- /// Дата/время получения данных от СКПБ
- ///
- public DateTime LastTelemetryDpcsDate { get; set; }
-
///
/// Дата начала первой фактической операции
/// Используется как дата начала бурения
diff --git a/AsbCloudInfrastructure/DependencyInjection.cs b/AsbCloudInfrastructure/DependencyInjection.cs
index aa4734bd..fd4d1612 100644
--- a/AsbCloudInfrastructure/DependencyInjection.cs
+++ b/AsbCloudInfrastructure/DependencyInjection.cs
@@ -136,6 +136,7 @@ namespace AsbCloudInfrastructure
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
diff --git a/AsbCloudInfrastructure/Services/WellInfoService.cs b/AsbCloudInfrastructure/Services/WellInfoService.cs
index d24b04a3..7a99a767 100644
--- a/AsbCloudInfrastructure/Services/WellInfoService.cs
+++ b/AsbCloudInfrastructure/Services/WellInfoService.cs
@@ -1,6 +1,7 @@
using AsbCloudApp.Data;
using AsbCloudApp.Data.ProcessMap;
using AsbCloudApp.Data.SAUB;
+using AsbCloudApp.Data.WITS;
using AsbCloudApp.Repositories;
using AsbCloudApp.Requests;
using AsbCloudApp.Services;
@@ -18,18 +19,36 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
-
public class WellInfoService
{
class WellMapInfoWithComanies : WellMapInfoDto
{
+ public int? IdTelemetry { get; set; }
public IEnumerable IdsCompanies { get; set; } = null!;
}
private const string workId = "Well statistics update";
private static readonly TimeSpan workPeriod = TimeSpan.FromMinutes(30);
+
+ private readonly TelemetryDataCache telemetryDataSaubCache;
+ private readonly TelemetryDataCache telemetryDataSpinCache;
+ private readonly IWitsRecordRepository witsRecord7Repository;
+ private readonly IWitsRecordRepository witsRecord1Repository;
private static IEnumerable WellMapInfo = Enumerable.Empty();
+
+ public WellInfoService(
+ TelemetryDataCache telemetryDataSaubCache,
+ TelemetryDataCache telemetryDataSpinCache,
+ IWitsRecordRepository witsRecord7Repository,
+ IWitsRecordRepository witsRecord1Repository)
+ {
+ this.telemetryDataSaubCache = telemetryDataSaubCache;
+ this.telemetryDataSpinCache = telemetryDataSpinCache;
+
+ this.witsRecord7Repository = witsRecord7Repository;
+ this.witsRecord1Repository = witsRecord1Repository;
+ }
public static WorkPeriodic MakeWork()
{
@@ -75,23 +94,22 @@ namespace AsbCloudInfrastructure.Services
WellMapInfo = activeWells.Select(well => {
var wellMapInfo = well.Adapt();
- var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id);
- var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null);
+ wellMapInfo.IdState = well.IdState;
double? currentDepth = null;
- double? planTotalDepth = null;
- DateTime lastTelemetryDate = default;
if (well.IdTelemetry.HasValue)
{
+ wellMapInfo.IdTelemetry = well.IdTelemetry.Value;
var lastSaubTelemetry = telemetryDataSaubCache.GetLastOrDefault(well.IdTelemetry.Value);
if(lastSaubTelemetry is not null)
{
currentDepth = lastSaubTelemetry.WellDepth;
- lastTelemetryDate = lastSaubTelemetry.DateTime;
}
}
+ var wellOperationsStat = operationsStat.FirstOrDefault(s => s.Id == well.Id);
+ var wellLastFactSection = wellOperationsStat?.Sections.LastOrDefault(s => s.Fact is not null);
currentDepth ??= wellLastFactSection?.Fact?.WellDepthEnd;
var wellProcessMaps = processMaps
@@ -111,9 +129,16 @@ namespace AsbCloudInfrastructure.Services
idSection ??= welllProcessMap?.IdWellSectionType;
}
+ double? planTotalDepth = null;
planTotalDepth = wellDepthByProcessMap.FirstOrDefault(p => p.Id == well.Id)?.DepthEnd;
planTotalDepth ??= wellOperationsStat?.Total.Plan?.WellDepthEnd;
+ wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
+ ?? wellOperationsStat?.Total.Plan?.Start;
+
+ wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End?
+ .AddDays(wellOperationsStat?.TvdLagDays ?? 0d);
+
wellMapInfo.WellDepth = new()
{
Plan = planTotalDepth,
@@ -135,17 +160,51 @@ namespace AsbCloudInfrastructure.Services
var wellSubsystemStat = subsystemStat.FirstOrDefault(s => s.Well.Id == well.Id);
wellMapInfo.SaubUsage = wellSubsystemStat?.SubsystemAKB?.KUsage ?? 0d;
wellMapInfo.SpinUsage = wellSubsystemStat?.SubsystemSpinMaster?.KUsage ?? 0d;
+ wellMapInfo.TorqueKUsage = wellSubsystemStat?.SubsystemTorqueMaster?.KUsage ?? 0d;
wellMapInfo.TvdLagPercent = wellOperationsStat?.TvdLagDays ?? 0d;
wellMapInfo.IdsCompanies = well.Companies.Select(c => c.Id);
+
return wellMapInfo;
}).ToArray();
}
- public static IEnumerable Where(Func predicate)
- => WellMapInfo.Where(predicate);
+ private WellMapInfoWithTelemetryStat Convert(WellMapInfoWithComanies wellInfo)
+ {
+ var result = wellInfo.Adapt();
+ if (wellInfo.IdTelemetry.HasValue)
+ {
+ result.LastDataSaub = telemetryDataSaubCache.GetLastOrDefault(wellInfo.IdTelemetry.Value);
+ result.LastDataSpin = telemetryDataSpinCache.GetLastOrDefault(wellInfo.IdTelemetry.Value);
+ result.LastDataDdsDate = GetLastOrDefaultDdsTelemetry(wellInfo.IdTelemetry.Value);
+ result.LastDataGtrDate = null;
+ result.LastDataDpcsDate = null;
+ result.LastDataDpcsDate = null;
+ }
- public static WellMapInfoDto? FirstOrDefault(Func predicate)
- => WellMapInfo.FirstOrDefault(predicate);
+ return result;
+ }
+
+ private DateTime? GetLastOrDefaultDdsTelemetry(int idTelemetry)
+ {
+ var lastDdsRecord1Date = witsRecord1Repository.GetLastOrDefault(idTelemetry)?.DateTime;
+ var lastDdsRecord7Date = witsRecord7Repository.GetLastOrDefault(idTelemetry)?.DateTime;
+
+ if (lastDdsRecord1Date.HasValue && lastDdsRecord7Date.HasValue)
+ if (lastDdsRecord1Date.Value > lastDdsRecord7Date.Value)
+ return lastDdsRecord1Date.Value;
+ else
+ return lastDdsRecord7Date.Value;
+
+ return lastDdsRecord1Date ?? lastDdsRecord7Date;
+ }
+
+ public WellMapInfoWithTelemetryStat? FirstOrDefault(Func predicate)
+ {
+ var first = WellMapInfo.FirstOrDefault(predicate);
+ if (first is WellMapInfoWithComanies wellMapInfoWithComanies)
+ return Convert(wellMapInfoWithComanies);
+
+ return null;
+ }
}
-
}
diff --git a/AsbCloudInfrastructure/Services/WellService.cs b/AsbCloudInfrastructure/Services/WellService.cs
index 711b495e..7645c0aa 100644
--- a/AsbCloudInfrastructure/Services/WellService.cs
+++ b/AsbCloudInfrastructure/Services/WellService.cs
@@ -16,12 +16,12 @@ using System.Threading.Tasks;
namespace AsbCloudInfrastructure.Services
{
-
public class WellService : CrudCacheRepositoryBase, IWellService
{
private readonly ITelemetryService telemetryService;
private readonly ICrudRepository companyTypesService;
private readonly ITimezoneService timezoneService;
+ private readonly WellInfoService wellInfoService;
private readonly IWellOperationRepository wellOperationRepository;
public ITelemetryService TelemetryService => telemetryService;
@@ -35,12 +35,12 @@ namespace AsbCloudInfrastructure.Services
.Include(w => w.RelationCompaniesWells)
.ThenInclude(r => r.Company);
- public WellService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService, ITimezoneService timezoneService)
+ public WellService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService, ITimezoneService timezoneService, WellInfoService wellInfoService)
: base(db, memoryCache, MakeQueryWell)
{
this.telemetryService = telemetryService;
this.timezoneService = timezoneService;
-
+ this.wellInfoService = wellInfoService;
this.wellOperationRepository = new WellOperationRepository(db, memoryCache, this);
companyTypesService = new CrudCacheRepositoryBase(dbContext, memoryCache);
}
@@ -92,13 +92,10 @@ namespace AsbCloudInfrastructure.Services
Longitude = gCluster.Key.Longitude ?? gDeposit.Key.Longitude,
Wells = gCluster.Select(well =>
{
- var dto = WellInfoService.FirstOrDefault(w => w.Id == well.Id);
- dto ??= well.Adapt();
+ var dto = wellInfoService.FirstOrDefault(w => w.Id == well.Id);
+ dto ??= well.Adapt();
dto.Latitude ??= gCluster.Key.Latitude ?? gDeposit.Key.Latitude;
dto.Longitude ??= gCluster.Key.Longitude ?? gDeposit.Key.Longitude;
- if (well.IdTelemetry is not null)
- dto.LastTelemetryDate = telemetryService.GetDatesRange(well.IdTelemetry.Value).To;
-
return dto;
}),
}),
diff --git a/AsbCloudWebApi/Rest/Well.http b/AsbCloudWebApi/Rest/Well.http
new file mode 100644
index 00000000..1cc68e29
--- /dev/null
+++ b/AsbCloudWebApi/Rest/Well.http
@@ -0,0 +1,10 @@
+@baseUrl = http://127.0.0.1:5000
+@contentType = application/json
+@auth = Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImN0eSI6IkpXVCJ9.eyJpZCI6IjEiLCJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1lIjoiZGV2IiwiaWRDb21wYW55IjoiMSIsImh0dHA6Ly9zY2hlbWFzLm1pY3Jvc29mdC5jb20vd3MvMjAwOC8wNi9pZGVudGl0eS9jbGFpbXMvcm9sZSI6InJvb3QiLCJuYmYiOjE2NjI1NDgxNjIsImV4cCI6MTY5NDEwNTc2MiwiaXNzIjoiYSIsImF1ZCI6ImEifQ.OEAlNzxi7Jat6pzDBTAjTbChskc-tdJthJexyWwwUKE
+
+@idWell = 1
+
+GET {{baseUrl}}/api/well/wellTree
+Content-Type: {{contentType}}
+accept: */*
+Authorization: {{auth}}
\ No newline at end of file