package io.github.qifan777.knowledge.context;


public class UserContext {

    private static final ThreadLocal<String> idThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<String> nameThreadLocal = new ThreadLocal<>();
    private static final ThreadLocal<Integer> roleIdThreadLocal = new ThreadLocal<>();

    public static String getThreadUserId(){
        return idThreadLocal.get();
    }

    public static void setThreadUserId(String id){
        idThreadLocal.set(id);
    }


    public static Integer getThreadUserRoleId(){
        return roleIdThreadLocal.get();
    }

    public static void setThreadUserRoleId(Integer id){
        roleIdThreadLocal.set(id);
    }

    public static String getThreadUserName(){
        return nameThreadLocal.get();
    }

    public static void setThreadUserName(String name){
        nameThreadLocal.set(name);
    }

    public static void clear(){
        idThreadLocal.remove();
        nameThreadLocal.remove();
        roleIdThreadLocal.remove();
    }
}
