Example #1
0
  /** 功能描述:部门树生成JSON串 逻辑描述:默认绑定一颗根节点,更节点的父节点为0 */
  public void editResourceJson() {
    try {
      JSONObject jsonObject = null;
      List<Department> departments =
          departmentManageImpl.executeSql(
              "select * from department where  ISNULL(parentId) ", new Object[] {});
      if (null != departments && departments.size() > 0) {
        jsonObject = new JSONObject();
        jsonObject = makeJSONObject(departments.get(0));
      }
      JSONArray array = new JSONArray();
      if (jsonObject != null) {
        array.put(jsonObject);
      }

      JSONObject jsonObject2 = new JSONObject();
      List<Enterprise> enterprises = enterpriseManageImpl.getAll();
      if (null != enterprises && enterprises.size() == 1) {
        Enterprise enterprise = enterprises.get(0);
        jsonObject2.put("icon", "/widgets/ztree/css/zTreeStyle/img/diy/1_open.png"); // 根节点
        jsonObject2.put("root", "root");
        jsonObject2.put("id", enterprise.getDbid());
        jsonObject2.put("name", enterprise.getName());
        jsonObject2.put("open", true);
        jsonObject2.put("children", array);
        renderJson(jsonObject2.toString());
        System.err.println(jsonObject2.toString());
      } else {
        renderJson("1");
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    return;
  }