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;
  }
  protected void loadChildrenTreeModels(List<TreeModel> treeModels, long parentId, SysUser user) {
    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;
        }
        TreeModel treeModel = new BaseTree();
        treeModel.setCode(bean.getCode());
        treeModel.setId(bean.getId());
        treeModel.setParentId(parentId);
        treeModel.setName(bean.getName());
        treeModel.setLocked(bean.getLocked());
        treeModel.setDescription(bean.getDesc());
        treeModel.setUrl(bean.getUrl());
        treeModel.setSortNo(bean.getSort());

        List<SysApplication> childrenNodes = null;
        if (user.isSystemAdmin()) {
          childrenNodes = getApplicationList((int) bean.getId());
        } else {
          childrenNodes = getAccessAppList(bean.getId(), user);
        }
        if (childrenNodes != null && childrenNodes.size() > 0) { // 有子菜单
          this.loadChildrenTreeModels(treeModels, bean.getId(), user);
        }
        treeModels.add(treeModel);
      }
    }
  }
Beispiel #3
0
  public static ObjectNode toObjectNode(SysUser user) {
    ObjectNode jsonObject = new ObjectMapper().createObjectNode();

    jsonObject.put("actorId", user.getAccount());
    jsonObject.put("actorId_enc", RequestUtils.encodeString(user.getAccount()));
    jsonObject.put("userId", user.getAccount());
    jsonObject.put("userId_enc", RequestUtils.encodeString(user.getAccount()));

    jsonObject.put("name", user.getName());
    jsonObject.put("locked", user.getStatus());
    jsonObject.put("status", user.getStatus());

    if (user.getDepartment() != null) {
      jsonObject.put("deptId", user.getDepartment().getId());
      jsonObject.put("deptName", user.getDepartment().getName());
    } else {
      jsonObject.put("deptId", user.getDeptId());
    }

    jsonObject.put("accountType", user.getAccountType());
    jsonObject.put("userType", user.getUserType());
    jsonObject.put("dumpFlag", user.getDumpFlag());
    jsonObject.put("gender", user.getGender());
    jsonObject.put("evection", user.getEvection());
    jsonObject.put("superiorIds", user.getSuperiorIds());

    jsonObject.put("fax", user.getFax());
    jsonObject.put("telephone", user.getTelephone());
    jsonObject.put("headship", user.getHeadship());
    jsonObject.put("adminFlag", user.getAdminFlag());

    if (user.getEmail() != null) {
      jsonObject.put("mail", user.getEmail());
      jsonObject.put("email", user.getEmail());
    }
    if (user.getMobile() != null) {
      jsonObject.put("mobile", user.getMobile());
    }
    if (user.getLastLoginTime() != null) {
      jsonObject.put("lastLoginDate", DateUtils.getDateTime(user.getLastLoginDate()));
      jsonObject.put("lastLoginTime", DateUtils.getDateTime(user.getLastLoginDate()));
    }
    if (user.getLastLoginIP() != null) {
      jsonObject.put("loginIP", user.getLastLoginIP());
    }

    if (user.getCreateBy() != null) {
      jsonObject.put("createBy", user.getCreateBy());
    }
    if (user.getUpdateBy() != null) {
      jsonObject.put("updateBy", user.getUpdateBy());
    }
    if (user.getUpdateDate() != null) {
      jsonObject.put("updateDate", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_date", DateUtils.getDate(user.getUpdateDate()));
      jsonObject.put("updateDate_datetime", DateUtils.getDateTime(user.getUpdateDate()));
    }

    if (user.getUserRoles() != null && !user.getUserRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysUserRole sysUserRole : user.getUserRoles()) {
        array.add(sysUserRole.toObjectNode());
      }
      jsonObject.set("userRoles", array);
    }

    if (user.getRoles() != null && !user.getRoles().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysRole sysRole : user.getRoles()) {
        array.add(sysRole.toObjectNode());
      }
      jsonObject.set("roles", array);
    }

    if (user.getFunctions() != null && !user.getFunctions().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysFunction sysFunction : user.getFunctions()) {
        array.add(sysFunction.toObjectNode());
      }
      // jsonObject.set("functions", array);
    }

    if (user.getApps() != null && !user.getApps().isEmpty()) {
      ArrayNode array = new ObjectMapper().createArrayNode();
      for (SysApplication app : user.getApps()) {
        array.add(app.toObjectNode());
      }
      // jsonObject.set("apps", array);
    }

    return jsonObject;
  }