package com.ruoyi.framework.interceptor;


import com.ruoyi.common.core.domain.model.UserExtendInfo;
import com.ruoyi.user.domain.User;

public class UserContext {

    static final ThreadLocal<User> CTX = new ThreadLocal<>();

    private UserContext(User user) {
        CTX.set(user);
    }

    public static UserContext setUser(User user) {
        return new UserContext(user);
    }

    public static User currentUser() {
        return CTX.get();
    }

    /**
     * 获取用户扩展信息
     * @return
     */
    public static UserExtendInfo currentUserExtendInfo() {
        return CTX.get().getUserExtendInfo();
    }


    public static void close() {
        CTX.remove();
    }
}
