package com.cretin.webservices.interceptor;


import com.cretin.webdb.entity.TbStrTranslateUser;

public class UserContextHolder {
    private static final ThreadLocal<String> ipContext = new ThreadLocal<>();
    private static final ThreadLocal<TbStrTranslateUser> userContext = new ThreadLocal<>();

    public static void setUserInfo(TbStrTranslateUser user) {
        if (user != null)
            userContext.set(user);
    }

    public static int getUserId() {
        TbStrTranslateUser tbStrTranslateUser = userContext.get();
        if (tbStrTranslateUser != null) {
            return tbStrTranslateUser.getId();
        }
        return -1000;
    }

    public static void setIp(String ip) {
        ipContext.set(ip);
    }

    public static TbStrTranslateUser getUserInfo() {
        return userContext.get();
    }

    public static String getIp() {
        return ipContext.get();
    }

    public static void clear() {
        userContext.remove();
        ipContext.remove();
    }
}
