示例#1
0
  public JSONArray getUserMenu2(long parent, String userId) {
    JSONArray array = new JSONArray();
    SysUser user = authorizeService.login(userId);
    if (user != null) {
      List<SysApplication> list = null;
      if (user.isSystemAdmin()) {
        logger.debug("#admin user="******"#user="******"#app list=" + list);
      }
      if (list != null && list.size() > 0) {
        Iterator<SysApplication> iter = list.iterator();
        while (iter.hasNext()) {
          SysApplication bean = (SysApplication) iter.next();
          if (bean.getLocked() == 1) {
            continue;
          }
          JSONObject item = new JSONObject();
          item.put("id", String.valueOf(bean.getId()));
          item.put("nodeId", bean.getNodeId());
          item.put("showMenu", bean.getShowMenu());
          item.put("sort", bean.getSort());
          item.put("description", bean.getDesc());
          item.put("name", bean.getName());
          item.put("icon", "icon-sys");
          item.put("url", bean.getUrl());

          List<SysApplication> childrenNodes = null;
          if (user.isSystemAdmin()) {
            childrenNodes = getApplicationList((int) bean.getId());
          } else {
            childrenNodes = getAccessAppList(bean.getId(), user);
          }
          if (childrenNodes != null && childrenNodes.size() > 0) { // 有子菜单
            JSONArray children = this.getUserMenu(bean.getId(), user);
            item.put("children", children);
          }

          array.put(item);
        }
      }
    }
    return array;
  }
示例#2
0
  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;
  }