Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
beyond-clouds
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
4
Issues
4
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
段启岩
beyond-clouds
Commits
17a9e657
Commit
17a9e657
authored
Feb 13, 2020
by
段启岩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
开启全局阻止重复提交
parent
b6c9cce7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
69 additions
and
4 deletions
+69
-4
src/main/java/cn/meteor/beyondclouds/config/properties/BeyondCloudsProperties.java
+2
-0
src/main/java/cn/meteor/beyondclouds/core/aop/PreventDuplicateSubmission.java
+59
-2
src/main/java/cn/meteor/beyondclouds/core/constant/SysConstants.java
+5
-0
src/main/java/cn/meteor/beyondclouds/core/lock/RedisLock.java
+0
-2
src/main/resources/application-dev.yml
+1
-0
src/main/resources/application-prod.yml
+1
-0
src/main/resources/application.yml
+1
-0
No files found.
src/main/java/cn/meteor/beyondclouds/config/properties/BeyondCloudsProperties.java
View file @
17a9e657
...
...
@@ -31,6 +31,8 @@ public class BeyondCloudsProperties {
*/
private
Boolean
debug
;
private
Boolean
globalPreventDuplicate
=
false
;
/**
* 认证配置
*/
...
...
src/main/java/cn/meteor/beyondclouds/core/aop/PreventDuplicateSubmission.java
View file @
17a9e657
package
cn
.
meteor
.
beyondclouds
.
core
.
aop
;
import
cn.meteor.beyondclouds.common.enums.ErrorCode
;
import
cn.meteor.beyondclouds.config.properties.BeyondCloudsProperties
;
import
cn.meteor.beyondclouds.core.api.Response
;
import
cn.meteor.beyondclouds.core.authentication.Subject
;
import
cn.meteor.beyondclouds.core.exception.ServiceException
;
...
...
@@ -11,8 +12,10 @@ import lombok.extern.slf4j.Slf4j;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
org.springframework.web.cors.CorsUtils
;
...
...
@@ -27,15 +30,69 @@ import java.util.concurrent.locks.Lock;
@Slf4j
public
class
PreventDuplicateSubmission
{
private
BeyondCloudsProperties
beyondCloudsProperties
;
private
RedisLockFactory
redisLockFactory
;
@Autowired
public
PreventDuplicateSubmission
(
RedisLockFactory
redisLockFactory
)
{
public
PreventDuplicateSubmission
(
RedisLockFactory
redisLockFactory
,
BeyondCloudsProperties
beyondCloudsProperties
)
{
this
.
redisLockFactory
=
redisLockFactory
;
this
.
beyondCloudsProperties
=
beyondCloudsProperties
;
}
@Around
(
value
=
"
@annotation(cn.meteor.beyondclouds.core.annotation.PreventDuplicate
)"
)
@Around
(
value
=
"
pointCutPreventDuplicateAnnotation(
)"
)
public
Object
processTx
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
if
(!
beyondCloudsProperties
.
getGlobalPreventDuplicate
())
{
log
.
info
(
"global prevent duplicate closed."
);
return
process
(
jp
);
}
else
{
return
jp
.
proceed
();
}
}
@Around
(
value
=
"pointCutRequestMapping() || pointCutGetMapping() || pointCutPutMapping() || pointCutPostMapping() || pointCutDeleteMapping()"
)
public
Object
processGlobalPreventDu
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
if
(
beyondCloudsProperties
.
getGlobalPreventDuplicate
())
{
log
.
info
(
"global prevent duplicate opened."
);
return
process
(
jp
);
}
else
{
return
jp
.
proceed
();
}
}
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.RequestMapping)"
)
public
void
pointCutRequestMapping
()
{
}
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.GetMapping)"
)
public
void
pointCutGetMapping
()
{
}
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.PutMapping)"
)
public
void
pointCutPutMapping
()
{
}
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.DeleteMapping)"
)
public
void
pointCutDeleteMapping
()
{
}
@Pointcut
(
"@annotation(org.springframework.web.bind.annotation.PostMapping)"
)
public
void
pointCutPostMapping
()
{
}
@Pointcut
(
"@annotation(cn.meteor.beyondclouds.core.annotation.PreventDuplicate)"
)
public
void
pointCutPreventDuplicateAnnotation
()
{
}
private
Object
process
(
ProceedingJoinPoint
jp
)
throws
Throwable
{
String
token
=
jp
.
getSignature
().
toString
();
token
=
SubjectUtils
.
getSubject
().
getIdentification
()
+
":"
+
token
;
Lock
lock
=
redisLockFactory
.
createLock
(
Md5Utils
.
encode
(
token
));
...
...
src/main/java/cn/meteor/beyondclouds/core/constant/SysConstants.java
View file @
17a9e657
...
...
@@ -25,4 +25,9 @@ public class SysConstants {
* 存储在HttpServletRequest里面的认证错误的信息
*/
public
static
final
String
AUTHORIZATION_ERROR_CODE
=
"AUTHORIZATION_ERROR_CODE"
;
/**
*
*/
public
static
final
String
THREAD_LOCAL_KEY_PREVENT_DUPLICATE_REDIS_LOCK
=
"THREAD_LOCAL_KEY_PREVENT_DUPLICATE_REDIS_LOCK"
;
}
src/main/java/cn/meteor/beyondclouds/core/lock/RedisLock.java
View file @
17a9e657
package
cn
.
meteor
.
beyondclouds
.
core
.
lock
;
import
cn.meteor.beyondclouds.common.helper.IRedisHelper
;
import
org.springframework.data.redis.core.RedisCallback
;
import
org.springframework.data.redis.core.RedisTemplate
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
java.util.Arrays
;
...
...
src/main/resources/application-dev.yml
View file @
17a9e657
...
...
@@ -87,6 +87,7 @@ logging:
# 云里云外
beyondclouds
:
debug
:
true
global-prevent-duplicate
:
true
auth
:
qq
:
client-id
:
101846021
...
...
src/main/resources/application-prod.yml
View file @
17a9e657
...
...
@@ -87,6 +87,7 @@ logging:
# 云里云外
beyondclouds
:
debug
:
true
global-prevent-duplicate
:
true
auth
:
qq
:
client-id
:
101846021
...
...
src/main/resources/application.yml
View file @
17a9e657
...
...
@@ -85,6 +85,7 @@ logging:
# 云里云外
beyondclouds
:
debug
:
true
global-prevent-duplicate
:
true
auth
:
qq
:
client-id
:
101846021
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment