package com.boman.system.service.impl;

import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.boman.domain.SysUser;
import com.boman.system.service.ISysMenuService;
import com.boman.system.service.ISysPermissionService;
import com.boman.system.service.ISysRoleService;

@Service
public class SysPermissionServiceImpl implements ISysPermissionService
{
    @Autowired
    private ISysRoleService roleService;

    @Autowired
    private ISysMenuService menuService;

    /**
     * 获取角色数据权限
     * 
     * @param id 用户Id
     * @return 角色权限信息
     */
    @Override
    public Set<String> getRolePermission(Long id)
    {
        Set<String> roles = new HashSet<String>();
        // 管理员拥有所有权限
        if (SysUser.isAdmin(id))
        {
            roles.add("admin");
        }
        else
        {
            roles.addAll(roleService.selectRolePermissionById(id));
        }
        return roles;
    }

    /**
     * 获取菜单数据权限
     * 
     * @param id 用户Id
     * @return 菜单权限信息
     */
    @Override
    public Set<String> getMenuPermission(Long id)
    {
        Set<String> perms = new HashSet<String>();
        // 管理员拥有所有权限
        if (SysUser.isAdmin(id))
        {
            perms.add("*:*:*");
        }
        else
        {
            perms.addAll(menuService.selectMenuPermsById(id));
        }
        return perms;
    }
}
