package com.ema.admin.handler;

import cn.dev33.satoken.stp.StpInterface;
import com.ema.admin.modules.system.service.SysAuthService;
import com.ema.admin.modules.system.vo.SysUserVo;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 自定义权限加载接口实现类,
 * 可根据业务需要在实现方法里实现自己的权限加载逻辑
 */
@Component
public class SaTokenStpInterface implements StpInterface {

    @Resource
    private SysAuthService sysAuthService;

    /**
     * 返回一个账号所拥有的权限码集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        SysUserVo currentUser = sysAuthService.getCurrentUser();
        return Objects.isNull(currentUser) ? null : currentUser.getPermsKeys();
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        SysUserVo currentUser = sysAuthService.getCurrentUser();
        return Objects.isNull(currentUser) ? null : currentUser.getRoleKeys();
    }

}

