!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

@ -2,7 +2,7 @@ package org.dromara.common.web.interceptor;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.ttl.TransmittableThreadLocal;
import org.dromara.common.core.context.ThreadLocalHolder;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.json.utils.JsonUtils;
@ -30,7 +30,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
private final String prodProfile = "prod";
private final TransmittableThreadLocal<StopWatch> invokeTimeTL = new TransmittableThreadLocal<>();
private final String STOP_WATCH_KEY = "stopwatch";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
@ -56,7 +56,7 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
}
StopWatch stopWatch = new StopWatch();
invokeTimeTL.set(stopWatch);
ThreadLocalHolder.set(STOP_WATCH_KEY, stopWatch);
stopWatch.start();
}
return true;
@ -70,10 +70,10 @@ public class PlusWebInvokeTimeInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
if (!prodProfile.equals(SpringUtils.getActiveProfile())) {
StopWatch stopWatch = invokeTimeTL.get();
StopWatch stopWatch = ThreadLocalHolder.get(STOP_WATCH_KEY);
stopWatch.stop();
log.info("[PLUS]结束请求 => URL[{}],耗时:[{}]毫秒", request.getMethod() + " " + request.getRequestURI(), stopWatch.getTime());
invokeTimeTL.remove();
ThreadLocalHolder.clear();
}
}