public String getMenu(long parent, SysUser user) { StringBuffer menu = new StringBuffer(""); List<SysApplication> list = getAccessAppList(parent, user); if (list == null || list.isEmpty()) { if (user.isSystemAdmin()) { list = getApplicationList((int) parent); } } if (list != null && list.size() > 0) { Iterator<SysApplication> iter = list.iterator(); while (iter.hasNext()) { SysApplication bean = (SysApplication) iter.next(); menu.append("<li>"); menu.append("<a href=\"javascript:jump('"); // System.out.println("ContextUtil.getContextPath():"+ContextUtil.getContextPath()); if (bean.getUrl() != null && bean.getUrl().startsWith("/")) { if (ApplicationContext.getContextPath() != null) { menu.append(ApplicationContext.getContextPath()); } } menu.append(bean.getUrl()); menu.append("',"); menu.append(bean.getShowMenu()); menu.append(");\">"); menu.append(bean.getName()).append("</a>\n"); List<SysApplication> sonNode = getAccessAppList(bean.getId(), user); if (sonNode == null || sonNode.isEmpty()) { if (user.isSystemAdmin()) { sonNode = getApplicationList((int) bean.getId()); } } if (sonNode != null && sonNode.size() > 0) { // 有子菜单 menu.append("<ul>"); menu.append(getMenu(bean.getId(), user)); menu.append("</ul>"); } menu.append("</li>").append("<li></li>\n"); } } return menu.toString(); }
public JSONArray getUserMenu(long parent, String actorId) { JSONArray array = new JSONArray(); SysUser user = authorizeService.login(actorId); if (user != null) { List<SysTree> treeList = null; SysApplication app = this.findById(parent); SysTreeQuery query = new SysTreeQuery(); query.treeId(app.getNode().getTreeId()); query.treeIdLike(app.getNode().getTreeId() + "%"); if (!user.isSystemAdmin()) { List<String> actorIds = new java.util.ArrayList<String>(); List<Object> rows = entityService.getList("getAgents", actorId); if (rows != null && !rows.isEmpty()) { for (Object object : rows) { if (object instanceof Agent) { Agent agent = (Agent) object; if (!agent.isValid()) { continue; } switch (agent.getAgentType()) { case 0: // 全局代理 actorIds.add(agent.getAssignFrom()); break; default: break; } } } } if (!actorIds.isEmpty()) { actorIds.add(actorId); query.setActorIds(actorIds); } else { query.setActorId(actorId); } treeList = sysTreeMapper.getTreeListByUsers(query); } else { treeList = sysTreeMapper.getTreeList(query); } List<TreeModel> treeModels = new java.util.ArrayList<TreeModel>(); for (SysTree tree : treeList) { if (StringUtils.isNotEmpty(tree.getUrl())) { if (StringUtils.startsWith(tree.getUrl(), "/")) { if (StringUtils.isNotEmpty(SystemConfig.getServiceUrl())) { String link = SystemConfig.getServiceUrl() + tree.getUrl(); tree.setUrl(link); } else { String link = ApplicationContext.getContextPath() + tree.getUrl(); tree.setUrl(link); } } } treeModels.add(tree); } TreeHelper treeHelper = new TreeHelper(); array = treeHelper.getTreeJSONArray(treeModels); // logger.debug(array.toString('\n')); } return array; }