Ejemplo n.º 1
0
  public String all() {
    if (!isUserLogined()) {
      plsLogin();
      return JSON_ERROR;
    }
    if (id > 0) {
      Corporation c = organizationMgr.getCorporation(id);
      if (c.getAccessType() == Corporation.PUBLIC_ACCESS) {
        id = 0; // public access
      }
    }
    if (id > 0 && !organizationMgr.canUserManageCorp(getCurUserId(), id)) {
      setErrMsg(ACCESS_DENY);
      return JSON_ERROR;
    }
    Gson gson = new Gson();

    List<User> users =
        id > 0 ? super.getAccountMgr().getUserList(id) : super.getAccountMgr().getUserList();
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    for (User user : users) {
      Map<String, Object> o = new HashMap<String, Object>();
      o.put("id", user.getId());
      o.put("name", user.getName());
      o.put("role", user.getRoleListStr());
      o.put("account", user.getAccount());
      o.put("realName", user.getRealname());
      o.put("empId", user.getEmpId());
      o.put("namePinyin", Pinyin4jUtil.calculatePinyinArrStr(user.getName()));
      o.put("realNamePinyin", Pinyin4jUtil.calculatePinyinArrStr(user.getRealname()));
      result.add(o);
    }
    setJson("{\"users\":" + gson.toJson(result) + "}");
    return SUCCESS;
  }