package com.fs.company.utils;

import com.fs.common.constant.HttpStatus;
import com.fs.common.exception.ServiceException;
import com.fs.his.domain.StoreLoginUser;

import static com.fs.common.utils.SecurityUtils.getAuthentication;

public class UserUtil {

    public static StoreLoginUser getLoginUser()
    {
        try
        {
            return (StoreLoginUser) getAuthentication().getPrincipal();
        }
        catch (Exception e)
        {
            throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
        }
    }


    public static Long getLoginUserStoreID()
    {
        try
        {
            StoreLoginUser principal = (StoreLoginUser) getAuthentication().getPrincipal();
            return principal.getFsStore().getStoreId();
        }
        catch (Exception e)
        {
            throw new ServiceException("获取用户信息异常", HttpStatus.UNAUTHORIZED);
        }
    }
}
