package com.fs.app.controller;


import com.fs.app.utils.JwtUtils;
import com.fs.common.core.redis.RedisCache;
import com.fs.common.utils.ServletUtils;
import com.fs.common.utils.StringUtils;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 基类控制器
 * 集成jwt redis
 */
public class AppBaseController {
	@Autowired
	protected JwtUtils jwtUtils;
	@Autowired
	protected RedisCache redisCache;

	public String getUserId()
	{
		String headValue =  ServletUtils.getRequest().getHeader("APPToken");
		if(StringUtils.isNotEmpty(headValue)){
			Claims claims=jwtUtils.getClaimByToken(headValue);
			if(StringUtils.isNotEmpty(claims)){
				return claims.getSubject();
			}
			else{
				return null;
			}
		}
		else{
			return null;
		}
	}
}
