// fs-admin模块
package com.fs.framework.config;

import com.fs.common.config.LoginContextCallback;
import com.fs.common.core.domain.model.LoginUser;
import com.fs.common.enums.DataScopeEnum;
import com.fs.common.enums.PlatEnum;
import com.fs.common.utils.SecurityUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * Admin端登录上下文回调实现
 */
@Component
public class AdminLoginContextCallback implements LoginContextCallback, ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public Long getUserId() {
        try {
            return SecurityUtils.getUserId();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Long getCompanyUserId() {
        // Admin端没有companyUserId概念
        return null;
    }

    @Override
    public String getUsername() {
        try {
            return SecurityUtils.getUsername();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public String getCompanyUserName() {
        // Admin端没有companyUserName概念
        return null;
    }

    @Override
    public Long getCompanyId() {
        // Admin端没有companyId概念，返回null
        return null;
    }

    @Override
    public Long getDeptId() {
        try {
            return SecurityUtils.getDeptId();
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public DataScopeEnum getDataScope() {
        return DataScopeEnum.ALL;
    }

    @Override
    public PlatEnum getNowPlatEnum() {
        return PlatEnum.ADMIN;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        AdminLoginContextCallback.applicationContext = applicationContext;
    }
}
