Files
xiu_b/src/main/java/com/tailbet/model/vo/UserContext.java
T
2026-08-05 13:48:48 +08:00

47 lines
1.1 KiB
Java

package com.tailbet.model.vo;
/**
* 用户上下文 - ThreadLocal保存当前登录用户
*/
public class UserContext {
private static final ThreadLocal<LoginUserVo> USER = new ThreadLocal<>();
public static void setUser(LoginUserVo user) {
USER.set(user);
}
public static LoginUserVo getUser() {
return USER.get();
}
public static Long getUserId() {
LoginUserVo user = USER.get();
return user != null ? user.getUserId() : null;
}
public static void remove() {
USER.remove();
}
public static boolean isOps() {
LoginUserVo user = USER.get();
return user != null && Boolean.TRUE.equals(user.getIsOps());
}
public static boolean isBot() {
LoginUserVo user = USER.get();
return user != null && Boolean.TRUE.equals(user.getIsBot());
}
public static boolean isFake() {
LoginUserVo user = USER.get();
return user != null && Boolean.TRUE.equals(user.getIsFake());
}
public static boolean isWhite() {
LoginUserVo user = USER.get();
return user != null && Boolean.TRUE.equals(user.getIsWhite());
}
}