From f946eb93574db4c1d9e4cf480af4c3e0c7d378c0 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Sun, 18 Feb 2024 17:00:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E5=B1=80=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E5=8A=9F=E8=83=BD=E8=B0=83=E6=95=B4=E3=80=81=20?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Myshipping.Core/Filter/RequestActionFilter.cs | 6 +++--- Myshipping.Core/Service/Log/Dto/OpLogInput.cs | 2 +- .../Service/Log/SysOpLogService.cs | 20 ++++++++++++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/Myshipping.Core/Filter/RequestActionFilter.cs b/Myshipping.Core/Filter/RequestActionFilter.cs index 56c0b6d0..c3be254f 100644 --- a/Myshipping.Core/Filter/RequestActionFilter.cs +++ b/Myshipping.Core/Filter/RequestActionFilter.cs @@ -102,7 +102,7 @@ public class RequestActionFilter : IAsyncActionFilter businessIdList = businessIdList.Distinct(); } } - var option = new JsonSerializerOptions() { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; + await _eventPublisher.PublishAsync(new ChannelEventSource("Create:OpLog", new SysLogOp { Name = httpContext.User?.FindFirstValue(ClaimConst.CLAINM_NAME), @@ -115,8 +115,8 @@ public class RequestActionFilter : IAsyncActionFilter ClassName = context.Controller.ToString(), MethodName = actionDescriptor?.ActionName, ReqMethod = httpRequest.Method, - Param = JSON.Serialize(context.ActionArguments.Count < 1 ? "" : context.ActionArguments, option), - Result = actionContext.Result?.GetType() == typeof(JsonResult) ? JSON.Serialize(actionContext.Result, option) : "", + Param = context.ActionArguments.Count < 1 ? "" : context.ActionArguments.ToJsonString(), + Result = actionContext.Result?.GetType() == typeof(JsonResult) ? actionContext.Result.ToJsonString() : "", ElapsedTime = sw.ElapsedMilliseconds, OpTime = DateTime.Now, Account = httpContext.User?.FindFirstValue(ClaimConst.CLAINM_ACCOUNT), diff --git a/Myshipping.Core/Service/Log/Dto/OpLogInput.cs b/Myshipping.Core/Service/Log/Dto/OpLogInput.cs index a6573220..33cddd0b 100644 --- a/Myshipping.Core/Service/Log/Dto/OpLogInput.cs +++ b/Myshipping.Core/Service/Log/Dto/OpLogInput.cs @@ -20,7 +20,7 @@ public class OpLogInput : PageInputBase /// /// 是否执行成功(Y-是,N-否) /// - public YesOrNot Success { get; set; } + public YesOrNot? Success { get; set; } /// /// ip diff --git a/Myshipping.Core/Service/Log/SysOpLogService.cs b/Myshipping.Core/Service/Log/SysOpLogService.cs index 3fc5f4d0..ced27e2b 100644 --- a/Myshipping.Core/Service/Log/SysOpLogService.cs +++ b/Myshipping.Core/Service/Log/SysOpLogService.cs @@ -39,15 +39,25 @@ public class SysOpLogService : ISysOpLogService, IDynamicApiController, ITransie query.InnerJoin((o, b) => o.Id == b.LogId) .Where((o, b) => b.BusinessId == input.BusinessId); } - var result = await query.Where(o => o.Success == input.Success) + if (!string.IsNullOrWhiteSpace(input.Url)) + { + input.Url = input.Url.Trim(); + if (!input.Url.StartsWith('/')) + { + input.Url = $"/{input.Url}"; + } + } + + var result = await query.Where(o => o.Id > 0) // 如果没有Id > 0这个条件,SELECT Count(*) FROM `sys_log_op` 会执行很长时间,最后报错 + .WhereIF(input.Success != null, o => o.Success == input.Success) .WhereIF(!string.IsNullOrWhiteSpace(input.Name), o => o.Name.Contains(input.Name.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.Ip), o => o.Ip == input.Ip.Trim()) - .WhereIF(!string.IsNullOrWhiteSpace(input.Url), o => o.Url == input.Url.Trim()) + .WhereIF(!string.IsNullOrWhiteSpace(input.Url), o => o.Url == input.Url) .WhereIF(!string.IsNullOrWhiteSpace(input.SearchBeginTime), o => o.OpTime >= DateTime.Parse(input.SearchBeginTime.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.SearchEndTime), o => o.OpTime <= DateTime.Parse(input.SearchEndTime.Trim())) - .OrderByIF(input.SortField == "opTime", o => o.Id, input.DescSort ? OrderByType.Desc : OrderByType.Asc) - .OrderByIF(input.SortField == "ip", o => o.Ip, input.DescSort ? OrderByType.Desc : OrderByType.Asc) - .OrderByIF(input.SortField == "name", o => o.Name, input.DescSort ? OrderByType.Desc : OrderByType.Asc) + .OrderByIF(string.IsNullOrWhiteSpace(input.SortField) || string.Equals(input.SortField, "opTime", StringComparison.OrdinalIgnoreCase), o => o.Id, input.DescSort ? OrderByType.Desc : OrderByType.Asc) + //.OrderByIF(input.SortField == "name", o => o.Name, input.DescSort ? OrderByType.Desc : OrderByType.Asc) + //.OrderByIF(input.SortField == "ip", o => o.Ip, input.DescSort ? OrderByType.Desc : OrderByType.Asc) .Select(o => new OpLogPageListDto() { Id = o.Id,