diff --git a/Api/Ewide.Core/Attributes/OpAttribute.cs b/Api/Ewide.Core/Attributes/OpAttribute.cs
new file mode 100644
index 0000000..897608b
--- /dev/null
+++ b/Api/Ewide.Core/Attributes/OpAttribute.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Ewide.Core.Attributes
+{
+ public class OpAttribute : Attribute
+ {
+ private readonly LogOpType logOpType;
+ public OpAttribute(LogOpType logOpType)
+ {
+ this.logOpType = logOpType;
+ }
+ public int OpType { get => (int)logOpType; }
+ }
+}
diff --git a/Api/Ewide.Core/Ewide.Core.xml b/Api/Ewide.Core/Ewide.Core.xml
index 8d6ebb4..4411fa2 100644
--- a/Api/Ewide.Core/Ewide.Core.xml
+++ b/Api/Ewide.Core/Ewide.Core.xml
@@ -2784,6 +2784,13 @@
请求日志拦截
+
+
+ 使用路由推断
+
+
+
+
用户管理
diff --git a/Api/Ewide.Core/Filter/RequestActionFilter.cs b/Api/Ewide.Core/Filter/RequestActionFilter.cs
index 6a37036..567e09a 100644
--- a/Api/Ewide.Core/Filter/RequestActionFilter.cs
+++ b/Api/Ewide.Core/Filter/RequestActionFilter.cs
@@ -10,6 +10,9 @@ using System.Threading.Tasks;
using UAParser;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
+using System.Reflection;
+using Ewide.Core.Attributes;
+using System.Linq;
namespace Ewide.Core
{
@@ -36,6 +39,11 @@ namespace Ewide.Core
var actionDescriptor = context.ActionDescriptor as ControllerActionDescriptor;
var descAtt = Attribute.GetCustomAttribute(actionDescriptor.MethodInfo, typeof(DescriptionAttribute)) as DescriptionAttribute;
+ //获取操作类型
+ var method = actionDescriptor.MethodInfo;
+ var opAttr = method.GetCustomAttribute();
+ var opType = opAttr?.OpType ?? InferOpType(httpRequest);
+
var message = "请求成功";
if (isRequestSucceed)
{
@@ -56,7 +64,7 @@ namespace Ewide.Core
var sysOpLog = new SysLogOp
{
Name = descAtt != null ? descAtt.Description : actionDescriptor.ActionName,
- OpType = 1,
+ OpType = opType,
Success = isRequestSucceed,
Message = message,
Ip = httpContext.GetRemoteIpAddressToIPv4(),
@@ -75,5 +83,28 @@ namespace Ewide.Core
};
await sysOpLog.InsertNowAsync();
}
+ ///
+ /// 使用路由推断
+ ///
+ ///
+ ///
+ int InferOpType(HttpRequest request)
+ {
+ var lastRoute = request.Path.Value.Split("/").Last();
+ var opNames = Enum.GetNames(typeof(LogOpType));
+ foreach (var op in opNames)
+ {
+ if (lastRoute.Contains(op, StringComparison.OrdinalIgnoreCase))
+ {
+ return (int)Enum.Parse(typeof(LogOpType), op);
+ }
+ }
+ if (lastRoute.Contains("page", StringComparison.OrdinalIgnoreCase) ||
+ lastRoute.Contains("list", StringComparison.OrdinalIgnoreCase))
+ {
+ return (int)LogOpType.QUERY;
+ }
+ return 0;
+ }
}
}
diff --git a/Api/Ewide.Core/Service/Auth/AuthService.cs b/Api/Ewide.Core/Service/Auth/AuthService.cs
index 7894894..a23914a 100644
--- a/Api/Ewide.Core/Service/Auth/AuthService.cs
+++ b/Api/Ewide.Core/Service/Auth/AuthService.cs
@@ -1,4 +1,5 @@
-using Ewide.Core.Util;
+using Ewide.Core.Attributes;
+using Ewide.Core.Util;
using Furion;
using Furion.DatabaseAccessor;
using Furion.DatabaseAccessor.Extensions;
@@ -69,6 +70,7 @@ namespace Ewide.Core.Service
///
[HttpPost("/login")]
[AllowAnonymous]
+ [Op(LogOpType.GRANT)]
public async Task LoginAsync([Required] LoginInput input)
{
var password = RSAHandler.RSADecrypt(input.Password);