|
|
@ -1,11 +1,13 @@ |
|
|
|
package com.epmet.commons.tools.aop; |
|
|
|
|
|
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
import com.epmet.commons.tools.constant.StrConstant; |
|
|
|
import com.epmet.commons.tools.distributedlock.DistributedLock; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
@ -46,10 +48,13 @@ public class NoRepeatSubmitAop { |
|
|
|
Object result = null; |
|
|
|
RLock lock = null; |
|
|
|
try { |
|
|
|
//key 为空则直接跳过 不加锁
|
|
|
|
if (key != null){ |
|
|
|
long leaseTime = noRepeatSubmit.leaseTime(); |
|
|
|
//如果获取不到锁等待0秒直接返回 持锁时间为leaseTime
|
|
|
|
lock = distributedLock.getLock(RedisKeys.getNoRepeatSubmitKey(key), leaseTime, NumConstant.ZERO_L, TimeUnit.MILLISECONDS); |
|
|
|
//因为getLock如果获取失败抛异常 所以不做锁状态的判断
|
|
|
|
} |
|
|
|
result = pjp.proceed(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.warn("noRepeatSubmit key:{},msg:{}", key, e.getMessage()); |
|
|
@ -64,7 +69,10 @@ public class NoRepeatSubmitAop { |
|
|
|
} |
|
|
|
|
|
|
|
private String getKey(String keyExpress, String token) { |
|
|
|
return keyExpress + token; |
|
|
|
if (StringUtils.isBlank(token)) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
return keyExpress + StrConstant.UNDER_LINE + token; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|