package io.renren.interceptor;


import io.renren.dto.AppSysUserDTO;

public class ThreadLocalLoginUser {

    private static ThreadLocal<AppSysUserDTO> loginUserThreadLocal=new ThreadLocal<AppSysUserDTO>();

    /**
     * 从ThreadLocal里获取缓存的值
     * @return 要获取的值
     */
    public static AppSysUserDTO get() {
        AppSysUserDTO user = loginUserThreadLocal.get();
        return user;
    }

    /**
     * 从ThreadLocal里获取缓存的值
     * @return 要获取的值
     */
    public static Long getUserId() {
        AppSysUserDTO user = loginUserThreadLocal.get();
        return user!=null? user.getId():null;
    }

    /**
     * 向ThreadLocal缓存值
     */
    public static void set(AppSysUserDTO userEntity) {
        loginUserThreadLocal.set(userEntity);
    }

    /**
     * 移除缓存里的数据
     */
    public static void remove(){
        loginUserThreadLocal.remove();
    }

}