package com.fs.hisStore.utils;

import com.fs.common.constant.HttpStatus;
import com.fs.common.exception.ServiceException;
import com.fs.hisStore.domain.StoreLoginUserScrm;

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

public class UserUtil {

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


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