From a14e5134bfa88b0798d15d824799cc9924caa1db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Mon, 9 Aug 2021 15:09:46 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=20=D1=81=D0=BE?= =?UTF-8?q?=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=BF=D0=BE=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=81=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AsbCloudApp/Services/IMessageService.cs | 2 +- .../Services/MessageService.cs | 34 +++++++++++++------ .../Controllers/MessageController.cs | 4 +-- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/AsbCloudApp/Services/IMessageService.cs b/AsbCloudApp/Services/IMessageService.cs index 9f816c66..3745cd16 100644 --- a/AsbCloudApp/Services/IMessageService.cs +++ b/AsbCloudApp/Services/IMessageService.cs @@ -6,7 +6,7 @@ namespace AsbCloudApp.Services { public interface IMessageService { - PaginationContainer GetMessages(int idWell, IEnumerable categoryids = null, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32); + PaginationContainer GetMessages(int idWell, IEnumerable 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 dtos); } diff --git a/AsbCloudInfrastructure/Services/MessageService.cs b/AsbCloudInfrastructure/Services/MessageService.cs index 81fd14e5..01326b23 100644 --- a/AsbCloudInfrastructure/Services/MessageService.cs +++ b/AsbCloudInfrastructure/Services/MessageService.cs @@ -25,7 +25,14 @@ namespace AsbCloudInfrastructure.Services cacheTUsers = cacheDb.GetCachedTable((AsbCloudDbContext)db); } - public PaginationContainer GetMessages(int idWell, IEnumerable categoryids = default, DateTime begin = default, DateTime end = default, int skip = 0, int take = 32) + public PaginationContainer GetMessages( + int idWell, + IEnumerable 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() { 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 + { + Skip = skip, + Take = take, + Count = messages.Count() + }; if (skip > 0) messages = messages.Skip(skip); diff --git a/AsbCloudWebApi/Controllers/MessageController.cs b/AsbCloudWebApi/Controllers/MessageController.cs index 7e35a6cf..8580b805 100644 --- a/AsbCloudWebApi/Controllers/MessageController.cs +++ b/AsbCloudWebApi/Controllers/MessageController.cs @@ -32,7 +32,7 @@ namespace AsbCloudWebApi.Controllers [HttpGet] [Route("{idWell}/message")] [ProducesResponseType(typeof(PaginationContainer), (int)System.Net.HttpStatusCode.OK)] - public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable categoryids = default, DateTime begin = default, DateTime end = default) + public IActionResult GetMessage(int idWell, int skip = 0, int take = 32, [FromQuery] IEnumerable 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();