/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 * <p>
 * https://www.renren.io
 * <p>
 * 版权所有，侵权必究！
 */

package com.ruoyi.api.controller.common;

import cn.hutool.core.util.ObjectUtil;

import com.ruoyi.clock.domain.Employee;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.framework.interceptor.UserContext;
import com.ruoyi.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

/**
 * Controller公共组件
 *
 * @author Mark sunlightcs@gmail.com
 */
public abstract class AbstractApiController {

    @Autowired
    RedisTemplate<String, String> redisTemplate;

    /**
     * 获取会员id
     *
     * @return
     */
    protected Long getUserId() {
        //isThrow 是否抛异常，不抛的话返回常量0
        Employee user = UserContext.currentUser();
        if (ObjectUtil.isNull(user)){
            throw new ServiceException("用户不存在");
        }
        return user.getEmployeeId();

    }

    /**
     * 获取当前登录老师
     *
     * @return
     */
    protected Employee getLoginUser() {
        return UserContext.currentUser();
    }

}
