package com.dxhy.gate.v2.service.impl;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.dxhy.common.constant.RedisConstant;
import com.dxhy.common.util.redis.RedisUtils;
import com.dxhy.gate.v2.service.TokenService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author jiaohongyang
 */
@Service("tokenService")
@Slf4j
public class TokenServiceImpl implements TokenService {
    @Value("${token.expore}")
    private long expore;
    @Resource
    private RedisUtils redisUtils;

    /**
     * 获取token中个信息
     *
     * @param loginname
     *            登录名
     * @param token
     *            token
     * @return 返回信息
     */
    @Override
    public String getToken(String loginname, String token) {
        log.debug("获取token：" + token);
        String userToken = redisUtils.get(RedisConstant.KEY_TOKEN + loginname);
        if (StringUtils.isNotBlank(userToken)) {
            redisUtils.set(RedisConstant.KEY_TOKEN + loginname, token, expore);
            return token;
        } else {
            return null;
        }
    }
}
