package com.xhpc.common.util;

import com.xhpc.common.core.constant.CacheConstants;
import com.xhpc.common.redis.service.RedisService;
import com.xhpc.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class LogUserUtils {

    @Autowired
    private RedisService redisService;

    /**
     * 获取登录信息
     *
     * @param request 请求参数
     * @return LoginUser 登录用户信息
     */
    public LoginUser getLogUser(HttpServletRequest request) {
        String token = request.getHeader(CacheConstants.HEADER);
        token = token.substring(7);
        LoginUser loginUser = new LoginUser();
        try {
            loginUser = redisService.getCacheObject(CacheConstants.LOGIN_TOKEN_KEY + token);
        } catch (Exception e) {
        }
        return loginUser;
    }
}
