Search in sources :

Example 1 with UrlResourcePO

use of com.ibeiliao.deployment.admin.po.account.UrlResourcePO in project Corgi by kevinYin.

the class MenuServiceImpl method loadMenuResource.

/**
 * 加载每个菜单下的资源
 *
 * @param appId
 *            - 应用系统ID
 * @param item
 *            - 菜单项
 */
private void loadMenuResource(int appId, MenuItem item) {
    List<MenuItem> children = item.getChildren();
    if (children == null || children.isEmpty()) {
        // 叶子节点才是带有资源的菜单
        if (item.isRoot()) {
            // 没有菜单
            return;
        }
        MenuPO menu = menuDao.getByAppIdAndMenuName(appId, item.getName());
        List<UrlResourcePO> resList = menuResourcesRelationDao.listSpecResourceByMenu(menu.getMenuId(), appId);
        for (UrlResourcePO res : resList) {
            MenuItem resItem = new MenuItem(res.getUrlName(), res.getUri());
            // TIP chenjianhong 主键提供给界面
            resItem.setId(res.getResId());
            item.createChildren().add(resItem);
        }
    } else {
        for (MenuItem mi : children) {
            loadMenuResource(appId, mi);
        }
    }
}
Also used : MenuPO(com.ibeiliao.deployment.admin.po.account.MenuPO) UrlResourcePO(com.ibeiliao.deployment.admin.po.account.UrlResourcePO) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Example 2 with UrlResourcePO

use of com.ibeiliao.deployment.admin.po.account.UrlResourcePO in project Corgi by kevinYin.

the class MenuServiceImpl method listToBeDeletedResource.

/**
 * 获取待删除的资源
 *
 * @param appId
 * @param root
 * @return
 */
private List<UrlResource> listToBeDeletedResource(int appId, MenuItem root) {
    List<UrlResource> resources = new ArrayList<>();
    List<UrlResourcePO> urlResourcePOs = urlResourceDao.listByApp(appId);
    Map<String, Boolean> resourceMap = mapResources(appId, root);
    for (UrlResourcePO urlResourcePO : urlResourcePOs) {
        String key = urlResourcePO.getAppId() + "_" + urlResourcePO.getUri();
        if (!resourceMap.containsKey(key)) {
            UrlResource resource = VOUtil.from(urlResourcePO, UrlResource.class);
            resources.add(resource);
        }
    }
    return resources;
}
Also used : UrlResource(com.ibeiliao.deployment.admin.vo.account.UrlResource) UrlResourcePO(com.ibeiliao.deployment.admin.po.account.UrlResourcePO)

Example 3 with UrlResourcePO

use of com.ibeiliao.deployment.admin.po.account.UrlResourcePO 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 4 with UrlResourcePO

use of com.ibeiliao.deployment.admin.po.account.UrlResourcePO in project Corgi by kevinYin.

the class MenuServiceImpl method saveMenuResource.

/**
 * 保存资源信息。 NOTE:各资源独立,暂时没有 parentResId
 *
 * @param appId
 *            - 应用系统ID
 * @param item
 *            - 要保存的节点
 * @param parentMenu
 *            - 属于哪个菜单
 */
private void saveMenuResource(int appId, MenuItem item, MenuItem parentMenu) {
    if (parentMenu == null) {
        throw new IllegalArgumentException("资源所属的菜单为空, item=" + item.toString());
    }
    UrlResourcePO res = urlResourceDao.getByAppIdAndUri(appId, item.getUrl());
    MenuPO menu = menuDao.getByAppIdAndMenuName(appId, parentMenu.getName());
    if (menu == null) {
        throw new IllegalArgumentException("资源所属的菜单在数据库里不存在, item=" + item.toString() + ", parent=" + parentMenu.toString());
    }
    if (res == null) {
        // 新增资源
        res = new UrlResourcePO();
        res.setResId(generateIdForName(false, item.getName(), item.getUrl()));
        // 暂时没有 parentResId
        res.setParentResId(0);
        res.setCreateTime(new Date());
        res.setLastModify(res.getCreateTime());
        res.setAppId(appId);
        res.setUrlName(item.getName());
        res.setOperator(AdminContext.getAccountId());
        res.setSequence(0);
        res.setUri(item.getUrl());
        urlResourceDao.save(res);
        res = urlResourceDao.getByAppIdAndUri(appId, item.getUrl());
    } else {
        // 更新资源
        // 暂时没有 parentResId
        res.setParentResId(0);
        res.setUrlName(item.getName());
        res.setOperator(AdminContext.getAccountId());
        res.setLastModify(new Date());
        // 注:这里不能更新uri,如果是新的uri,应该是新的记录
        // name,parent_res_id,operator,type,sequence=,last_modify
        urlResourceDao.updateRes(res);
    }
    // 保存菜单和资源的关系
    MenuResourcesRelationPO relation = menuResourcesRelationDao.getMenuResource(menu.getMenuId(), res.getResId());
    if (relation == null) {
        relation = new MenuResourcesRelationPO();
        relation.setMenuId(menu.getMenuId());
        relation.setResId(res.getResId());
        menuResourcesRelationDao.save(relation);
    }
}
Also used : MenuPO(com.ibeiliao.deployment.admin.po.account.MenuPO) MenuResourcesRelationPO(com.ibeiliao.deployment.admin.po.account.MenuResourcesRelationPO) UrlResourcePO(com.ibeiliao.deployment.admin.po.account.UrlResourcePO)

Aggregations

UrlResourcePO (com.ibeiliao.deployment.admin.po.account.UrlResourcePO)4 MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)2 MenuResourcesRelationPO (com.ibeiliao.deployment.admin.po.account.MenuResourcesRelationPO)1 MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)1 AccountRoleRelation (com.ibeiliao.deployment.admin.vo.account.AccountRoleRelation)1 UrlResource (com.ibeiliao.deployment.admin.vo.account.UrlResource)1