package com.xiaomai.utils;

import org.springframework.test.context.ContextConfiguration;

import java.util.Hashtable;
@ContextConfiguration(locations = {"classpath:/spring-core.xml", "classpath:/applicationContext.xml"})
public class CommonLoginInfo {
    private Hashtable<String, CommonRequestParameters> loginInfoMap ;
    public Hashtable<String, CommonRequestParameters> getLoginInfoMap() {
        return loginInfoMap;
    }

    public void setLoginInfoMap(Hashtable<String, CommonRequestParameters> loginInfoMap) {
        this.loginInfoMap = new Hashtable<String, CommonRequestParameters>();
    }

    public void add(String loginUser, CommonRequestParameters loginInfo){
        if(null == loginInfoMap){
            loginInfoMap =  new Hashtable<String, CommonRequestParameters>();
        }
        this.loginInfoMap.put(loginUser,loginInfo);
    }

    public CommonRequestParameters get(String loginUser){
        if(null == loginInfoMap){
            return  new CommonRequestParameters();
        }
        if(null ==loginInfoMap.get(loginUser) ){
            return  new CommonRequestParameters();
        }
        return loginInfoMap.get(loginUser);
    }

    /**
     * 获取登录信息user   未取到信息将自动返回一个 空对象。 使用时自行处理判断
     * @param loginUser
     * @return
     */
    public static CommonRequestParameters  getLoginUser(String loginUser){
        CommonLoginInfo _loginInfoMap = (CommonLoginInfo) SpringContextUtil.getBean("commonLoginInfoMap");
        CommonRequestParameters loginInfo = _loginInfoMap.get(loginUser);
        return  loginInfo;
    }
}
