Browse Source

Merge remote-tracking branch 'origin/master'

dev
wangxianzhang 3 years ago
parent
commit
c95cadf150
  1. 12
      epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aop/NoRepeatSubmitAop.java

12
epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/aop/NoRepeatSubmitAop.java

@ -47,9 +47,10 @@ public class NoRepeatSubmitAop {
// 如果缓存中有这个url视为重复提交
Object result = null;
RLock lock = null;
try {
try {
//key 为空则直接跳过 不加锁
if (key != null){
if (key != null) {
long leaseTime = noRepeatSubmit.leaseTime();
//如果获取不到锁等待0秒直接返回 持锁时间为leaseTime
lock = distributedLock.getLock(RedisKeys.getNoRepeatSubmitKey(key), leaseTime, NumConstant.ZERO_L, TimeUnit.MILLISECONDS);
@ -59,23 +60,18 @@ public class NoRepeatSubmitAop {
log.warn("noRepeatSubmit key:{},msg:{}", key, e.getMessage());
//"未获取到锁,重复提交了
throw new RenException(EpmetErrorCode.REPEAT_SUBMIT.getCode());
} finally {
distributedLock.unLock(lock);
}
try {
//因为getLock如果获取失败抛异常 所以不做锁状态的判断
//执行业务代码
result = pjp.proceed();
} finally {
distributedLock.unLock(lock);
}
return result;
}
private String getKey(String keyExpress, String token) {
log.debug("getKey param keyExpress:{},token:{}",keyExpress,token);
log.debug("getKey param keyExpress:{},token:{}", keyExpress, token);
if (StringUtils.isBlank(token)) {
return null;
}

Loading…
Cancel
Save