Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gxpt_ht
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pseer
gxpt_ht
Commits
a35eee80
Commit
a35eee80
authored
Oct 11, 2024
by
吕明尚
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
验券增加幂等
parent
b491437e
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
87 additions
and
10 deletions
+87
-10
pom.xml
share-common/pom.xml
+7
-0
RepeatSubmit.java
...on/src/main/java/share/common/utils/aop/RepeatSubmit.java
+14
-0
RepeatSubmitAspect.java
.../main/java/share/common/utils/aop/RepeatSubmitAspect.java
+61
-0
QPServiceImpl.java
...rc/main/java/share/system/service/impl/QPServiceImpl.java
+3
-1
TiktokServiceImpl.java
...ain/java/share/system/service/impl/TiktokServiceImpl.java
+2
-0
share.iml
share.iml
+0
-9
No files found.
share-common/pom.xml
View file @
a35eee80
...
...
@@ -176,6 +176,12 @@
<artifactId>
xstream
</artifactId>
<version>
1.4.9
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
21.0
</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
share-common/src/main/java/share/common/utils/aop/RepeatSubmit.java
0 → 100644
View file @
a35eee80
package
share
.
common
.
utils
.
aop
;
import
java.lang.annotation.*
;
@Target
(
ElementType
.
METHOD
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
@Documented
@Inherited
public
@interface
RepeatSubmit
{
String
key
()
default
""
;
}
share-common/src/main/java/share/common/utils/aop/RepeatSubmitAspect.java
0 → 100644
View file @
a35eee80
package
share
.
common
.
utils
.
aop
;
import
com.google.common.cache.Cache
;
import
com.google.common.cache.CacheBuilder
;
import
org.apache.commons.lang3.StringUtils
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.stereotype.Component
;
import
java.lang.reflect.Method
;
import
java.util.concurrent.TimeUnit
;
@Aspect
@Component
public
class
RepeatSubmitAspect
{
private
static
final
Cache
<
String
,
Object
>
CACHES
=
CacheBuilder
.
newBuilder
()
// 最大缓存 设置为1000个
.
maximumSize
(
1000
)
// 设置写缓存后1s过期
.
expireAfterWrite
(
1
,
TimeUnit
.
SECONDS
)
.
build
();
@Around
(
"execution(public * *(..)) && @annotation(share.common.utils.aop.RepeatSubmit))"
)
public
Object
interceptor
(
ProceedingJoinPoint
pjp
)
{
MethodSignature
signature
=
(
MethodSignature
)
pjp
.
getSignature
();
Method
method
=
signature
.
getMethod
();
RepeatSubmit
repeatSubmit
=
method
.
getAnnotation
(
RepeatSubmit
.
class
);
String
key
=
getKey
(
repeatSubmit
.
key
(),
pjp
.
getArgs
());
if
(
StringUtils
.
isNotBlank
(
key
))
{
if
(
CACHES
.
getIfPresent
(
key
)
!=
null
)
{
throw
new
RuntimeException
(
"请勿重复请求"
);
}
// 如果是第一次请求,就将key 当前对象压入缓存中
CACHES
.
put
(
key
,
key
);
}
try
{
return
pjp
.
proceed
();
}
catch
(
Throwable
throwable
)
{
throw
new
RuntimeException
(
"服务器异常!"
);
}
}
/**
* key 的生成策略
*
* @param keyExpress 表达式
* @param args 参数
* @return 生成的key
*/
private
String
getKey
(
String
keyExpress
,
Object
[]
args
)
{
for
(
int
i
=
0
;
i
<
args
.
length
;
i
++)
{
keyExpress
=
keyExpress
.
replace
(
"arg["
+
i
+
"]"
,
args
[
i
].
toString
());
}
return
keyExpress
;
}
}
share-system/src/main/java/share/system/service/impl/QPServiceImpl.java
View file @
a35eee80
...
...
@@ -32,6 +32,7 @@ import share.common.core.redis.RedisUtil;
import
share.common.enums.*
;
import
share.common.exception.base.BaseException
;
import
share.common.utils.DateUtils
;
import
share.common.utils.aop.RepeatSubmit
;
import
share.system.domain.SConsumer
;
import
share.system.domain.SConsumerCoupon
;
import
share.system.domain.SCoupon
;
...
...
@@ -100,6 +101,7 @@ public class QPServiceImpl implements QPService {
* 用户验卷接口
*/
@Override
@RepeatSubmit
(
key
=
"美团验卷"
)
public
String
consumeByUser
(
String
code
,
String
storeId
,
String
status
)
throws
Exception
{
//获取用户信息
SConsumer
user
=
FrontTokenComponent
.
getWxSConsumerEntry
();
...
...
@@ -206,7 +208,7 @@ public class QPServiceImpl implements QPService {
}
isConsumerCouponService
.
insertSConsumerCoupon
(
sConsumerCoupon
);
//核销美团券
qpService
.
consume
(
code
.
trim
(),
1
,
sStore
.
getOpenShopUuid
(),
status
);
//
qpService.consume(code.trim(), 1, sStore.getOpenShopUuid(), status);
return
"验劵成功"
;
}
...
...
share-system/src/main/java/share/system/service/impl/TiktokServiceImpl.java
View file @
a35eee80
...
...
@@ -20,6 +20,7 @@ import org.springframework.util.CollectionUtils;
import
share.common.core.redis.RedisUtil
;
import
share.common.enums.*
;
import
share.common.exception.base.BaseException
;
import
share.common.utils.aop.RepeatSubmit
;
import
share.system.domain.SConsumer
;
import
share.system.domain.SConsumerCoupon
;
import
share.system.domain.SCoupon
;
...
...
@@ -351,6 +352,7 @@ public class TiktokServiceImpl implements TiktokService {
}
@Override
@RepeatSubmit
(
key
=
"抖音验卷"
)
public
String
consumeByUser
(
String
code
,
String
storeId
)
throws
Exception
{
SConsumer
user
=
FrontTokenComponent
.
getWxSConsumerEntry
();
if
(
ObjectUtil
.
isNull
(
user
))
{
...
...
share.iml
deleted
100644 → 0
View file @
b491437e
<?xml version="1.0" encoding="UTF-8"?>
<module
org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule=
"true"
type=
"JAVA_MODULE"
version=
"4"
>
<component
name=
"AdditionalModuleElements"
>
<content
url=
"file://$MODULE_DIR$"
dumb=
"true"
>
<excludeFolder
url=
"file://$MODULE_DIR$/target"
/>
</content>
</component>
</module>
\ No newline at end of file
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