forked from ddrilling/AsbCloudServer
правки по результатам ревью
This commit is contained in:
parent
57d97057da
commit
31efdbf406
@ -17,7 +17,7 @@ public interface IEventRepository
|
|||||||
/// <param name="request">параметры запроса</param>
|
/// <param name="request">параметры запроса</param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token);
|
Task<IEnumerable<TelemetryEventDto>> GetAsync(TelemetryEventRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Сохранить. Добавить или заменить.
|
/// Сохранить. Добавить или заменить.
|
||||||
@ -26,6 +26,5 @@ public interface IEventRepository
|
|||||||
/// <param name="dtos"></param>
|
/// <param name="dtos"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos,
|
Task UpsertAsync(string uid, IEnumerable<EventDto> dtos, CancellationToken token);
|
||||||
CancellationToken token = default);
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ namespace AsbCloudApp.Repositories;
|
|||||||
public interface IMessageRepository : ITelemetryDataEditorService
|
public interface IMessageRepository : ITelemetryDataEditorService
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить PaginationContainer с сообщениями по параметрам
|
/// Получить сообщения по параметрам
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
|
@ -2,6 +2,7 @@ using AsbCloudApp.Data;
|
|||||||
using AsbCloudApp.Data.SAUB;
|
using AsbCloudApp.Data.SAUB;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace AsbCloudApp.Requests;
|
namespace AsbCloudApp.Requests;
|
||||||
|
|
||||||
@ -86,19 +87,25 @@ public class MessageTelemetryRequest : MessageRequestBase
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// события
|
/// события
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<TelemetryEventDto> Events { get; set; } = null!;
|
public IEnumerable<TelemetryEventDto> Events { get; set; }= Enumerable.Empty<TelemetryEventDto>();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// телеметрии
|
/// телеметрии
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = null!;
|
public IEnumerable<TelemetryBaseDto> Telemetries { get; set; } = Enumerable.Empty<TelemetryBaseDto>();
|
||||||
|
|
||||||
/// <summary>
|
/// <inheritdoc/>
|
||||||
///
|
public MessageTelemetryRequest(
|
||||||
/// </summary>
|
MessageRequestBase request,
|
||||||
/// <param name="request"></param>
|
IEnumerable<TelemetryEventDto> events,
|
||||||
public MessageTelemetryRequest(MessageRequestBase request) : base(request)
|
IEnumerable<TelemetryBaseDto> telemetries) : base(request)
|
||||||
{
|
{
|
||||||
|
Events = events;
|
||||||
|
Telemetries = telemetries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public MessageTelemetryRequest(MessageRequestBase request)
|
||||||
|
: base(request) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ public interface IMessageService
|
|||||||
/// <param name="request"></param>
|
/// <param name="request"></param>
|
||||||
/// <param name="token"></param>
|
/// <param name="token"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token);
|
Task<IEnumerable<StatCriticalMessageDto>> GetStatAsync(MessageRequest request, CancellationToken token);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Получить PaginationContainer с сообщениями по параметрам
|
/// Получить PaginationContainer с сообщениями по параметрам
|
||||||
|
@ -224,7 +224,7 @@ public class MessageServiceTest
|
|||||||
.Returns(telemetries);
|
.Returns(telemetries);
|
||||||
|
|
||||||
eventRepositoryMock
|
eventRepositoryMock
|
||||||
.Get(Arg.Any<TelemetryEventRequest>(), Arg.Any<CancellationToken>())
|
.GetAsync(Arg.Any<TelemetryEventRequest>(), Arg.Any<CancellationToken>())
|
||||||
.Returns(events);
|
.Returns(events);
|
||||||
|
|
||||||
messageRepositoryMock
|
messageRepositoryMock
|
||||||
@ -239,75 +239,51 @@ public class MessageServiceTest
|
|||||||
//act
|
//act
|
||||||
var baseRequest = new MessageRequestBase() { };
|
var baseRequest = new MessageRequestBase() { };
|
||||||
var messageRequest = new MessageRequest(baseRequest, [1]);
|
var messageRequest = new MessageRequest(baseRequest, [1]);
|
||||||
var result = await messageServiceMock.GetStat(messageRequest, CancellationToken.None);
|
var result = await messageServiceMock.GetStatAsync(messageRequest, CancellationToken.None);
|
||||||
|
|
||||||
Assert.Equal(6, result.Count());
|
Assert.Equal(6, result.Count());
|
||||||
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_1_Expected = messages
|
var сообщение_1_1 = result
|
||||||
.Where(x => x.IdTelemetry == 1)
|
|
||||||
.Where(x => x.IdEvent == 1)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_1_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 1)
|
.Where(x => x.IdTelemetry == 1)
|
||||||
.Where(x => x.IdCategory == 1)
|
.Where(x => x.IdCategory == 1)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 1")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 1")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_1_Category_1_Template_1_Expected, mCount_Telemetry_1_Category_1_Template_1_Actual);
|
Assert.Equal(3, сообщение_1_1.MessagesCount);
|
||||||
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_2_Expected = messages
|
var сообщение_1_2 = result
|
||||||
.Where(x => x.IdTelemetry == 1)
|
|
||||||
.Where(x => x.IdEvent == 2)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_2_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 1)
|
.Where(x => x.IdTelemetry == 1)
|
||||||
.Where(x => x.IdCategory == 1)
|
.Where(x => x.IdCategory == 1)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 1")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 1")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_1_Category_1_Template_2_Expected, mCount_Telemetry_1_Category_1_Template_2_Actual);
|
Assert.Equal(3, сообщение_1_2.MessagesCount);
|
||||||
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_3_Expected = messages
|
var сообщение_1_3 = result
|
||||||
.Where(x => x.IdTelemetry == 1)
|
|
||||||
.Where(x => x.IdEvent == 3)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_1_Category_1_Template_3_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 1)
|
.Where(x => x.IdTelemetry == 1)
|
||||||
.Where(x => x.IdCategory == 1)
|
.Where(x => x.IdCategory == 1)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 1")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 1")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_1_Category_1_Template_3_Expected, mCount_Telemetry_1_Category_1_Template_3_Actual);
|
Assert.Equal(3, сообщение_1_3.MessagesCount);
|
||||||
|
|
||||||
var mCount_Telemetry_1_Category_2_Template_2_Expected = messages
|
var сообщение_2_2 = result
|
||||||
.Where(x => x.IdTelemetry == 1)
|
|
||||||
.Where(x => x.IdEvent == 5)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_1_Category_2_Template_2_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 1)
|
.Where(x => x.IdTelemetry == 1)
|
||||||
.Where(x => x.IdCategory == 2)
|
.Where(x => x.IdCategory == 2)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 2")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 2 категории 2")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_1_Category_2_Template_2_Expected, mCount_Telemetry_1_Category_2_Template_2_Actual);
|
Assert.Equal(2, сообщение_2_2.MessagesCount);
|
||||||
|
|
||||||
var mCount_Telemetry_1_Category_2_Template_3_Expected = messages
|
var сообщение_2_1 = result
|
||||||
.Where(x => x.IdTelemetry == 1)
|
|
||||||
.Where(x => x.IdEvent == 6)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_1_Category_2_Template_3_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 1)
|
.Where(x => x.IdTelemetry == 1)
|
||||||
.Where(x => x.IdCategory == 2)
|
.Where(x => x.IdCategory == 2)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 3 категории 2")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 2")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_1_Category_2_Template_3_Expected, mCount_Telemetry_1_Category_2_Template_3_Actual);
|
Assert.Equal(2, сообщение_2_1.MessagesCount);
|
||||||
|
|
||||||
var mCount_Telemetry_2_Category_3_Template_1_Expected = messages
|
var сообщение_3_1 = result
|
||||||
.Where(x => x.IdTelemetry == 2)
|
|
||||||
.Where(x => x.IdEvent == 6)
|
|
||||||
.Count();
|
|
||||||
var mCount_Telemetry_2_Category_3_Template_1_Actual = result
|
|
||||||
.Where(x => x.IdTelemetry == 2)
|
.Where(x => x.IdTelemetry == 2)
|
||||||
.Where(x => x.IdCategory == 3)
|
.Where(x => x.IdCategory == 3)
|
||||||
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 3")
|
.Where(x => x.MessageTemplate == "Шаблон сообщения 1 категории 3")
|
||||||
.Sum(x => x.MessagesCount);
|
.Single();
|
||||||
Assert.Equal(mCount_Telemetry_2_Category_3_Template_1_Expected, mCount_Telemetry_2_Category_3_Template_1_Actual);
|
Assert.Equal(3, сообщение_3_1.MessagesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ public class EventRepository : IEventRepository
|
|||||||
this.telemetryService = telemetryService;
|
this.telemetryService = telemetryService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<TelemetryEventDto>> Get(TelemetryEventRequest request, CancellationToken token)
|
public async Task<IEnumerable<TelemetryEventDto>> GetAsync(TelemetryEventRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryEvent>(), token);
|
var allEvents = await memoryCache.GetOrCreateBasicAsync(db.Set<TelemetryEvent>(), token);
|
||||||
var events = allEvents.Where(e => request.IdsTelemetries.Contains(e.IdTelemetry));
|
var events = allEvents.Where(e => request.IdsTelemetries.Contains(e.IdTelemetry));
|
||||||
@ -65,7 +65,7 @@ public class EventRepository : IEventRepository
|
|||||||
IdCategory = dto.IdCategory,
|
IdCategory = dto.IdCategory,
|
||||||
MessageTemplate = dto.Message
|
MessageTemplate = dto.Message
|
||||||
});
|
});
|
||||||
var result = await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
|
await db.Database.ExecInsertOrUpdateAsync(db.TelemetryEvents, entities, token);
|
||||||
memoryCache.DropBasic<TelemetryEvent>();
|
memoryCache.DropBasic<TelemetryEvent>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class MessageService : IMessageService
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IEnumerable<StatCriticalMessageDto>> GetStat(MessageRequest request, CancellationToken token)
|
public async Task<IEnumerable<StatCriticalMessageDto>> GetStatAsync(MessageRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
|
var messageTelemetryRequest = await CreateMessageTelemetryRequest(request, token);
|
||||||
|
|
||||||
@ -77,10 +77,9 @@ public class MessageService : IMessageService
|
|||||||
IdsCategories = request.IdsCategories,
|
IdsCategories = request.IdsCategories,
|
||||||
SearchString = request.SearchString,
|
SearchString = request.SearchString,
|
||||||
};
|
};
|
||||||
|
var events = await eventRepository.GetAsync(telemetryEventRequest, token);
|
||||||
|
|
||||||
var messageTelemetryRequest = new MessageTelemetryRequest(request);
|
var messageTelemetryRequest = new MessageTelemetryRequest(request, events, telemetries);
|
||||||
messageTelemetryRequest.Telemetries = telemetries;
|
|
||||||
messageTelemetryRequest.Events = await eventRepository.Get(telemetryEventRequest, token);
|
|
||||||
|
|
||||||
return messageTelemetryRequest;
|
return messageTelemetryRequest;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ public class MessageController : ControllerBase
|
|||||||
[ProducesResponseType(typeof(IEnumerable<StatCriticalMessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
[ProducesResponseType(typeof(IEnumerable<StatCriticalMessageDto>), (int)System.Net.HttpStatusCode.OK)]
|
||||||
public async Task<IActionResult> Get([FromQuery] MessageRequest request, CancellationToken token)
|
public async Task<IActionResult> Get([FromQuery] MessageRequest request, CancellationToken token)
|
||||||
{
|
{
|
||||||
var result = await messageService.GetStat(request, token);
|
var result = await messageService.GetStatAsync(request, token);
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user