forked from ddrilling/AsbCloudServer
merge dev to feature/email_notifications
This commit is contained in:
commit
c05fc0f400
@ -50,6 +50,11 @@ namespace AsbCloudApp.Data
|
||||
/// 2 - завершена
|
||||
/// </summary>
|
||||
public int IdState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Название текущей секции
|
||||
/// </summary>
|
||||
public string? Section { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Коэф-т использования автоподачи долота (суммарный ротор + слайд)
|
||||
@ -89,6 +94,31 @@ namespace AsbCloudApp.Data
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> ROP { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Нагрузка на долота, Т
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> AxialLoad { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Обороты ротора
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> TopDriveSpeed { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Момент ротора кн/м
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> TopDriveTorque { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Перепад давления
|
||||
/// </summary>
|
||||
public PlanFactDto<double?> Pressure { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// Действующее задание давления, атм
|
||||
/// </summary>
|
||||
public double? PressureSp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Плановая и текущая глубина
|
||||
/// </summary>
|
||||
|
@ -0,0 +1,6 @@
|
||||
namespace AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Интерфейс маркер для доменных событий
|
||||
/// </summary>
|
||||
public interface IIntegrationEvent { }
|
@ -0,0 +1,19 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
|
||||
/// <summary>
|
||||
/// Обработчик событий
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface IIntegrationEventHandler<in T> where T: IIntegrationEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Метод обработки события
|
||||
/// </summary>
|
||||
/// <param name="integrationEvent"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
Task HandleAsync(T integrationEvent, CancellationToken cancellationToken);
|
||||
}
|
9
AsbCloudApp/IntegrationEvents/UpdateWellInfoEvent.cs
Normal file
9
AsbCloudApp/IntegrationEvents/UpdateWellInfoEvent.cs
Normal file
@ -0,0 +1,9 @@
|
||||
using AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
|
||||
namespace AsbCloudApp.IntegrationEvents;
|
||||
|
||||
/// <summary>
|
||||
/// Обновление показателей бурения
|
||||
/// </summary>
|
||||
/// <param name="IdWell"></param>
|
||||
public record UpdateWellInfoEvent(int IdWell) : IIntegrationEvent;
|
@ -230,11 +230,15 @@ namespace AsbCloudInfrastructure.Services.Subsystems
|
||||
|
||||
var beginUTC = gtDate.HasValue
|
||||
? gtDate.Value.ToUtcDateTimeOffset(hoursOffset)
|
||||
: DateTime.Today.AddDays(-1).ToUtcDateTimeOffset(hoursOffset);
|
||||
: db.SubsystemOperationTimes.Min(s => s.DateStart)
|
||||
.DateTime
|
||||
.ToUtcDateTimeOffset(hoursOffset);
|
||||
|
||||
var endUTC = ltDate.HasValue
|
||||
? ltDate.Value.ToUtcDateTimeOffset(hoursOffset)
|
||||
: DateTime.Today.ToUtcDateTimeOffset(hoursOffset);
|
||||
: db.SubsystemOperationTimes.Max(s => s.DateEnd)
|
||||
.DateTime
|
||||
.ToUtcDateTimeOffset(hoursOffset);
|
||||
|
||||
var telemetryIds = wells
|
||||
.Where(w => w.IdTelemetry is not null)
|
||||
|
@ -6,7 +6,6 @@ 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;
|
||||
@ -16,6 +15,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.IntegrationEvents;
|
||||
using AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
|
||||
namespace AsbCloudInfrastructure.Services
|
||||
{
|
||||
@ -36,7 +37,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
private readonly IWitsRecordRepository<Record1Dto> witsRecord1Repository;
|
||||
private readonly IGtrRepository gtrRepository;
|
||||
private static IEnumerable<WellMapInfoWithComanies> WellMapInfo = Enumerable.Empty<WellMapInfoWithComanies>();
|
||||
|
||||
|
||||
public WellInfoService(
|
||||
TelemetryDataCache<TelemetryDataSaubDto> telemetryDataSaubCache,
|
||||
TelemetryDataCache<TelemetryDataSpinDto> telemetryDataSpinCache,
|
||||
@ -63,23 +64,18 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
private static async Task WorkAction(string workName, IServiceProvider serviceProvider, CancellationToken token)
|
||||
{
|
||||
var db = serviceProvider.GetRequiredService<IAsbCloudDbContext>();
|
||||
var wellService = serviceProvider.GetRequiredService<IWellService>();
|
||||
var operationsStatService = serviceProvider.GetRequiredService<IOperationsStatService>();
|
||||
var processMapRepository = serviceProvider.GetRequiredService<IProcessMapPlanRepository>();
|
||||
var subsystemOperationTimeService = serviceProvider.GetRequiredService<ISubsystemOperationTimeService>();
|
||||
var telemetryDataSaubCache = serviceProvider.GetRequiredService<TelemetryDataCache<TelemetryDataSaubDto>>();
|
||||
var messageHub = serviceProvider.GetRequiredService<IIntegrationEventHandler<UpdateWellInfoEvent>>();
|
||||
|
||||
var activeWells = await wellService.GetAsync(new() {IdState = 1}, token);
|
||||
var wells = await wellService.GetAllAsync(token);
|
||||
|
||||
IEnumerable<int> activeWellsIds = activeWells
|
||||
.Select(w => w.Id);
|
||||
var wellsIds = wells.Select(w => w.Id);
|
||||
|
||||
var idTelemetries = activeWells
|
||||
.Where(w => w.IdTelemetry != null)
|
||||
.Select(t => t.IdTelemetry);
|
||||
|
||||
var processMapRequests = activeWellsIds.Select(id => new ProcessMapRequest { IdWell = id });
|
||||
var processMapRequests = wellsIds.Select(id => new ProcessMapRequest { IdWell = id });
|
||||
var processMaps = await processMapRepository.GetProcessMapAsync(processMapRequests, token);
|
||||
|
||||
var wellDepthByProcessMap = processMaps
|
||||
@ -90,20 +86,23 @@ namespace AsbCloudInfrastructure.Services
|
||||
DepthEnd = g.Max(p => p.DepthEnd)
|
||||
});
|
||||
|
||||
var operationsStat = await operationsStatService.GetWellsStatAsync(activeWellsIds, token);
|
||||
var operationsStat = await operationsStatService.GetWellsStatAsync(wellsIds, token);
|
||||
|
||||
var subsystemStat = await subsystemOperationTimeService.GetStatByActiveWells(activeWellsIds, token);
|
||||
var subsystemStat = await subsystemOperationTimeService
|
||||
.GetStatByActiveWells(wellsIds, token);
|
||||
|
||||
WellMapInfo = activeWells.Select(well => {
|
||||
WellMapInfo = wells.Select(well => {
|
||||
var wellMapInfo = well.Adapt<WellMapInfoWithComanies>();
|
||||
wellMapInfo.IdState = well.IdState;
|
||||
|
||||
double? currentDepth = null;
|
||||
|
||||
TelemetryDataSaubDto? lastSaubTelemetry = null;
|
||||
|
||||
if (well.IdTelemetry.HasValue)
|
||||
{
|
||||
wellMapInfo.IdTelemetry = well.IdTelemetry.Value;
|
||||
var lastSaubTelemetry = telemetryDataSaubCache.GetLastOrDefault(well.IdTelemetry.Value);
|
||||
lastSaubTelemetry = telemetryDataSaubCache.GetLastOrDefault(well.IdTelemetry.Value);
|
||||
if(lastSaubTelemetry is not null)
|
||||
{
|
||||
currentDepth = lastSaubTelemetry.WellDepth;
|
||||
@ -119,27 +118,54 @@ namespace AsbCloudInfrastructure.Services
|
||||
.OrderBy(p => p.DepthEnd);
|
||||
|
||||
int? idSection = wellLastFactSection?.Id;
|
||||
ProcessMapPlanDto? welllProcessMap = null;
|
||||
ProcessMapPlanDto? wellProcessMap = null;
|
||||
|
||||
if (idSection.HasValue)
|
||||
{
|
||||
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection);
|
||||
wellProcessMap = wellProcessMaps.FirstOrDefault(p => p.IdWellSectionType == idSection);
|
||||
}
|
||||
else if(currentDepth.HasValue)
|
||||
{
|
||||
welllProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value);
|
||||
idSection ??= welllProcessMap?.IdWellSectionType;
|
||||
wellProcessMap = wellProcessMaps.FirstOrDefault(p => p.DepthStart <= currentDepth.Value && p.DepthEnd >= currentDepth.Value);
|
||||
}
|
||||
|
||||
double? planTotalDepth = null;
|
||||
planTotalDepth = wellDepthByProcessMap.FirstOrDefault(p => p.Id == well.Id)?.DepthEnd;
|
||||
planTotalDepth ??= wellOperationsStat?.Total.Plan?.WellDepthEnd;
|
||||
|
||||
wellMapInfo.Section = wellLastFactSection?.Caption;
|
||||
|
||||
wellMapInfo.FirstFactOperationDateStart = wellOperationsStat?.Total.Fact?.Start
|
||||
?? wellOperationsStat?.Total.Plan?.Start;
|
||||
|
||||
wellMapInfo.LastPredictOperationDateEnd = wellOperationsStat?.Total.Plan?.End;
|
||||
|
||||
wellMapInfo.AxialLoad = new()
|
||||
{
|
||||
Plan = wellProcessMap?.AxialLoad.Plan,
|
||||
Fact = lastSaubTelemetry?.AxialLoad
|
||||
};
|
||||
|
||||
wellMapInfo.TopDriveSpeed = new()
|
||||
{
|
||||
Plan = wellProcessMap?.TopDriveSpeed.Plan,
|
||||
Fact = lastSaubTelemetry?.RotorSpeed
|
||||
};
|
||||
|
||||
wellMapInfo.TopDriveTorque = new()
|
||||
{
|
||||
Plan = wellProcessMap?.TopDriveTorque.Plan,
|
||||
Fact = lastSaubTelemetry?.RotorTorque
|
||||
};
|
||||
|
||||
wellMapInfo.Pressure = new()
|
||||
{
|
||||
Plan = wellProcessMap?.Pressure.Plan,
|
||||
Fact = lastSaubTelemetry?.Pressure
|
||||
};
|
||||
|
||||
wellMapInfo.PressureSp = lastSaubTelemetry?.PressureSp;
|
||||
|
||||
wellMapInfo.WellDepth = new()
|
||||
{
|
||||
Plan = planTotalDepth,
|
||||
@ -148,7 +174,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
wellMapInfo.ROP = new()
|
||||
{
|
||||
Plan = welllProcessMap?.RopPlan,
|
||||
Plan = wellProcessMap?.RopPlan,
|
||||
Fact = wellOperationsStat?.Total.Fact?.Rop,
|
||||
};
|
||||
|
||||
@ -167,6 +193,11 @@ namespace AsbCloudInfrastructure.Services
|
||||
|
||||
return wellMapInfo;
|
||||
}).ToArray();
|
||||
|
||||
var updateWellInfoEventTasks = wellsIds.Select(idWell =>
|
||||
messageHub.HandleAsync(new UpdateWellInfoEvent(idWell), token));
|
||||
|
||||
await Task.WhenAll(updateWellInfoEventTasks);
|
||||
}
|
||||
|
||||
private WellMapInfoWithTelemetryStat Convert(WellMapInfoWithComanies wellInfo)
|
||||
|
@ -92,7 +92,7 @@ namespace AsbCloudInfrastructure.Services
|
||||
Longitude = gCluster.Key.Longitude ?? gDeposit.Key.Longitude,
|
||||
Wells = gCluster.Select(well =>
|
||||
{
|
||||
var dto = wellInfoService.FirstOrDefault(w => w.Id == well.Id);
|
||||
var dto = wellInfoService.FirstOrDefault(w => w.Id == well.Id && well.IdState == 1);
|
||||
dto ??= well.Adapt<WellMapInfoWithTelemetryStat>();
|
||||
dto.Latitude ??= gCluster.Key.Latitude ?? gDeposit.Key.Latitude;
|
||||
dto.Longitude ??= gCluster.Key.Longitude ?? gDeposit.Key.Longitude;
|
||||
|
@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
IWellOperationImportService wellOperationImportService,
|
||||
IUserRepository userRepository)
|
||||
{
|
||||
this.operationRepository = operationService;
|
||||
this.operationRepository = operationRepository;
|
||||
this.wellService = wellService;
|
||||
this.wellOperationImportService = wellOperationImportService;
|
||||
this.userRepository = userRepository;
|
||||
@ -218,7 +218,7 @@ namespace AsbCloudWebApi.Controllers
|
||||
|
||||
var result = await operationRepository.InsertRangeAsync(values, token)
|
||||
.ConfigureAwait(false);
|
||||
|
||||
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,6 @@ using AsbCloudApp.Repositories;
|
||||
using AsbCloudDb.Model;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Microsoft.OpenApi.Models;
|
||||
@ -12,9 +11,13 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.IntegrationEvents;
|
||||
using AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
using AsbCloudApp.Services.Notifications;
|
||||
using AsbCloudInfrastructure.Services.Email;
|
||||
using AsbCloudWebApi.SignalR;
|
||||
using AsbCloudWebApi.SignalR.Services;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.OpenApi.Any;
|
||||
|
||||
namespace AsbCloudWebApi
|
||||
@ -144,5 +147,8 @@ namespace AsbCloudWebApi
|
||||
|
||||
services.AddTransient<NotificationPublisher>();
|
||||
}
|
||||
|
||||
public static void AddIntegrationEvents(this IServiceCollection services) => services
|
||||
.AddTransient<IIntegrationEventHandler<UpdateWellInfoEvent>, WellInfoHub>();
|
||||
}
|
||||
}
|
||||
|
53
AsbCloudWebApi/SignalR/WellInfoHub.cs
Normal file
53
AsbCloudWebApi/SignalR/WellInfoHub.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using AsbCloudApp.IntegrationEvents;
|
||||
using AsbCloudApp.IntegrationEvents.Interfaces;
|
||||
using AsbCloudApp.Services;
|
||||
using AsbCloudInfrastructure.Services;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
|
||||
namespace AsbCloudWebApi.SignalR;
|
||||
|
||||
public class WellInfoHub : BaseHub, IIntegrationEventHandler<UpdateWellInfoEvent>
|
||||
{
|
||||
private readonly IHubContext<WellInfoHub> hubContext;
|
||||
private readonly IWellService wellService;
|
||||
private readonly WellInfoService wellInfoService;
|
||||
|
||||
public WellInfoHub(IHubContext<WellInfoHub> hubContext,
|
||||
IWellService wellService,
|
||||
WellInfoService wellInfoService)
|
||||
{
|
||||
this.hubContext = hubContext;
|
||||
this.wellService = wellService;
|
||||
this.wellInfoService = wellInfoService;
|
||||
}
|
||||
|
||||
public override async Task AddToGroup(string groupName)
|
||||
{
|
||||
var idWell = int.Parse(groupName.Split('_')[2]);
|
||||
|
||||
await Groups.AddToGroupAsync(Context.ConnectionId, groupName);
|
||||
|
||||
await HandleAsync(new UpdateWellInfoEvent(idWell), CancellationToken.None);
|
||||
}
|
||||
|
||||
public async Task HandleAsync(UpdateWellInfoEvent integrationEvent, CancellationToken cancellationToken)
|
||||
{
|
||||
const string method = "update_well_info";
|
||||
|
||||
var well = await wellService.GetOrDefaultAsync(integrationEvent.IdWell, cancellationToken);
|
||||
|
||||
if(well is null)
|
||||
return;
|
||||
|
||||
var wellInfo = wellInfoService.FirstOrDefault(w => w.Id == well.Id);
|
||||
|
||||
await hubContext.Clients.Group($"well_info_{integrationEvent.IdWell}")
|
||||
.SendAsync(method, new
|
||||
{
|
||||
Well = well,
|
||||
WellInfo = wellInfo
|
||||
}, cancellationToken);
|
||||
}
|
||||
}
|
@ -45,6 +45,8 @@ namespace AsbCloudWebApi
|
||||
|
||||
services.AddNotificationTransportServices();
|
||||
|
||||
services.AddIntegrationEvents();
|
||||
|
||||
services.AddJWTAuthentication();
|
||||
|
||||
services.AddSignalR()
|
||||
@ -151,6 +153,7 @@ namespace AsbCloudWebApi
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
endpoints.MapHub<WellInfoHub>("/hubs/wellInfo");
|
||||
endpoints.MapHub<NotificationHub>("/hubs/notifications");
|
||||
endpoints.MapHub<TelemetryHub>("/hubs/telemetry");
|
||||
endpoints.MapHub<ReportsHub>("/hubs/reports");
|
||||
|
@ -10,7 +10,7 @@ internal class Program
|
||||
{
|
||||
var connectionBuilder = new HubConnectionBuilder();
|
||||
var connection = connectionBuilder
|
||||
.WithUrl("http://localhost:5000/hubs/notifications", connectionOptions => {
|
||||
.WithUrl("http://localhost:5000/hubs/limitingParameters", connectionOptions => {
|
||||
connectionOptions.AccessTokenProvider = AccessTokenProvider;
|
||||
})
|
||||
.WithAutomaticReconnect()
|
||||
@ -26,9 +26,9 @@ internal class Program
|
||||
connection.StartAsync().Wait();
|
||||
|
||||
//Console.WriteLine("OnConnected");
|
||||
//connection.SendCoreAsync("OnConnected", new object[] { }, CancellationToken.None).Wait();
|
||||
connection.SendCoreAsync("OnConnectedAsync", new object[] { 1 }, CancellationToken.None).Wait();
|
||||
|
||||
var subsction = connection.On<object>("receiveNotifications", (str1) => {
|
||||
var subsction = connection.On<object>("well_info_update", (str1) => {
|
||||
Console.WriteLine(str1);
|
||||
} );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user