package com.huiju.foyo.session;

import com.huiju.foyo.model.SysUser;
import lombok.extern.slf4j.Slf4j;

/**
 * session 操作
 * @author weiximei
 */
@Slf4j
public class SessionLoad {

    private static ThreadLocal<SysUser> threadLocal = new ThreadLocal<>();

    /**
     * 设置用户信息
     * @param user
     */
    public static void setUser(SysUser user){
        log.info("当前线程 --- [{}] --- 设置用户 {} ", Thread.currentThread().getName(), user);
        threadLocal.set(user);
    }

    /**
     * 获取用户信息
     * @return
     */
    public static SysUser getUser() {
        SysUser user = threadLocal.get();
        log.info("当前线程 --- [{}] --- 获取用户 {} ", Thread.currentThread().getName(), user);
        return user;
    }

    /**
     * 移除用户
     */
    public static void removeUser() {
        threadLocal.remove();
    }

}
