package com.platform.modules.app.controller;

import com.platform.modules.app.interceptor.AuthorizationInterceptor;
import com.platform.modules.sys.entity.SysUserEntity;
import com.platform.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * @author Anine
 * @date 2019/3/12
 */
public abstract class AppAbstractController {
    @Autowired
    private SysUserService sysUserService;
	protected Long getUserId() {

		RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();

        return (Long) requestAttributes.getAttribute(AuthorizationInterceptor.USER_KEY, RequestAttributes.SCOPE_REQUEST);
	}

	protected Long getUserTenantId() {

		RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();

		return (Long) requestAttributes.getAttribute(AuthorizationInterceptor.USER_TENANT_KEY, RequestAttributes.SCOPE_REQUEST);
	}

	protected SysUserEntity getUser(){
	    return sysUserService.selectById(getUserId());
    }
}
