package com.huiju.estateagents.base;

import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.exception.EstaException;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;

/**
 * 用户控制
 */
public class UserControl {

    /**
     * 获取用户信息
     * @return
     */
    public static TaUser getUser() {
        ServletRequestAttributes servletRequestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
        HttpSession session = servletRequestAttributes.getRequest().getSession();
        TaUser taUser = (TaUser) session.getAttribute("miniapp_user");
        if (null == taUser) {
            throw new EstaException("用户信息不存在, 请登录!");
        }
        return taUser;
    }

    /**
     * 获取公司 org_id
     * @return
     */
    public static Integer getOrgId() {
        TaUser user = getUser();
        return user.getOrgId();
    }

}
