forked from ddrilling/AsbCloudServer
Рефактор метода GetMessagesAsync в MessageService
This commit is contained in:
parent
e81abc86e6
commit
2746c94729
@ -28,16 +28,8 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
public async Task<PaginationContainer<MessageDto>> GetMessagesAsync(MessageRequest request, CancellationToken token)
|
||||
{
|
||||
var idWell = request.IdWell;
|
||||
var categoryids = request.Categoryids;
|
||||
var searchString = request.SearchString;
|
||||
var begin = request.Begin;
|
||||
var end = request.End;
|
||||
var skip = request.Skip ?? 0;
|
||||
var take = request.Take ?? 32;
|
||||
var sortFields = request.SortFields;
|
||||
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(idWell);
|
||||
var idTelemetry = telemetryService.GetOrDefaultIdTelemetryByIdWell(request.IdWell);
|
||||
if (idTelemetry is null)
|
||||
return null;
|
||||
|
||||
@ -50,13 +42,13 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
var query = db.TelemetryMessages.Where(m => m.IdTelemetry == idTelemetry)
|
||||
.OrderBy(m => m.DateTime).AsNoTracking();
|
||||
|
||||
if (categoryids?.Any() == true || !string.IsNullOrEmpty(searchString))
|
||||
if (request.Categoryids?.Any() == true || !string.IsNullOrEmpty(request.SearchString))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
events = events.Where(e => e.MessageTemplate.Contains(searchString, StringComparison.OrdinalIgnoreCase));
|
||||
if (!string.IsNullOrEmpty(request.SearchString))
|
||||
events = events.Where(e => e.MessageTemplate.Contains(request.SearchString, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (categoryids?.Any() == true)
|
||||
events = events.Where(e => categoryids.ToList().Contains(e.IdCategory));
|
||||
if (request.Categoryids?.Any() == true)
|
||||
events = events.Where(e => request.Categoryids.ToList().Contains(e.IdCategory));
|
||||
|
||||
var eventIds = events.Select(e => e.IdEvent);
|
||||
|
||||
@ -70,31 +62,31 @@ namespace AsbCloudInfrastructure.Services.SAUB
|
||||
|
||||
var timezone = telemetryService.GetTimezone(idTelemetry ?? default);
|
||||
|
||||
if (begin != default)
|
||||
if (request.Begin != default)
|
||||
{
|
||||
var beginUtc = begin.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
var beginUtc = request.Begin.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query = query.Where(m => m.DateTime >= beginUtc);
|
||||
}
|
||||
|
||||
if (end != default)
|
||||
if (request.End != default)
|
||||
{
|
||||
var endUtc = end.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
var endUtc = request.End.Value.ToUtcDateTimeOffset(timezone.Hours);
|
||||
query = query.Where(m => m.DateTime <= endUtc);
|
||||
}
|
||||
|
||||
var result = new PaginationContainer<MessageDto>
|
||||
{
|
||||
Skip = skip,
|
||||
Take = take,
|
||||
Skip = request.Skip ?? 0,
|
||||
Take = request.Take ?? 32,
|
||||
Count = query.Count()
|
||||
};
|
||||
|
||||
if (sortFields?.Any() == true)
|
||||
if (request.SortFields?.Any() == true)
|
||||
{
|
||||
query = query.SortBy(request.SortFields);
|
||||
}
|
||||
var messagesList = await query.Skip(skip)
|
||||
.Take(take).AsNoTracking()
|
||||
var messagesList = await query.Skip(request.Skip ?? 0)
|
||||
.Take(request.Take ?? 32).AsNoTracking()
|
||||
.ToListAsync(token).ConfigureAwait(false);
|
||||
|
||||
if (messagesList.Count == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user