forked from ddrilling/AsbCloudServer
1. Критические сообщения
2. Рефакторинг кода, связанного с сообщениями
This commit is contained in:
parent
9ebd3f4851
commit
cdb6ed7390
@ -7,6 +7,13 @@ namespace AsbCloudApp.Data.SAUB;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TelemetryMessageDto : IId
|
public class TelemetryMessageDto : IId
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
public TelemetryMessageDto()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Id сообщения в базе панели оператора
|
/// Id сообщения в базе панели оператора
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -51,4 +58,9 @@ public class TelemetryMessageDto : IId
|
|||||||
/// аргумент №3 для подстановки в шаблон сообщения
|
/// аргумент №3 для подстановки в шаблон сообщения
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Arg3 { get; set; }
|
public string? Arg3 { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ключ телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public int IdTelemetry { get; set; }
|
||||||
}
|
}
|
||||||
|
31
AsbCloudApp/Repositories/IEventRepository.cs
Normal file
31
AsbCloudApp/Repositories/IEventRepository.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Repositories;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Репозиторий по работе с событиями
|
||||||
|
/// </summary>
|
||||||
|
public interface IEventRepository
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// получение списка событий по параметрам запроса
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request">параметры запроса</param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Сохранить. Добавить или заменить.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid"></param>
|
||||||
|
/// <param name="dtos"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
||||||
|
CancellationToken token = default);
|
||||||
|
}
|
41
AsbCloudApp/Repositories/IMessageRepository.cs
Normal file
41
AsbCloudApp/Repositories/IMessageRepository.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Repositories;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Репозиторий по работе с сообщениями панели оператора
|
||||||
|
/// </summary>
|
||||||
|
public interface IMessageRepository : ITelemetryDataEditorService
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Получить PaginationContainer с сообщениями по параметрам
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<PaginationContainer<MessageDto>> GetPaginatedMessagesAsync(MessageTelemetryRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Получить сообщения по параметрам
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task<IEnumerable<TelemetryMessageDto>> GetMessagesAsync(MessageTelemetryRequest request, CancellationToken token);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Метод для сохранения сообщения от панели
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="uid"></param>
|
||||||
|
/// <param name="dtos"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
||||||
|
CancellationToken token);
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@ -11,7 +13,7 @@ public class MessageRequestBase : RequestBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// категория
|
/// категория
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<int>? Categoryids { get; set; }
|
public IEnumerable<int>? IdsCategories { get; set; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -29,29 +31,13 @@ public class MessageRequestBase : RequestBase
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public string? SearchString { get; set; }
|
public string? SearchString { get; set; }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// параметры для запроса списка сообщений (с id скважины)
|
|
||||||
/// </summary>
|
|
||||||
public class MessageRequest : MessageRequestBase
|
|
||||||
{
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// id скважины
|
/// копирующий конструктор
|
||||||
/// </summary>
|
|
||||||
public int IdWell { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// параметры для запроса списка сообщений (с id скважины)
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="idWell"></param>
|
public MessageRequestBase(MessageRequestBase request)
|
||||||
public MessageRequest(MessageRequestBase request, int idWell)
|
|
||||||
{
|
{
|
||||||
this.IdWell = idWell;
|
this.IdsCategories = request.IdsCategories;
|
||||||
|
|
||||||
this.Categoryids = request.Categoryids;
|
|
||||||
this.Begin = request.Begin;
|
this.Begin = request.Begin;
|
||||||
this.End = request.End;
|
this.End = request.End;
|
||||||
this.SearchString = request.SearchString;
|
this.SearchString = request.SearchString;
|
||||||
@ -62,3 +48,49 @@ public class MessageRequest : MessageRequestBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// параметры для запроса списка сообщений (с ids скважин)
|
||||||
|
/// </summary>
|
||||||
|
public class MessageRequest : MessageRequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ids скважин
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int> IdsWell { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// параметры для запроса списка сообщений (с ids скважин)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="idsWell"></param>
|
||||||
|
public MessageRequest(MessageRequestBase request, IEnumerable<int> idsWell) : base(request)
|
||||||
|
{
|
||||||
|
this.IdsWell = idsWell;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// параметры запроса для получения списка сообщений телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public class MessageTelemetryRequest : MessageRequestBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// события
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<TelemetryEventDto> Events { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
public MessageTelemetryRequest(MessageRequestBase request) : base(request)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
28
AsbCloudApp/Requests/TelemetryEventRequest.cs
Normal file
28
AsbCloudApp/Requests/TelemetryEventRequest.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// параметры запроса для получения событий телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public class TelemetryEventRequest
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// ключи телеметрии
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int> IdsTelemetries { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// ключи категорий
|
||||||
|
/// </summary>
|
||||||
|
public IEnumerable<int>? IdsCategories { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// строка поиска
|
||||||
|
/// </summary>
|
||||||
|
public string? SearchString { get; set; }
|
||||||
|
}
|
@ -1,22 +0,0 @@
|
|||||||
using AsbCloudApp.Data.SAUB;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudApp.Services;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Сервис сохранения списка сообщений от панелей
|
|
||||||
/// </summary>
|
|
||||||
public interface IEventService
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Сохранить. Добавить или заменить.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="uid"></param>
|
|
||||||
/// <param name="dtos"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
|
||||||
CancellationToken token = default);
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.SAUB;
|
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -8,25 +7,24 @@ using System.Threading.Tasks;
|
|||||||
namespace AsbCloudApp.Services;
|
namespace AsbCloudApp.Services;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сервис сообщений панели оператора
|
/// Сервис сообщений
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IMessageService : ITelemetryDataEditorService
|
public interface IMessageService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить сообщения по параметрам
|
/// Получить статистику сообщений по параметрам запроса
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<PaginationContainer<MessageDto>> GetMessagesAsync(MessageRequest request, CancellationToken token);
|
Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Метод для сохранения сообщения от панели
|
/// Получить PaginationContainer с сообщениями по параметрам
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="uid"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="dtos"></param>
|
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
Task<PaginationContainer<MessageDto>> GetPaginatedMessagesAsync(MessageRequest request, CancellationToken token);
|
||||||
CancellationToken token);
|
|
||||||
}
|
}
|
@ -47,6 +47,12 @@ public interface ITelemetryService
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
TelemetryBaseDto? GetOrDefaultTelemetryByIdWell(int idWell);
|
TelemetryBaseDto? GetOrDefaultTelemetryByIdWell(int idWell);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// получить список телеметрии по ключам скважин
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="idsWells">ключи скважин</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerable<TelemetryBaseDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// получить диапазон дат за которые есть данные
|
/// получить диапазон дат за которые есть данные
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -291,9 +291,10 @@ public static class DependencyInjection
|
|||||||
services.AddTransient<IAuthService, AuthService>();
|
services.AddTransient<IAuthService, AuthService>();
|
||||||
services.AddTransient<IDepositRepository, DepositRepository>();
|
services.AddTransient<IDepositRepository, DepositRepository>();
|
||||||
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
services.AddTransient<IDrillingProgramService, DrillingProgramService>();
|
||||||
services.AddTransient<IEventService, EventService>();
|
services.AddTransient<IEventRepository, EventRepository>();
|
||||||
services.AddTransient<FileService>();
|
services.AddTransient<FileService>();
|
||||||
services.AddTransient<IMeasureService, MeasureService>();
|
services.AddTransient<IMeasureService, MeasureService>();
|
||||||
|
services.AddTransient<IMessageRepository, MessageRepository>();
|
||||||
services.AddTransient<IMessageService, MessageService>();
|
services.AddTransient<IMessageService, MessageService>();
|
||||||
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
services.AddTransient<IOperationsStatService, OperationsStatService>();
|
||||||
services.AddTransient<IReportService, ReportService>();
|
services.AddTransient<IReportService, ReportService>();
|
||||||
|
71
AsbCloudInfrastructure/Repository/EventRepository.cs
Normal file
71
AsbCloudInfrastructure/Repository/EventRepository.cs
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Repository;
|
||||||
|
|
||||||
|
|
||||||
|
public class EventRepository : IEventRepository
|
||||||
|
{
|
||||||
|
private readonly IAsbCloudDbContext db;
|
||||||
|
private readonly IMemoryCache memoryCache;
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
|
public EventRepository(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService)
|
||||||
|
{
|
||||||
|
this.db = db;
|
||||||
|
this.memoryCache = memoryCache;
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryEvent>(), token);
|
||||||
|
var events = allEvents.Where(e => request.IdsTelemetries.Contains(e.IdTelemetry));
|
||||||
|
|
||||||
|
if (request.IdsCategories?.Any() == true)
|
||||||
|
events = events.Where(e => request.IdsCategories.Contains(e.IdCategory));
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(request.SearchString))
|
||||||
|
events = events.Where(e => e.MessageTemplate.Contains(request.SearchString, StringComparison.OrdinalIgnoreCase));
|
||||||
|
|
||||||
|
var dtos = events.Select(e =>
|
||||||
|
{
|
||||||
|
var dto = new TelemetryEventDto();
|
||||||
|
dto.Id = e.IdEvent;
|
||||||
|
dto.IdCategory = e.IdCategory;
|
||||||
|
dto.MessageTemplate = e.MessageTemplate;
|
||||||
|
return dto;
|
||||||
|
});
|
||||||
|
|
||||||
|
return dtos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
||||||
|
CancellationToken token = default)
|
||||||
|
{
|
||||||
|
if (!dtos.Any())
|
||||||
|
return;
|
||||||
|
|
||||||
|
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
||||||
|
|
||||||
|
var entities = dtos.Select(dto => new TelemetryEvent
|
||||||
|
{
|
||||||
|
IdEvent = dto.Id,
|
||||||
|
IdTelemetry = telemetry.Id,
|
||||||
|
IdCategory = dto.IdCategory,
|
||||||
|
MessageTemplate = dto.Message
|
||||||
|
});
|
||||||
|
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
|
||||||
|
memoryCache.DropBasic<TelemetryEvent>();
|
||||||
|
}
|
||||||
|
}
|
87
AsbCloudInfrastructure/Services/MessageService.cs
Normal file
87
AsbCloudInfrastructure/Services/MessageService.cs
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
|
using AsbCloudApp.Requests;
|
||||||
|
using AsbCloudApp.Services;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace AsbCloudInfrastructure.Services;
|
||||||
|
|
||||||
|
|
||||||
|
public class MessageService : IMessageService
|
||||||
|
{
|
||||||
|
private readonly IMessageRepository messageRepository;
|
||||||
|
private readonly ITelemetryService telemetryService;
|
||||||
|
private readonly IEventRepository eventRepository;
|
||||||
|
|
||||||
|
public MessageService(
|
||||||
|
IMessageRepository messageRepository,
|
||||||
|
ITelemetryService telemetryService,
|
||||||
|
IEventRepository eventRepository)
|
||||||
|
{
|
||||||
|
this.messageRepository = messageRepository;
|
||||||
|
this.telemetryService = telemetryService;
|
||||||
|
this.eventRepository = eventRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<MessageDto>> GetPaginatedMessagesAsync(MessageRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
|
||||||
|
|
||||||
|
var result = await messageRepository.GetPaginatedMessagesAsync(messageTelemetryRequest, token);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
|
||||||
|
|
||||||
|
var telemetryMessages = await messageRepository.GetMessagesAsync(messageTelemetryRequest, token);
|
||||||
|
|
||||||
|
var groupedMessages = telemetryMessages.GroupBy(x => new { x.IdTelemetry, x.IdEvent });
|
||||||
|
var events = messageTelemetryRequest.Events.ToDictionary(e => e.Id);
|
||||||
|
|
||||||
|
var result = groupedMessages
|
||||||
|
.Select(m => new
|
||||||
|
{
|
||||||
|
m.Key.IdTelemetry,
|
||||||
|
events.GetValueOrDefault(m.Key.IdEvent)?.IdCategory,
|
||||||
|
events.GetValueOrDefault(m.Key.IdEvent)?.MessageTemplate,
|
||||||
|
Count = m.Count()
|
||||||
|
})
|
||||||
|
.Where(m => m.IdCategory != null)
|
||||||
|
.Where(m => m.MessageTemplate != null)
|
||||||
|
.GroupBy(m => new { m.IdTelemetry, m.IdCategory, m.MessageTemplate })
|
||||||
|
.Select(m => new StatCriticalMessageDto()
|
||||||
|
{
|
||||||
|
IdTelemetry = m.Key.IdTelemetry,
|
||||||
|
IdCategory = m.Key.IdCategory,
|
||||||
|
MessageTemplate = m.Key.MessageTemplate,
|
||||||
|
MessagesCount = m.Select(z => z.Count).Sum()
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<MessageTelemetryRequest> CreateMessageTelemetryRequest(MessageRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var telemetries = telemetryService.GetOrDefaultTelemetriesByIdsWells(request.IdsWell);
|
||||||
|
|
||||||
|
var telemetryEventRequest = new TelemetryEventRequest()
|
||||||
|
{
|
||||||
|
IdsTelemetries = telemetries.Select(t => t.Id),
|
||||||
|
IdsCategories = request.IdsCategories,
|
||||||
|
SearchString = request.SearchString,
|
||||||
|
};
|
||||||
|
|
||||||
|
var messageTelemetryRequest = new MessageTelemetryRequest(request);
|
||||||
|
messageTelemetryRequest.Telemetries = telemetries;
|
||||||
|
messageTelemetryRequest.Events = await eventRepository.Get(telemetryEventRequest, token);
|
||||||
|
|
||||||
|
return messageTelemetryRequest;
|
||||||
|
}
|
||||||
|
}
|
@ -1,45 +0,0 @@
|
|||||||
using AsbCloudApp.Data.SAUB;
|
|
||||||
using AsbCloudApp.Services;
|
|
||||||
using AsbCloudDb;
|
|
||||||
using AsbCloudDb.Model;
|
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.SAUB;
|
|
||||||
|
|
||||||
|
|
||||||
public class EventService : IEventService
|
|
||||||
{
|
|
||||||
private readonly IAsbCloudDbContext db;
|
|
||||||
private readonly IMemoryCache memoryCache;
|
|
||||||
private readonly ITelemetryService telemetryService;
|
|
||||||
|
|
||||||
public EventService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService)
|
|
||||||
{
|
|
||||||
this.db = db;
|
|
||||||
this.memoryCache = memoryCache;
|
|
||||||
this.telemetryService = telemetryService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public async Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
|
||||||
CancellationToken token = default)
|
|
||||||
{
|
|
||||||
if (!dtos.Any())
|
|
||||||
return;
|
|
||||||
|
|
||||||
var telemetry = telemetryService.GetOrCreateTelemetryByUid(uid);
|
|
||||||
|
|
||||||
var entities = dtos.Select(dto => new TelemetryEvent
|
|
||||||
{
|
|
||||||
IdEvent = dto.Id,
|
|
||||||
IdTelemetry = telemetry.Id,
|
|
||||||
IdCategory = dto.IdCategory,
|
|
||||||
MessageTemplate = dto.Message
|
|
||||||
});
|
|
||||||
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
|
|
||||||
memoryCache.DropBasic<TelemetryEvent>();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +1,17 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudDb;
|
using AsbCloudDb;
|
||||||
using AsbCloudDb.Model;
|
using AsbCloudDb.Model;
|
||||||
|
using DocumentFormat.OpenXml.Bibliography;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Internal;
|
||||||
using Microsoft.Extensions.Caching.Memory;
|
using Microsoft.Extensions.Caching.Memory;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@ -16,20 +21,31 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace AsbCloudInfrastructure.Services.SAUB;
|
namespace AsbCloudInfrastructure.Services.SAUB;
|
||||||
|
|
||||||
public class MessageService : IMessageService
|
public class MessageRepository : IMessageRepository
|
||||||
{
|
{
|
||||||
private readonly IAsbCloudDbContext db;
|
private readonly IAsbCloudDbContext db;
|
||||||
private readonly IMemoryCache memoryCache;
|
private readonly IMemoryCache memoryCache;
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
|
|
||||||
public MessageService(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService)
|
public MessageRepository(IAsbCloudDbContext db, IMemoryCache memoryCache, ITelemetryService telemetryService)
|
||||||
{
|
{
|
||||||
this.db = db;
|
this.db = db;
|
||||||
this.memoryCache = memoryCache;
|
this.memoryCache = memoryCache;
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<PaginationContainer<MessageDto>> GetMessagesAsync(MessageRequest request, CancellationToken token)
|
public async Task<IEnumerable<TelemetryMessageDto>> GetMessagesAsync(MessageTelemetryRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var query = BuildQuery(request, token);
|
||||||
|
|
||||||
|
var entities = await query.ToArrayAsync(token);
|
||||||
|
|
||||||
|
var dtos = entities.Select(m => m.Adapt<TelemetryMessageDto>());
|
||||||
|
|
||||||
|
return dtos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginationContainer<MessageDto>> GetPaginatedMessagesAsync(MessageTelemetryRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = new PaginationContainer<MessageDto>
|
var result = new PaginationContainer<MessageDto>
|
||||||
{
|
{
|
||||||
@ -37,36 +53,86 @@ public class MessageService : IMessageService
|
|||||||
Take = request.Take ?? 32,
|
Take = request.Take ?? 32,
|
||||||
};
|
};
|
||||||
|
|
||||||
var telemetry = telemetryService.GetOrDefaultTelemetryByIdWell(request.IdWell);
|
if (request.Telemetries.IsNullOrEmpty() || request.Events.IsNullOrEmpty())
|
||||||
if (telemetry is null)
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryEvent>(), token);
|
var query = BuildQuery(request, token);
|
||||||
var events = allEvents.Where(e => e.IdTelemetry == telemetry.Id);
|
|
||||||
|
|
||||||
if (!events.Any())
|
if (request.SortFields?.Any() == true)
|
||||||
return result;
|
|
||||||
|
|
||||||
var query = db.TelemetryMessages.Where(m => m.IdTelemetry == telemetry.Id)
|
|
||||||
.OrderBy(m => m.DateTime).AsNoTracking();
|
|
||||||
|
|
||||||
if (request.Categoryids?.Any() == true || !string.IsNullOrEmpty(request.SearchString))
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(request.SearchString))
|
query = query.SortBy(request.SortFields);
|
||||||
events = events.Where(e => e.MessageTemplate.Contains(request.SearchString, StringComparison.OrdinalIgnoreCase));
|
|
||||||
|
|
||||||
if (request.Categoryids?.Any() == true)
|
|
||||||
events = events.Where(e => request.Categoryids.ToList().Contains(e.IdCategory));
|
|
||||||
|
|
||||||
var eventIds = events.Select(e => e.IdEvent);
|
|
||||||
|
|
||||||
if (!eventIds.Any())
|
|
||||||
return result;
|
|
||||||
|
|
||||||
query = query.Where(m => eventIds.Contains(m.IdEvent));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
query = query.OrderByDescending(m => m.DateTime);
|
result.Count = query.Count();
|
||||||
|
|
||||||
|
var messagesList = await query
|
||||||
|
.Skip(result.Skip)
|
||||||
|
.Take(result.Take)
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
|
if (messagesList.Count() == 0)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var allUsers = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryUser>(), token);
|
||||||
|
var users = allUsers.Where(u => request.Telemetries!.Select(t => t.Id).Contains(u.IdTelemetry));
|
||||||
|
|
||||||
|
if (!request.Events.Any())
|
||||||
|
return result;
|
||||||
|
|
||||||
|
var eventsDict = request.Events.ToDictionary(x => x.Id);
|
||||||
|
var usersDict = users.ToDictionary(x => x.IdUser, x => x);
|
||||||
|
|
||||||
|
var messagesDtoList = new List<MessageDto>();
|
||||||
|
|
||||||
|
foreach (var message in messagesList)
|
||||||
|
{
|
||||||
|
var messageDto = new MessageDto
|
||||||
|
{
|
||||||
|
Id = message.Id,
|
||||||
|
WellDepth = message.WellDepth,
|
||||||
|
};
|
||||||
|
|
||||||
|
var telemetry = request.Telemetries.Where(t => t.Id == message.IdTelemetry).FirstOrDefault();
|
||||||
|
|
||||||
|
if(telemetry != null && telemetry.TimeZone != null)
|
||||||
|
messageDto.DateTime = message.DateTime.ToOffset(TimeSpan.FromHours(telemetry.TimeZone.Hours));
|
||||||
|
|
||||||
|
if (message.IdTelemetryUser is not null)
|
||||||
|
{
|
||||||
|
if (usersDict.TryGetValue((int)message.IdTelemetryUser, out TelemetryUser? user))
|
||||||
|
{
|
||||||
|
messageDto.User = user.MakeDisplayName();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
messageDto.User = message.IdTelemetryUser.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventsDict.TryGetValue(message.IdEvent, out TelemetryEventDto? e))
|
||||||
|
{
|
||||||
|
messageDto.CategoryId = e.IdCategory;
|
||||||
|
messageDto.Message = e.MakeMessageText([
|
||||||
|
message.Arg0,
|
||||||
|
message.Arg1,
|
||||||
|
message.Arg2,
|
||||||
|
message.Arg3
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
messagesDtoList.Add(messageDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
result.Items = result.Items.Concat(messagesDtoList);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public IQueryable<TelemetryMessage> BuildQuery(MessageTelemetryRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var idsTelemetries = request.Telemetries.Select(t => t.Id);
|
||||||
|
var eventIds = request.Events.Select(e => e.Id);
|
||||||
|
|
||||||
|
var query = db.TelemetryMessages
|
||||||
|
.Where(m => idsTelemetries.Contains(m.IdTelemetry))
|
||||||
|
.Where(m => eventIds.Contains(m.IdEvent));
|
||||||
|
|
||||||
if (request.Begin is not null)
|
if (request.Begin is not null)
|
||||||
{
|
{
|
||||||
@ -80,59 +146,9 @@ public class MessageService : IMessageService
|
|||||||
query = query.Where(m => m.DateTime <= endUtc);
|
query = query.Where(m => m.DateTime <= endUtc);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Count = query.Count();
|
query = query.OrderByDescending(m => m.DateTime);
|
||||||
|
|
||||||
if (request.SortFields?.Any() == true)
|
return query;
|
||||||
{
|
|
||||||
query = query.SortBy(request.SortFields);
|
|
||||||
}
|
|
||||||
var messagesList = await query.Skip(result.Skip)
|
|
||||||
.Take(result.Take).AsNoTracking()
|
|
||||||
.ToListAsync(token).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (messagesList.Count == 0)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
var allUsers = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryUser>(), token);
|
|
||||||
var users = allUsers.Where(u => u.IdTelemetry == telemetry.Id);
|
|
||||||
|
|
||||||
var eventsDict = events.ToDictionary(x => x.IdEvent, x => x);
|
|
||||||
var usersDict = users.ToDictionary(x => x.IdUser, x => x);
|
|
||||||
|
|
||||||
var messagesDtoList = new List<MessageDto>();
|
|
||||||
var timezone = telemetryService.GetTimezone(telemetry.Id);
|
|
||||||
|
|
||||||
foreach (var message in messagesList)
|
|
||||||
{
|
|
||||||
var messageDto = new MessageDto
|
|
||||||
{
|
|
||||||
Id = message.Id,
|
|
||||||
WellDepth = message.WellDepth
|
|
||||||
};
|
|
||||||
|
|
||||||
messageDto.DateTime = message.DateTime.ToOffset(TimeSpan.FromHours(timezone.Hours));
|
|
||||||
|
|
||||||
if (message.IdTelemetryUser is not null)
|
|
||||||
{
|
|
||||||
if (usersDict.TryGetValue((int)message.IdTelemetryUser, out TelemetryUser? user))
|
|
||||||
{
|
|
||||||
messageDto.User = user.MakeDisplayName();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
messageDto.User = message.IdTelemetryUser.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (eventsDict.TryGetValue(message.IdEvent, out TelemetryEvent? e))
|
|
||||||
{
|
|
||||||
messageDto.CategoryId = e.IdCategory;
|
|
||||||
messageDto.Message = e.MakeMessageText(message);
|
|
||||||
}
|
|
||||||
messagesDtoList.Add(messageDto);
|
|
||||||
}
|
|
||||||
|
|
||||||
result.Items = result.Items.Concat(messagesDtoList);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
public Task InsertAsync(string uid, IEnumerable<TelemetryMessageDto> dtos,
|
@ -21,7 +21,7 @@ public class TelemetryDataEditorService : ITelemetryDataEditorService
|
|||||||
/// <param name="dataSaubService"></param>
|
/// <param name="dataSaubService"></param>
|
||||||
/// <param name="dataSpinService"></param>
|
/// <param name="dataSpinService"></param>
|
||||||
/// <param name="dataSaubStatRepository"></param>
|
/// <param name="dataSaubStatRepository"></param>
|
||||||
/// <param name="messageService"></param>
|
/// <param name="messageRepository"></param>
|
||||||
/// <param name="drillTestRepository"></param>
|
/// <param name="drillTestRepository"></param>
|
||||||
/// <param name="limitingParameterRepository"></param>
|
/// <param name="limitingParameterRepository"></param>
|
||||||
/// <param name="detectedOperationRepository"></param>
|
/// <param name="detectedOperationRepository"></param>
|
||||||
@ -36,7 +36,7 @@ public class TelemetryDataEditorService : ITelemetryDataEditorService
|
|||||||
ITelemetryDataSaubService dataSaubService,
|
ITelemetryDataSaubService dataSaubService,
|
||||||
ITelemetryDataService<TelemetryDataSpinDto> dataSpinService,
|
ITelemetryDataService<TelemetryDataSpinDto> dataSpinService,
|
||||||
IDataSaubStatRepository dataSaubStatRepository,
|
IDataSaubStatRepository dataSaubStatRepository,
|
||||||
IMessageService messageService,
|
IMessageRepository messageRepository,
|
||||||
IDrillTestRepository drillTestRepository,
|
IDrillTestRepository drillTestRepository,
|
||||||
ILimitingParameterRepository limitingParameterRepository,
|
ILimitingParameterRepository limitingParameterRepository,
|
||||||
IDetectedOperationRepository detectedOperationRepository,
|
IDetectedOperationRepository detectedOperationRepository,
|
||||||
@ -54,7 +54,7 @@ public class TelemetryDataEditorService : ITelemetryDataEditorService
|
|||||||
dataSaubService,
|
dataSaubService,
|
||||||
dataSpinService,
|
dataSpinService,
|
||||||
dataSaubStatRepository,
|
dataSaubStatRepository,
|
||||||
messageService,
|
messageRepository,
|
||||||
drillTestRepository,
|
drillTestRepository,
|
||||||
limitingParameterRepository,
|
limitingParameterRepository,
|
||||||
detectedOperationRepository,
|
detectedOperationRepository,
|
||||||
|
@ -144,15 +144,27 @@ public class TelemetryService : ITelemetryService
|
|||||||
|
|
||||||
public TelemetryBaseDto? GetOrDefaultTelemetryByIdWell(int idWell)
|
public TelemetryBaseDto? GetOrDefaultTelemetryByIdWell(int idWell)
|
||||||
{
|
{
|
||||||
var entity = GetTelemetryCache()
|
var dto = GetOrDefaultTelemetriesByIdsWells([idWell])
|
||||||
.FirstOrDefault(t => t.Well?.Id == idWell);
|
.FirstOrDefault();
|
||||||
|
|
||||||
if (entity?.Well?.Timezone is not null && entity.TimeZone.Hours != entity.Well.Timezone.Hours)
|
return dto;
|
||||||
{
|
|
||||||
entity.TimeZone = entity.Well.Timezone;
|
|
||||||
//TODO: выдаем предупреждение!
|
|
||||||
}
|
}
|
||||||
return entity?.Adapt<TelemetryBaseDto>();
|
|
||||||
|
public IEnumerable<TelemetryBaseDto> GetOrDefaultTelemetriesByIdsWells(IEnumerable<int> idsWells)
|
||||||
|
{
|
||||||
|
var entities = GetTelemetryCache()
|
||||||
|
.Where(t => t.Well != null)
|
||||||
|
.Where(t => idsWells.Contains(t.Well!.Id))
|
||||||
|
.Select(t => {
|
||||||
|
t.TimeZone = t.TimeZone.Hours != t.Well!.Timezone.Hours ? t.Well.Timezone : t.TimeZone;
|
||||||
|
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
var dtos = entities.Select(t => t.Adapt<TelemetryBaseDto>());
|
||||||
|
|
||||||
|
return dtos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TelemetryDto GetOrCreateTelemetryByUid(string uid)
|
public TelemetryDto GetOrCreateTelemetryByUid(string uid)
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using AsbCloudApp.Data;
|
using AsbCloudApp.Data;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Requests;
|
using AsbCloudApp.Requests;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
|
using AsbCloudDb.Model;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@ -14,13 +17,18 @@ namespace AsbCloudWebApi.Controllers.SAUB;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class MessageController : ControllerBase
|
public class MessageController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly IMessageService messageService;
|
private readonly IMessageRepository messageRepository;
|
||||||
private readonly IWellService wellService;
|
private readonly IWellService wellService;
|
||||||
|
private readonly IMessageService messageService;
|
||||||
|
|
||||||
public MessageController(IMessageService messageService, IWellService wellService)
|
public MessageController(
|
||||||
|
IMessageRepository messageRepository,
|
||||||
|
IWellService wellService,
|
||||||
|
IMessageService messageService)
|
||||||
{
|
{
|
||||||
this.messageService = messageService;
|
this.messageRepository = messageRepository;
|
||||||
this.wellService = wellService;
|
this.wellService = wellService;
|
||||||
|
this.messageService = messageService;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -46,17 +54,22 @@ public class MessageController : ControllerBase
|
|||||||
if (request.Take > 1024)
|
if (request.Take > 1024)
|
||||||
return this.ValidationBadRequest(nameof(request.Take), "limit mast be less then 1024");
|
return this.ValidationBadRequest(nameof(request.Take), "limit mast be less then 1024");
|
||||||
|
|
||||||
var requestToService = new MessageRequest(request, idWell);
|
var messageRequest = new MessageRequest(request, new int[] { idWell });
|
||||||
|
var result = await messageService.GetPaginatedMessagesAsync(messageRequest, token);
|
||||||
var result = await messageService.GetMessagesAsync(
|
|
||||||
requestToService,
|
|
||||||
token)
|
|
||||||
.ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (result is null || result.Count == 0)
|
if (result is null || result.Count == 0)
|
||||||
return NoContent();
|
return NoContent();
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpGet("/api/serviceOperation/[controller]")]
|
||||||
|
[ProducesResponseType(typeof(IEnumerable<StatCriticalMessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
|
public async Task<IActionResult> Get([FromQuery] MessageRequest request, CancellationToken token)
|
||||||
|
{
|
||||||
|
var result = await messageService.GetStat(request, token);
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
|
using AsbCloudApp.Repositories;
|
||||||
using AsbCloudApp.Services;
|
using AsbCloudApp.Services;
|
||||||
using AsbCloudWebApi.SignalR;
|
using AsbCloudWebApi.SignalR;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -20,21 +20,21 @@ namespace AsbCloudWebApi.Controllers.SAUB;
|
|||||||
public class TelemetryController : ControllerBase
|
public class TelemetryController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ITelemetryService telemetryService;
|
private readonly ITelemetryService telemetryService;
|
||||||
private readonly IMessageService messageService;
|
private readonly IMessageRepository messageRepository;
|
||||||
private readonly IEventService eventService;
|
private readonly IEventRepository eventRepository;
|
||||||
private readonly ITelemetryUserService telemetryUserService;
|
private readonly ITelemetryUserService telemetryUserService;
|
||||||
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
private readonly IHubContext<TelemetryHub> telemetryHubContext;
|
||||||
|
|
||||||
public TelemetryController(
|
public TelemetryController(
|
||||||
ITelemetryService telemetryService,
|
ITelemetryService telemetryService,
|
||||||
IMessageService messageService,
|
IMessageRepository messageRepository,
|
||||||
IEventService eventService,
|
IEventRepository eventRepository,
|
||||||
ITelemetryUserService telemetryUserService,
|
ITelemetryUserService telemetryUserService,
|
||||||
IHubContext<TelemetryHub> telemetryHubContext)
|
IHubContext<TelemetryHub> telemetryHubContext)
|
||||||
{
|
{
|
||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
this.messageService = messageService;
|
this.messageRepository = messageRepository;
|
||||||
this.eventService = eventService;
|
this.eventRepository = eventRepository;
|
||||||
this.telemetryUserService = telemetryUserService;
|
this.telemetryUserService = telemetryUserService;
|
||||||
this.telemetryHubContext = telemetryHubContext;
|
this.telemetryHubContext = telemetryHubContext;
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class TelemetryController : ControllerBase
|
|||||||
{
|
{
|
||||||
var from = DateTimeOffset.UtcNow.AddDays(-1);
|
var from = DateTimeOffset.UtcNow.AddDays(-1);
|
||||||
var stream = await telemetryService.GetTelemetriesInfoByLastData(from, token);
|
var stream = await telemetryService.GetTelemetriesInfoByLastData(from, token);
|
||||||
return File(stream, "text/csv", $"Software versions by active telemetries from {from :yy-MM-dd hh-mm}.csv");
|
return File(stream, "text/csv", $"Software versions by active telemetries from {from:yy-MM-dd hh-mm}.csv");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -79,7 +79,7 @@ public class TelemetryController : ControllerBase
|
|||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
var idWell = telemetryService.GetIdWellByTelemetryUid(uid);
|
||||||
await messageService.InsertAsync(uid, dtos, token).ConfigureAwait(false);
|
await messageRepository.InsertAsync(uid, dtos, token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (dtos.Any())
|
if (dtos.Any())
|
||||||
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
await Task.Run(() => telemetryHubContext.Clients.Group($"well_{idWell}")
|
||||||
@ -99,7 +99,7 @@ public class TelemetryController : ControllerBase
|
|||||||
public async Task<IActionResult> PostEventsAsync(string uid, [FromBody] List<EventDto> events,
|
public async Task<IActionResult> PostEventsAsync(string uid, [FromBody] List<EventDto> events,
|
||||||
CancellationToken token)
|
CancellationToken token)
|
||||||
{
|
{
|
||||||
await eventService.UpsertAsync(uid, events, token)
|
await eventRepository.UpsertAsync(uid, events, token)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user