mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-25 20:35:35 +08:00
优化
This commit is contained in:
70
src/main/java/xyz/playedu/api/BCtx.java
Normal file
70
src/main/java/xyz/playedu/api/BCtx.java
Normal file
@@ -0,0 +1,70 @@
|
||||
package xyz.playedu.api;
|
||||
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BCtx {
|
||||
|
||||
private static final java.lang.ThreadLocal<LinkedHashMap<String, Object>> THREAD_LOCAL = new java.lang.ThreadLocal<>();
|
||||
|
||||
public final static String KEY_ADMIN_USER_ID = "admin_id";
|
||||
public final static String KEY_ADMIN_USER = "admin_user";
|
||||
public final static String KEY_ADMIN_PER = "admin_per";
|
||||
public final static String KEY_CONFIG = "config";
|
||||
|
||||
public BCtx() {
|
||||
}
|
||||
|
||||
private static void put(String key, Object val) {
|
||||
LinkedHashMap<String, Object> hashMap = THREAD_LOCAL.get();
|
||||
if (hashMap == null) {
|
||||
hashMap = new LinkedHashMap<>();
|
||||
}
|
||||
hashMap.put(key, val);
|
||||
THREAD_LOCAL.set(hashMap);
|
||||
}
|
||||
|
||||
private static Object get(String key) {
|
||||
return THREAD_LOCAL.get().getOrDefault(key, null);
|
||||
}
|
||||
|
||||
public static void remove() {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static Integer getAdminUserID() {
|
||||
return (Integer) get(KEY_ADMIN_USER_ID);
|
||||
}
|
||||
|
||||
public static void setAdminUserId(Integer userId) {
|
||||
put(KEY_ADMIN_USER_ID, userId);
|
||||
}
|
||||
|
||||
public static AdminUser getAdminUser() {
|
||||
return (AdminUser) get(KEY_ADMIN_USER);
|
||||
}
|
||||
|
||||
public static void setAdminUser(AdminUser adminUser) {
|
||||
put(KEY_ADMIN_USER, adminUser);
|
||||
}
|
||||
|
||||
public static void setAdminPer(HashMap<String, Boolean> permissions) {
|
||||
put(KEY_ADMIN_PER, permissions);
|
||||
}
|
||||
|
||||
public static HashMap<String, Boolean> getAdminPer() {
|
||||
return (HashMap<String, Boolean>) get(KEY_ADMIN_PER);
|
||||
}
|
||||
|
||||
public static void setConfig(Map<String, String> config) {
|
||||
put(KEY_CONFIG, config);
|
||||
}
|
||||
|
||||
public static Map<String, String> getConfig() {
|
||||
return (Map<String, String>) get(KEY_CONFIG);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user