Search in sources :

Example 11 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuServiceImpl method buildTreeMap.

/**
 * 建立菜单树
 *
 * @param appId
 *            - 应用系统ID
 * @param root
 *            - 根节点
 * @param menuList
 *            - 菜单列表
 */
private void buildTreeMap(int appId, MenuItem root, List<MenuPO> menuList) {
    Map<Integer, MenuItem> tmpMap = new HashMap<>(menuList.size() * 4 / 3);
    // 2014/8/14 增加,原因:个别程序员增加了几个找不到 parentMenuId 的菜单,导致死循环
    final int LOOP_MAX = menuList.size() * menuList.size() + 10;
    int loopCount = 0;
    int i;
    for (i = 0; i < menuList.size() && loopCount < LOOP_MAX; ) {
        MenuPO menu = menuList.get(i);
        if (menu.getParentMenuId() == 0) {
            if (tmpMap.containsKey(menu.getMenuId())) {
                // 忽略,不可能出现
                ;
            } else {
                MenuItem item = new MenuItem(menu.getMenuName(), "");
                item.setId(menu.getMenuId());
                item.setSequence(menu.getSequence());
                root.createChildren().add(item);
                tmpMap.put(menu.getMenuId(), item);
            }
            i++;
        } else {
            MenuItem parent = tmpMap.get(menu.getParentMenuId());
            if (parent == null) {
                // 找不到父菜单,放到队列后面处理
                if (i == menuList.size() - 1) {
                    // 如果已经跑到队列最后,终止,避免死循环
                    break;
                }
                // 碰到有问题的菜单,可能有死循环 2014/8/14
                menuList.remove(i);
                // 放到最后
                menuList.add(menu);
            } else {
                // 增加一个子菜单
                MenuItem item = new MenuItem(menu.getMenuName(), "");
                item.setId(menu.getMenuId());
                item.setSequence(menu.getSequence());
                parent.createChildren().add(item);
                tmpMap.put(menu.getMenuId(), item);
                // next
                i++;
            }
        }
        ++loopCount;
    }
    if (loopCount >= LOOP_MAX) {
        MenuPO tmp = (i < menuList.size() ? menuList.get(i) : null);
        logger.info("菜单死循环, LOOP_MAX=" + LOOP_MAX + ", appId=" + appId + ", 有问题的菜单=" + JsonUtil.toJSONString(tmp));
    }
}
Also used : MenuPO(com.ibeiliao.deployment.admin.po.account.MenuPO) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Example 12 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class MenuServiceImpl method getMenuTree.

@Override
public MenuItem getMenuTree(long accountId, int appId) {
    if (accountId <= 0) {
        return new MenuItem("root", "", true);
    }
    List<MenuPO> menuList = menuDao.listByAppId(appId);
    menuList = gainHasPermissionMenu(accountId, menuList);
    MenuItem root = new MenuItem("root", "", true);
    if (menuList.size() > 0) {
        buildTreeMap(appId, root, menuList);
        loadMenuResource(appId, root);
    }
    return root;
}
Also used : MenuPO(com.ibeiliao.deployment.admin.po.account.MenuPO) MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Example 13 with MenuItem

use of com.ibeiliao.deployment.admin.utils.resource.MenuItem in project Corgi by kevinYin.

the class HtmlMenuGenerator method outputMenu.

/**
 * 递归输出每个菜单的HTML代码
 * @param menu - 当前菜单项
 * @param buf - 输出缓存
 * @param level - 第几级菜单
 */
private static void outputMenu(MenuItem menu, StringBuilder buf, int level) {
    List<MenuItem> children = menu.getChildren();
    String jspxUrl = findJspUrl(children);
    // boolean active = activeUrl.equals(jspxUrl);
    String space = "\t";
    if (level == 2) {
        space = "\t\t\t";
    } else if (level >= 3) {
        space = "\t\t\t\t";
    }
    // 如果这个菜单下面的children,全是 .jspx, .do,说明已经到最里面的菜单了,直接输出 jspx页面的链接
    if (children == null || children.isEmpty() || jspxUrl != null) {
        buf.append(space).append("<li>");
        // 已经到了最底的子页面
        buf.append("<a href=\"").append(jspxUrl).append("\"><i class=\"fa fa-link\"></i>").append(menu.getName()).append("</a>");
        buf.append("</li>\n");
    } else {
        buf.append(space);
        if (level == 1) {
            buf.append("<li class=\"treeview\">\n");
        } else {
            buf.append("<ul class=\"treeview-menu\">\n");
        }
        buf.append(space).append("\t").append("<a href=\"#\">");
        // if (level > 1) {
        // 有下级菜单输出一个小图标
        buf.append("<i class=\"fa fa-list-ul\"></i>");
        // }
        buf.append(menu.getName()).append("<i class=\"fa fa-angle-left pull-right\"></i></a>\n");
        buf.append(space).append("\t").append("<ul class=\"treeview-menu\">\n");
        for (MenuItem child : children) {
            // render next level
            outputMenu(child, buf, level + 1);
        }
        buf.append(space).append("\t").append("</ul>\n");
        buf.append(space);
        if (level == 1) {
            buf.append("</li>\n");
        } else {
            buf.append("</ul>\n");
        }
    }
}
Also used : MenuItem(com.ibeiliao.deployment.admin.utils.resource.MenuItem)

Aggregations

MenuItem (com.ibeiliao.deployment.admin.utils.resource.MenuItem)13 MenuPO (com.ibeiliao.deployment.admin.po.account.MenuPO)5 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 RestResult (com.ibeiliao.deployment.admin.common.RestResult)1 UrlResourcePO (com.ibeiliao.deployment.admin.po.account.UrlResourcePO)1 MenuResource (com.ibeiliao.deployment.admin.utils.resource.MenuResource)1 AppDefine (com.ibeiliao.deployment.admin.vo.account.AppDefine)1 Role (com.ibeiliao.deployment.admin.vo.account.Role)1 RoleMenuRelation (com.ibeiliao.deployment.admin.vo.account.RoleMenuRelation)1 RoleResRelation (com.ibeiliao.deployment.admin.vo.account.RoleResRelation)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1