Search in sources :

Example 1 with AccountRoleRelation

use of com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation 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 AccountRoleRelation

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

the class MenuServiceImpl method listMenuResourceByAccount.

@Override
public List<UrlResource> listMenuResourceByAccount(long accountId, int appId) {
    // 读取角色
    List<AccountRoleRelation> accountRoleList = adminAccountService.listAccountRoles(accountId);
    // List<RoleMenuRelation> roleMenuList = new LinkedList<>();
    // 读取每个角色的菜单ID
    // for (AccountRoleRelation arr : accountRoleList) {
    // roleMenuList.addAll(roleService.listRoleMenus(arr.getRoleId()));
    // }
    /*
		Map<Integer, UrlResourcePO> resourceMap = new HashMap<>(roleMenuList.size() * 4 + 16);

		for (RoleMenuRelation rmr : roleMenuList) {
			List<UrlResourcePO> tmpList = menuResourcesRelationDao.listSpecResourceByMenu(rmr.getMenuId(), appId);
			for (UrlResourcePO res : tmpList) {
				Integer resId = res.getResId();
				if (!resourceMap.containsKey(resId)) {
					resourceMap.put(resId, res);
				}
			}
		}
		Collection<UrlResourcePO> collections = resourceMap.values();
		return VOUtil.fromList(collections, UrlResource.class);
		*/
    Map<Integer, UrlResourcePO> resourceMap = new HashMap<>(10);
    for (AccountRoleRelation arr : accountRoleList) {
        List<UrlResourcePO> list = roleResRelationDao.listResourceByRole(arr.getRoleId());
        for (UrlResourcePO res : list) {
            Integer resId = res.getResId();
            if (!resourceMap.containsKey(resId)) {
                resourceMap.put(resId, res);
            }
        }
    }
    Collection<UrlResourcePO> collections = resourceMap.values();
    return VOUtil.fromList(collections, UrlResource.class);
}
Also used : AccountRoleRelation(com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation) UrlResourcePO(com.ibeiliao.deployment.admin.po.account.UrlResourcePO)

Example 3 with AccountRoleRelation

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

the class ListAccountController method listAccount.

/**
 * 读取管理员列表
 * @param keyword 搜索的关键字
 * @param page 第几页
 * @param pageSize 每页多少
 * @return result.object=数据列表,数据列表不为null
 */
@RequestMapping("queryAccount")
@MenuResource("读取管理员列表")
@ResponseBody
public PageResult<List<AdminAccount>> listAccount(String keyword, int page, int pageSize, HttpServletRequest request) {
    List<AdminAccount> list = adminAccountService.listAccounts(keyword, page, pageSize);
    int total = adminAccountService.statAccount(keyword);
    for (AdminAccount account : list) {
        StringBuilder buf = new StringBuilder();
        List<AccountRoleRelation> tmpList = adminAccountService.listAccountRoles(account.getUid());
        for (AccountRoleRelation arr : tmpList) {
            Role role = roleService.getById(arr.getRoleId());
            if (role != null) {
                if (buf.length() > 0)
                    buf.append(",");
                buf.append(role.getRoleName());
            }
        }
        account.setRoleName(buf.toString());
    }
    PageResult<List<AdminAccount>> result = new PageResult<>(list);
    result.setCurrentPage(page);
    result.setPageSize(pageSize);
    result.setCount(total);
    return result;
}
Also used : Role(com.ibeiliao.deployment.admin.vo.account.Role) AccountRoleRelation(com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation) AdminAccount(com.ibeiliao.deployment.admin.vo.account.AdminAccount) List(java.util.List) PageResult(com.ibeiliao.deployment.admin.common.PageResult) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with AccountRoleRelation

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

the class EditAccountController method getAdmin.

/**
 * 读取管理员信息
 * @param uid 管理员ID
 * @return 返回管理员信息
 */
@RequestMapping("getAdmin")
@MenuResource("读取管理员信息")
@ResponseBody
public RestResult<AdminAccount> getAdmin(long uid) {
    AdminAccount account = adminAccountService.getById(uid);
    RestResult<AdminAccount> result;
    if (account == null) {
        result = new RestResult<>(ApiCode.FAILURE, "管理员不存在:uid=" + uid);
    } else {
        List<AccountRoleRelation> list = adminAccountService.listAccountRoles(uid);
        if (list.size() == 1) {
            account.setRoleId(list.get(0).getRoleId());
        }
        account.setPassword(aesPropertiesEncoder.decode(account.getPassword()));
        result = new RestResult<>(account);
    }
    return result;
}
Also used : AccountRoleRelation(com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation) AdminAccount(com.ibeiliao.deployment.admin.vo.account.AdminAccount) MenuResource(com.ibeiliao.deployment.admin.utils.resource.MenuResource) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

AccountRoleRelation (com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation)4 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)2 AdminAccount (com.ibeiliao.deployment.admin.vo.account.AdminAccount)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 PageResult (com.ibeiliao.deployment.admin.common.PageResult)1 MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)1 UrlResourcePO (com.ibeiliao.deployment.admin.po.account.UrlResourcePO)1 Role (com.ibeiliao.deployment.admin.vo.account.Role)1 RoleMenuRelation (com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)1 List (java.util.List)1