|
@@ -1,22 +1,19 @@
|
|
|
package com.ym.mec.student.interceptor;
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
import com.ym.mec.common.filters.TenantIdThreadLocal;
|
|
|
-
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
+import com.ym.mec.util.web.WebUtil;
|
|
|
import org.slf4j.MDC;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
|
|
|
|
|
-import com.ym.mec.util.web.WebUtil;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.util.UUID;
|
|
|
|
|
|
@Component
|
|
|
public class MDCInterceptor extends HandlerInterceptorAdapter {
|
|
@@ -24,6 +21,8 @@ public class MDCInterceptor extends HandlerInterceptorAdapter {
|
|
|
private static final String IP = "ip";
|
|
|
|
|
|
private static final String USERNAME = "username";
|
|
|
+
|
|
|
+ private static final String REQ_ID = "reqId";
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private SysUserFeignService sysUserFeignService;
|
|
@@ -39,13 +38,11 @@ public class MDCInterceptor extends HandlerInterceptorAdapter {
|
|
|
}else {
|
|
|
TenantIdThreadLocal.set(1);
|
|
|
}
|
|
|
+ // 存储userId以及IP
|
|
|
+ MDC.put(USERNAME, sysUser.getUsername() + "@" + sysUser.getId());
|
|
|
}
|
|
|
- String username = "";
|
|
|
- String userId = "";
|
|
|
- // 存储userId以及IP
|
|
|
- MDC.put(USERNAME, username + "@" + userId);
|
|
|
MDC.put(IP, WebUtil.getRemoteIp(request));
|
|
|
-
|
|
|
+ MDC.put(REQ_ID, UUID.randomUUID().toString());
|
|
|
return true;
|
|
|
}
|
|
|
|