Search in sources :

Example 1 with MenuResourcesRelationPO

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

MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)1 MenuResourcesRelationPO (com.ibeiliao.deployment.admin.po.account.MenuResourcesRelationPO)1 UrlResourcePO (com.ibeiliao.deployment.admin.po.account.UrlResourcePO)1