File tree Expand file tree Collapse file tree 2 files changed +10
-20
lines changed
framework/src/Bing.AspNetCore/Bing/AspNetCore/Mvc/Filters
modules/admin/src/Bing.Admin.FreeSQL/Apis Expand file tree Collapse file tree 2 files changed +10
-20
lines changed Original file line number Diff line number Diff line change @@ -35,9 +35,14 @@ public class AntiDuplicateRequestAttribute : ActionFilterAttribute
3535 public int Interval { get ; set ; } = 30 ;
3636
3737 /// <summary>
38- /// 锁模式
38+ /// 提示消息
3939 /// </summary>
40- public LockMode Mode { get ; set ; } = LockMode . Limit ;
40+ public string Message { get ; set ; }
41+
42+ /// <summary>
43+ /// 是否自动解锁,默认:false(true:时间间隔内请求处理完成,可以继续提交)
44+ /// </summary>
45+ public bool AutoUnLock { get ; set ; } = false ;
4146
4247 /// <summary>
4348 /// 执行
@@ -73,7 +78,7 @@ public override async Task OnActionExecutionAsync(ActionExecutingContext context
7378 finally
7479 {
7580 // 并发模式下,需要释放锁
76- if ( isSuccess && Mode == LockMode . Concurrent )
81+ if ( isSuccess && AutoUnLock )
7782 await @lock . LockReleaseAsync ( key , value ) ;
7883 }
7984 }
@@ -120,7 +125,7 @@ protected virtual string GetValue(ActionExecutingContext context)
120125 /// <summary>
121126 /// 获取失败消息
122127 /// </summary>
123- protected virtual string GetFailMessage ( ) => Type == LockType . User ? R . UserDuplicateRequest : R . GlobalDuplicateRequest ;
128+ protected virtual string GetFailMessage ( ) => ! string . IsNullOrWhiteSpace ( Message ) ? Message : Type == LockType . User ? R . UserDuplicateRequest : R . GlobalDuplicateRequest ;
124129 }
125130
126131 /// <summary>
@@ -138,19 +143,4 @@ public enum LockType
138143 /// </summary>
139144 Global = 1
140145 }
141-
142- /// <summary>
143- /// 锁模式
144- /// </summary>
145- public enum LockMode
146- {
147- /// <summary>
148- /// 限制模式。一定时间内只能有一个通过
149- /// </summary>
150- Limit ,
151- /// <summary>
152- /// 并发模式。在上个请求未结束,均不能通过
153- /// </summary>
154- Concurrent ,
155- }
156146}
Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ public async Task<IActionResult> TestMessageAsync([FromBody] TestMessage request
9393 /// </summary>
9494 [ AllowAnonymous ]
9595 [ HttpPost ( "testAntiDuplicate" ) ]
96- [ AntiDuplicateRequest ( Key = "test" , IsDistributed = true , Mode = LockMode . Limit ) ]
96+ [ AntiDuplicateRequest ( Key = "test" , IsDistributed = true ) ]
9797 public Task < IActionResult > TestAntiDuplicateAsync ( )
9898 {
9999 return Task . FromResult ( Success ( ) ) ;
You can’t perform that action at this time.
0 commit comments