♻️ feat(调整): 调整过滤器文件位置
This commit is contained in:
parent
4b774bdfc8
commit
544e8ab7ce
|
@ -7,6 +7,9 @@ using Microsoft.AspNetCore.Mvc.Filters;
|
|||
|
||||
namespace Bunny.Common.Filter;
|
||||
|
||||
/// <summary>
|
||||
/// 自定事务注解
|
||||
/// </summary>
|
||||
public class TransactionIAsyncActionFilter : IAsyncActionFilter
|
||||
{
|
||||
private static readonly ILog Log = LogManager.GetLogger(typeof(TransactionIAsyncActionFilter));
|
||||
|
@ -14,25 +17,29 @@ public class TransactionIAsyncActionFilter : IAsyncActionFilter
|
|||
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
|
||||
{
|
||||
var actionDesc = context.ActionDescriptor as ControllerActionDescriptor;
|
||||
var hasNotTransactionalAttribute =
|
||||
actionDesc?.MethodInfo.IsDefined(typeof(TransactionAttribute), false) ?? false;
|
||||
// 如果加上 【TransactionAttribute】 注解才执行操作
|
||||
var hasNotTransactionalAttribute = actionDesc?.MethodInfo.IsDefined(typeof(TransactionAttribute), false) ?? false;
|
||||
|
||||
// 如果没有加上自定义注解直接跳过
|
||||
if (hasNotTransactionalAttribute)
|
||||
{
|
||||
await next();
|
||||
return;
|
||||
}
|
||||
|
||||
// 开启事务
|
||||
using var txScope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled);
|
||||
var result = await next();
|
||||
|
||||
// 没有出错,直接标记完成
|
||||
if (result.Exception == null)
|
||||
{
|
||||
txScope.Complete();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorMessage =
|
||||
$"执行数据库出错 用户Id:[{BaseContext.GetUserId()}] token [{BaseContext.GetToken()}]:{result.Exception}";
|
||||
// 输出执行数据库操作产生事务原因
|
||||
var errorMessage = $"执行数据库出错 用户Id:[{BaseContext.GetUserId()}] token [{BaseContext.GetToken()}]:{result.Exception}";
|
||||
Log.Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ using Bunny.Dao.Common.Result;
|
|||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
namespace Bunny.Common.Attribute;
|
||||
namespace Bunny.Common.Filter;
|
||||
|
||||
/// <summary>
|
||||
/// 全局请求表单验证拦截器
|
||||
|
@ -12,6 +12,7 @@ public class ValidateModelStateAttribute : ActionFilterAttribute
|
|||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext actionContext)
|
||||
{
|
||||
// 验证通过直接跳过
|
||||
if (actionContext.ModelState.IsValid) return;
|
||||
|
||||
// 表单验证失败
|
|
@ -27,7 +27,7 @@ public static partial class NetUtil
|
|||
.Replace("\\**", ".*") + "$";
|
||||
|
||||
// 判断匹配规则是否成立
|
||||
return path.IsNullOrEmpty() ? Regex.IsMatch("", antPattern) : Regex.IsMatch(path!, antPattern);
|
||||
return path.IsNullOrEmpty() ? Regex.IsMatch("", antPattern) : Regex.IsMatch(path, antPattern);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
Loading…
Reference in New Issue