feat: 排行榜普通方法
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.landaiqing.subject.common.context;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* @Classname LoginContextHolder
|
||||
* @BelongsProject: qing-yu-club
|
||||
* @BelongsPackage: com.landaiqing.subject.application.context
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-03-03 18:11
|
||||
* @Description: 登录上下文对象
|
||||
* @Version: 1.0
|
||||
*/
|
||||
public class LoginContextHolder {
|
||||
private static final InheritableThreadLocal <Map<String,Object>> THREAD_LOCAL=new InheritableThreadLocal<>();
|
||||
|
||||
public static void set(String key,Object val){
|
||||
Map<String,Object> map=getThreadLoacalMap();
|
||||
map.put(key, val);
|
||||
}
|
||||
public static Object get(String key){
|
||||
Map<String,Object> threadLoacalMap=getThreadLoacalMap();
|
||||
return threadLoacalMap.get(key);
|
||||
}
|
||||
public static void remove(){
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static String getLoginId(){
|
||||
return (String) getThreadLoacalMap().get("loginId");
|
||||
}
|
||||
public static Map<String,Object> getThreadLoacalMap(){
|
||||
Map<String,Object> map =THREAD_LOCAL.get();
|
||||
if (Objects.isNull(map)){
|
||||
map=new ConcurrentHashMap<>();
|
||||
THREAD_LOCAL.set(map);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package com.landaiqing.subject.common.util;
|
||||
|
||||
import com.landaiqing.subject.common.context.LoginContextHolder;
|
||||
|
||||
/**
|
||||
* @Classname LoginUtil
|
||||
* @BelongsProject: qing-yu-club
|
||||
* @BelongsPackage: com.landaiqing.subject.application.util
|
||||
* @Author: landaiqing
|
||||
* @CreateTime: 2024-03-03 18:33
|
||||
* @Description: 用户登录util
|
||||
* @Version: 1.0
|
||||
*/
|
||||
|
||||
public class LoginUtil {
|
||||
public static String getLoginId() {
|
||||
return LoginContextHolder.getLoginId();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user