Example #1
0
 private void initWeixinUser() {
   try {
     JSONObject jsonObject = WeixinUtil.getDepartUsersDetail("1", 1, WeixinDepartStatus.获取全部成员);
     if (null != jsonObject) {
       JSONArray jsonUserList = jsonObject.getJSONArray("userlist");
       String errmsg = jsonObject.getString("errmsg");
       String errcode = jsonObject.getString("errcode");
       if ("0".equals(errcode)) {
         if (null != jsonUserList) {
           List<WeixinUser> weixinUserList = new ArrayList<WeixinUser>(jsonUserList.size());
           for (int i = 0, size = jsonUserList.size(); i < size; i++) {
             weixinUserList.add(
                 JSON.toJavaObject(jsonUserList.getJSONObject(i), WeixinUser.class));
           }
           SystemCacheUtil.getInstance().getDefaultCache().add("AllUser", weixinUserList);
           LOGGER.info("初始化所有用户信息成功!" + JSON.toJSONString(weixinUserList));
         }
       } else {
         LOGGER.error("初始化所有用户信息失败,原因:" + errmsg);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     LOGGER.error("初始化所有用户信息失败!", e);
   }
 }
Example #2
0
  private void initWeixinDept() {
    try {
      JSONObject jsonObject = WeixinUtil.getDepartments(null);
      if (null != jsonObject) {
        JSONArray jsonDeptList = jsonObject.getJSONArray("department");
        String errmsg = jsonObject.getString("errmsg");
        String errcode = jsonObject.getString("errcode");
        if ("0".equals(errcode)) {
          if (null != jsonDeptList) {
            Department dept = null;
            Department root = null;
            Department temp = null;
            List<Department> deptList = new ArrayList<Department>();

            for (int i = 0, size = jsonDeptList.size(); i < size; i++) {
              deptList.add(JSON.toJavaObject(jsonDeptList.getJSONObject(i), Department.class));
            }

            // 组装结构
            for (int i = 0, size = deptList.size(); i < size; i++) {
              dept = deptList.get(i);
              if ("0".equals(dept.getParentid())) {
                root = dept;
              }
              for (int j = i + 1; j < size; j++) {
                temp = deptList.get(j);
                if (dept.getId().equals(temp.getParentid())) {
                  dept.addChild(temp);
                }
              }
            }

            SystemCacheUtil.getInstance().getDefaultCache().add("AllDept", root);
            LOGGER.info("初始化所有部门信息成功!" + JSON.toJSON(root));
          }
        } else {
          LOGGER.error("初始化所有部门信息失败,原因:" + errmsg);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      LOGGER.error("初始化所有部门信息失败!", e);
    }
  }