MichelleChung
2023-12-29 4ceb79afa35b2be369b8c84219524d687451974b
ruoyi-common/ruoyi-common-web/src/main/java/org/dromara/common/web/interceptor/PlusWebInvokeTimeInterceptor.java
@@ -2,7 +2,7 @@
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 @@
    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 @@
            }
            StopWatch stopWatch = new StopWatch();
            invokeTimeTL.set(stopWatch);
            ThreadLocalHolder.set(STOP_WATCH_KEY, stopWatch);
            stopWatch.start();
        }
        return true;
@@ -70,10 +70,10 @@
    @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();
        }
    }