All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.zznote.basecommon.service.impl.TPermissionServiceImpl Maven / Gradle / Ivy

The newest version!
package com.zznote.basecommon.service.impl;


import com.zznote.basecommon.common.util.LoginHelper;
import com.zznote.basecommon.service.TMenuService;
import com.zznote.basecommon.service.TPermissionService;
import com.zznote.basecommon.service.TRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Set;

@RequiredArgsConstructor
@Service
public class TPermissionServiceImpl implements TPermissionService {

    private final TRoleService roleService;
    private final TMenuService menuService;

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

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy