Search in sources :

Example 1 with RoleMenuRelation

use of com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation in project Corgi by kevinYin.

the class MenuServiceImpl method gainHasPermissionMenu.

/**
 * 获取有权限的菜单
 *
 * @param accountId
 * @param menuList
 * @return
 */
private List<MenuPO> gainHasPermissionMenu(long accountId, List<MenuPO> menuList) {
    if (adminAccountService.isSuperAdmin(accountId)) {
        return menuList;
    }
    // 读取角色
    List<AccountRoleRelation> accountRoleList = adminAccountService.listAccountRoles(accountId);
    List<RoleMenuRelation> roleMenuList = new LinkedList<>();
    // 读取每个角色的菜单ID
    for (AccountRoleRelation arr : accountRoleList) {
        roleMenuList.addAll(roleService.listRoleMenus(arr.getRoleId()));
    }
    Set<Integer> accountMenuIdSet = new HashSet<>(roleMenuList.size());
    for (RoleMenuRelation rmr : roleMenuList) {
        accountMenuIdSet.add(Integer.valueOf(rmr.getMenuId()));
    }
    // 判断哪个菜单有权限
    List<MenuPO> list = new LinkedList<>();
    StringBuilder buf = new StringBuilder(1024);
    for (MenuPO menuPO : menuList) {
        if (accountMenuIdSet.contains(Integer.valueOf(menuPO.getMenuId()))) {
            list.add(menuPO);
            if (buf.length() > 0)
                buf.append(" , ");
            buf.append(menuPO.getMenuId()).append(": ").append(menuPO.getMenuName());
        }
    }
    return list;
}
Also used : AccountRoleRelation(com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation) MenuPO(com.ibeiliao.deployment.admin.po.account.MenuPO) RoleMenuRelation(com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)

Example 2 with RoleMenuRelation

use of com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation in project Corgi by kevinYin.

the class EditRoleController method listAllAppMenu.

/**
 * 读取所有APP的菜单,及角色的菜单权限
 * @param roleId 角色ID
 * @return
 */
@MenuResource("读取角色菜单")
@RequestMapping("allAppMenus")
@ResponseBody
public Map<String, Object> listAllAppMenu(int roleId) {
    Map<String, Object> map = new HashMap<>(4);
    List<AppDefine> apps = appService.listAll();
    List<MenuItem> appMenus = new ArrayList<>(apps.size());
    for (AppDefine app : apps) {
        appMenus.add(menuService.getMenuTree(app.getAppId()));
    }
    map.put("success", Boolean.TRUE);
    map.put("appList", apps);
    map.put("appMenus", appMenus);
    if (roleId > 0) {
        List<RoleMenuRelation> menuIds = roleService.listRoleMenus(roleId);
        map.put("menuIds", menuIds);
        Role role = roleService.getById(roleId);
        map.put("role", role);
        List<RoleResRelation> resList = roleService.listRoleResources(roleId);
        map.put("resIds", resList);
    }
    return map;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem) Role(com.ibeiliao.deployment.admin.vo.account.Role) RoleResRelation(com.ibeiliao.deployment.admin.vo.account.RoleResRelation) AppDefine(com.ibeiliao.deployment.admin.vo.account.AppDefine) RoleMenuRelation(com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

RoleMenuRelation (com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)2 MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)1 MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)1 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)1 AccountRoleRelation (com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation)1 AppDefine (com.ibeiliao.deployment.admin.vo.account.AppDefine)1 Role (com.ibeiliao.deployment.admin.vo.account.Role)1 RoleResRelation (com.ibeiliao.deployment.admin.vo.account.RoleResRelation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1