добавлен фильтр сообщений по тексту

This commit is contained in:
Фролов 2021-08-09 15:09:46 +05:00
parent 9e69ff4ce7
commit a14e5134bf
3 changed files with 26 additions and 14 deletions

View File

@ -6,7 +6,7 @@ namespace AsbCloudApp.Services
{
public interface IMessageService
{
PaginationContainer<MessageDto> GetMessages(int idWell, IEnumerable<int> categoryids = null, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32);
PaginationContainer<MessageDto> GetMessages(int idWell, IEnumerable<int> categoryids = null, DateTime begin = default, DateTime end = default, string searchString = default, int skip = 0, int take = 32);
DatesRangeDto GetMessagesDatesRange(int idWell);
void Insert(string uid, IEnumerable<TelemetryMessageDto> dtos);
}

View File

@ -25,7 +25,14 @@ namespace AsbCloudInfrastructure.Services
cacheTUsers = cacheDb.GetCachedTable<TelemetryUser>((AsbCloudDbContext)db);
}
public PaginationContainer<MessageDto> GetMessages(int idWell, IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32)
public PaginationContainer<MessageDto> GetMessages(
int idWell,
IEnumerable<int> categoryids = default,
DateTime begin = default,
DateTime end = default,
string searchString = default,
int skip = 0,
int take = 32)
{
var telemetryId = telemetryService.GetIdTelemetryByIdWell(idWell);
if (telemetryId is null)
@ -36,15 +43,17 @@ namespace AsbCloudInfrastructure.Services
if (!events.Any())
return null;
var messages = from m in db.Messages
where m.IdTelemetry == telemetryId
select m;
var messages = db.Messages.Where(m => m.IdTelemetry == telemetryId);
if ((categoryids != default) && (categoryids.Any()))
if((categoryids?.Any() == true) || !string.IsNullOrEmpty(searchString))
{
var eventIds = from e in events
where categoryids.ToList().Contains(e.IdCategory)
select e.IdEvent;
if (!string.IsNullOrEmpty(searchString))
events = events.Where(e => e.MessageTemplate.Contains(searchString, StringComparison.OrdinalIgnoreCase));
if (categoryids?.Any() == true)
events = events.Where(e => categoryids.ToList().Contains(e.IdCategory));
var eventIds = events.Select(e=> e.IdEvent);
if (!eventIds.Any())
return null;
@ -52,8 +61,6 @@ namespace AsbCloudInfrastructure.Services
messages = messages.Where(m => eventIds.Contains(m.IdEvent));
}
var result = new PaginationContainer<MessageDto>() { Skip = skip, Take = take };
messages = messages.OrderByDescending(m => m.Date);
if (begin != default)
@ -62,7 +69,12 @@ namespace AsbCloudInfrastructure.Services
if (end != default)
messages = messages.Where(m => m.Date <= end);
result.Count = messages.Count();
var result = new PaginationContainer<MessageDto>
{
Skip = skip,
Take = take,
Count = messages.Count()
};
if (skip > 0)
messages = messages.Skip(skip);

View File

@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers
[HttpGet]
[Route("{idWell}/message")]
[ProducesResponseType(typeof(PaginationContainer<MessageDto>), (int)System.Net.HttpStatusCode.OK)]
public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default)
public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable<int> categoryids = default, DateTime begin = default, DateTime end = default, string searchString = default)
{
if (take > 1024)
return BadRequest("limit mast be less then 1024");
@ -40,7 +40,7 @@ namespace AsbCloudWebApi.Controllers
if (begin > DateTime.Now)
begin = default;
var result = messageService.GetMessages(idWell, categoryids, begin, end, skip, take);
var result = messageService.GetMessages(idWell, categoryids, begin, end, searchString, skip, take);
if (result is null || result.Count == 0)
return NoContent();