Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
O
oms
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
iuav
oms
Commits
7ffc2bdb
提交
7ffc2bdb
authored
8月 31, 2023
作者:
张小凤
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
NotRepeatSubmitConfig(update)
上级
e69c7c5b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
1 行删除
+44
-1
NotRepeatSubmitConfig.java
...c/oms/controller/demand/commit/NotRepeatSubmitConfig.java
+44
-1
没有找到文件。
src/main/java/com/mmc/oms/controller/demand/commit/NotRepeatSubmitConfig.java
浏览文件 @
7ffc2bdb
package
com
.
mmc
.
oms
.
controller
.
demand
.
commit
;
package
com
.
mmc
.
oms
.
controller
.
demand
.
commit
;
import
com.alibaba.fastjson.JSONObject
;
import
com.mmc.oms.common.result.ResultBody
;
import
com.mmc.oms.controller.BaseController
;
import
com.mmc.oms.controller.BaseController
;
import
com.mmc.oms.dao.demand.DemandReleaseOrderDao
;
import
com.mmc.oms.entity.demand.GetOrderNumberDO
;
import
com.mmc.oms.entity.demand.GetOrderNumberDTO
;
import
com.mmc.oms.model.vo.demand.CommonPaymentVO
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.CodeSignature
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RLock
;
import
org.redisson.api.RedissonClient
;
import
org.redisson.api.RedissonClient
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.redis.core.StringRedisTemplate
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
java.lang.reflect.Method
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.concurrent.TimeUnit
;
import
java.util.concurrent.TimeUnit
;
/**
/**
...
@@ -28,6 +41,12 @@ public class NotRepeatSubmitConfig extends BaseController {
...
@@ -28,6 +41,12 @@ public class NotRepeatSubmitConfig extends BaseController {
@Autowired
@Autowired
private
RedissonClient
redissonClient
;
private
RedissonClient
redissonClient
;
@Autowired
private
DemandReleaseOrderDao
releaseOrderDao
;
@Autowired
private
StringRedisTemplate
stringRedisTemplate
;
@Pointcut
(
"@within(notRepeatSubmit)||@annotation(notRepeatSubmit)"
)
@Pointcut
(
"@within(notRepeatSubmit)||@annotation(notRepeatSubmit)"
)
public
void
pointcut
(
NotRepeatSubmit
notRepeatSubmit
)
{
public
void
pointcut
(
NotRepeatSubmit
notRepeatSubmit
)
{
...
@@ -44,6 +63,7 @@ public class NotRepeatSubmitConfig extends BaseController {
...
@@ -44,6 +63,7 @@ public class NotRepeatSubmitConfig extends BaseController {
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
ServletRequestAttributes
attributes
=
(
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
();
HttpServletRequest
request
=
attributes
.
getRequest
();
HttpServletRequest
request
=
attributes
.
getRequest
();
Integer
userAccountId
=
this
.
getCurrentAccount
(
request
).
getUserAccountId
();
Integer
userAccountId
=
this
.
getCurrentAccount
(
request
).
getUserAccountId
();
String
accountUriLockKey
=
userAccountId
+
"-"
+
request
.
getServletPath
();
String
accountUriLockKey
=
userAccountId
+
"-"
+
request
.
getServletPath
();
// 设置锁定资源名称,accountUriLock改为userid+uri作为标识,作为测试写死
// 设置锁定资源名称,accountUriLock改为userid+uri作为标识,作为测试写死
// String accountUriLockKey = "accountUriLock";
// String accountUriLockKey = "accountUriLock";
...
@@ -51,13 +71,36 @@ public class NotRepeatSubmitConfig extends BaseController {
...
@@ -51,13 +71,36 @@ public class NotRepeatSubmitConfig extends BaseController {
RLock
accountUriLock
=
redissonClient
.
getLock
(
accountUriLockKey
);
RLock
accountUriLock
=
redissonClient
.
getLock
(
accountUriLockKey
);
boolean
tryLock
;
boolean
tryLock
;
MethodSignature
signature
=
(
MethodSignature
)
proceedingJoinPoint
.
getSignature
();
Method
method
=
signature
.
getMethod
();
String
name
=
method
.
getDeclaringClass
().
getName
();
String
[]
parameterNames
=
signature
.
getParameterNames
();
Map
<
String
,
Object
>
map
=
new
HashMap
<
String
,
Object
>();
Object
[]
values
=
proceedingJoinPoint
.
getArgs
();
String
[]
names
=
((
CodeSignature
)
proceedingJoinPoint
.
getSignature
()).
getParameterNames
();
for
(
int
i
=
0
;
i
<
names
.
length
;
i
++)
{
map
.
put
(
names
[
i
],
values
[
i
]);
}
log
.
info
(
map
+
""
);
CommonPaymentVO
commonPaymentsVO
=
(
CommonPaymentVO
)
map
.
get
(
"commonPaymentVO"
);
//尝试获取分布式锁
//尝试获取分布式锁
//-1为永久 leaseTime 最多等待几秒 上锁以后leaseTime秒自动解锁
//-1为永久 leaseTime 最多等待几秒 上锁以后leaseTime秒自动解锁
tryLock
=
accountUriLock
.
tryLock
(-
1
,
leaseTime
,
TimeUnit
.
MILLISECONDS
);
tryLock
=
accountUriLock
.
tryLock
(-
1
,
leaseTime
,
TimeUnit
.
MILLISECONDS
);
log
.
info
(
"tryLock:"
+
tryLock
);
log
.
info
(
"tryLock:"
+
tryLock
);
if
(
tryLock
)
{
if
(
tryLock
)
{
try
{
try
{
String
orderNumber
=
commonPaymentsVO
.
getOrderNumber
();
String
json
=
stringRedisTemplate
.
opsForValue
().
get
(
orderNumber
);
GetOrderNumberDTO
getOrderNumberDTO
=
JSONObject
.
parseObject
(
json
,
GetOrderNumberDTO
.
class
);
GetOrderNumberDO
getOrderNumberDO
=
new
GetOrderNumberDO
(
getOrderNumberDTO
);
if
(
getOrderNumberDTO
.
getRequirementsInfoId
()!=
null
){
int
i
=
releaseOrderDao
.
selectOrderNumberDO
(
getOrderNumberDO
.
getRequirementsInfoId
());
if
(
i
!=
0
){
return
ResultBody
.
error
(
"当前需求已有人支付"
);
}
}
// 查询订单库存判断是否大于0
// 查询订单库存判断是否大于0
// 大于0表示还有库存可以更新订单库存将库存数字减一更新到数据库中
// 大于0表示还有库存可以更新订单库存将库存数字减一更新到数据库中
// 不大于0表示没有库存了本次请求就终止
// 不大于0表示没有库存了本次请求就终止
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论