!467 新增 ThreadLocalHolder 整合 SaHolder,ThreadLocal

* fix 修复 issue#I8RWB5 字段缺少问题 ;
* add 新增 ThreadLocalHolder 替换 SaHolder ;
This commit is contained in:
MichelleChung
2023-12-29 03:39:15 +00:00
committed by 疯狂的狮子Li
parent 84671e5972
commit 4ceb79afa3
11 changed files with 155 additions and 80 deletions

View File

@ -5,6 +5,7 @@ import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.crypto.SecureUtil;
import org.dromara.common.core.constant.GlobalConstants;
import org.dromara.common.core.context.ThreadLocalHolder;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.exception.ServiceException;
import org.dromara.common.core.utils.MessageUtils;
@ -36,7 +37,7 @@ import java.util.StringJoiner;
@Aspect
public class RepeatSubmitAspect {
private static final ThreadLocal<String> KEY_CACHE = new ThreadLocal<>();
private static final String KEY_CACHE = "keyCache";
@Before("@annotation(repeatSubmit)")
public void doBefore(JoinPoint point, RepeatSubmit repeatSubmit) throws Throwable {
@ -59,7 +60,7 @@ public class RepeatSubmitAspect {
// 唯一标识指定key + url + 消息头)
String cacheRepeatKey = GlobalConstants.REPEAT_SUBMIT_KEY + url + submitKey;
if (RedisUtils.setObjectIfAbsent(cacheRepeatKey, "", Duration.ofMillis(interval))) {
KEY_CACHE.set(cacheRepeatKey);
ThreadLocalHolder.set(KEY_CACHE, cacheRepeatKey);
} else {
String message = repeatSubmit.message();
if (StringUtils.startsWith(message, "{") && StringUtils.endsWith(message, "}")) {
@ -82,9 +83,10 @@ public class RepeatSubmitAspect {
if (r.getCode() == R.SUCCESS) {
return;
}
RedisUtils.deleteObject(KEY_CACHE.get());
String cacheKey = ThreadLocalHolder.get(KEY_CACHE);
RedisUtils.deleteObject(cacheKey);
} finally {
KEY_CACHE.remove();
ThreadLocalHolder.remove(KEY_CACHE);
}
}
}
@ -97,8 +99,9 @@ public class RepeatSubmitAspect {
*/
@AfterThrowing(value = "@annotation(repeatSubmit)", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, RepeatSubmit repeatSubmit, Exception e) {
RedisUtils.deleteObject(KEY_CACHE.get());
KEY_CACHE.remove();
String cacheKey = ThreadLocalHolder.get(KEY_CACHE);
RedisUtils.deleteObject(cacheKey);
ThreadLocalHolder.remove(KEY_CACHE);
}
/**