This commit is contained in:
2026-08-13 16:53:39 +08:00
parent 5210ad34f3
commit ed48da0a78
27 changed files with 392 additions and 313 deletions
@@ -339,7 +339,7 @@ public class OtherUtil {
// }
public static String getHeader(String headerName) {
String value = getHeader(headerName);
String value = getRequest().getHeader(headerName);
if(StringUtils.hasText(value))
return value;
else
@@ -8,8 +8,8 @@ public class UserContext {
private static final ThreadLocal<Integer> ROLE_ID = new ThreadLocal<>();
private static final ThreadLocal<Integer> SCH_ID = new ThreadLocal<>();
private static final ThreadLocal<String> IP = new ThreadLocal<>();
private static final ThreadLocal<Integer> TYPE = new ThreadLocal<>();
// 原有 setter/getter 示例(请确保都有)
public static void setUserId(Integer userId) {
USER_ID.set(userId);
}
@@ -38,7 +38,6 @@ public class UserContext {
return SCH_ID.get();
}
// ⬇️ 新增 IP 的 setter/getter
public static void setIp(String ip) {
IP.set(ip);
}
@@ -46,6 +45,13 @@ public class UserContext {
return IP.get();
}
public static void setType(Integer type) {
TYPE.set(type);
}
public static Integer getType() {
return TYPE.get();
}
@Value
public static class UserInfo {
Integer userId;
@@ -53,15 +59,17 @@ public class UserContext {
Integer roleId;
Integer schId;
String ip;
Integer type;
}
public static UserInfo getCurrentUserInfo() {
public static UserInfo getCurrentUser() {
return new UserInfo(
USER_ID.get(),
USER_NAME.get(),
ROLE_ID.get(),
SCH_ID.get(),
IP.get()
IP.get(),
TYPE.get()
);
}
@@ -72,10 +80,11 @@ public class UserContext {
ROLE_ID.set(info.getRoleId());
SCH_ID.set(info.getSchId());
IP.set(info.getIp());
TYPE.set(info.getType());
}
public static Runnable wrap(Runnable task) {
UserInfo info = getCurrentUserInfo();
UserInfo info = getCurrentUser();
return () -> {
try {
setUserInfo(info);
@@ -92,5 +101,6 @@ public class UserContext {
ROLE_ID.remove();
SCH_ID.remove();
IP.remove();
TYPE.remove();
}
}
}