|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.dsideal.FengHuang.Util;
|
|
|
|
|
|
|
|
|
|
import cn.binarywang.tools.generator.ChineseMobileNumberGenerator;
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.aliyun.dingtalkoauth2_1_0.models.*;
|
|
|
|
@ -244,7 +245,6 @@ public class DingTalkUtil {
|
|
|
|
|
long childDeptId = j.getLongValue("dept_id");
|
|
|
|
|
kv.set("dept_id", childDeptId);
|
|
|
|
|
kv.set("name", j.getString("name"));
|
|
|
|
|
//kv.set("parent_id", j.getLongValue("parent_id"));
|
|
|
|
|
deptList.add(kv);
|
|
|
|
|
getDeptList(access_token, childDeptId);//递归
|
|
|
|
|
}
|
|
|
|
@ -401,7 +401,72 @@ public class DingTalkUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**-----------------------------------------------------下面是数据库操作---------------------------------------------*/
|
|
|
|
|
public static List<Kv> personList = new ArrayList();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void getDeptPerson(String access_token, long dept_id) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listsimple");
|
|
|
|
|
long next_cursor = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
OapiUserListsimpleRequest req = new OapiUserListsimpleRequest();
|
|
|
|
|
req.setDeptId(dept_id);
|
|
|
|
|
req.setCursor(next_cursor);
|
|
|
|
|
req.setSize(10L);
|
|
|
|
|
req.setOrderField("modify_desc");
|
|
|
|
|
req.setContainAccessLimit(false);
|
|
|
|
|
req.setLanguage("zh_CN");
|
|
|
|
|
OapiUserListsimpleResponse rsp = client.execute(req, access_token);
|
|
|
|
|
JSONObject jo = JSONObject.parseObject(rsp.getBody());
|
|
|
|
|
|
|
|
|
|
JSONArray ja = jo.getJSONObject("result").getJSONArray("list");
|
|
|
|
|
if (ja == null) return;
|
|
|
|
|
for (int i = 0; i < ja.size(); i++) {
|
|
|
|
|
JSONObject j = ja.getJSONObject(i);
|
|
|
|
|
Kv kv = Kv.create();
|
|
|
|
|
String userid = j.getString("userid");
|
|
|
|
|
String name = j.getString("name");
|
|
|
|
|
kv.set("userid", userid);
|
|
|
|
|
kv.set("name", name);
|
|
|
|
|
personList.add(kv);
|
|
|
|
|
}
|
|
|
|
|
if (jo.getJSONObject("result").getBoolean("has_more"))
|
|
|
|
|
next_cursor = jo.getJSONObject("result").getLong("next_cursor");
|
|
|
|
|
else break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void getBureauPerson(String access_token, long dept_id) throws ApiException {
|
|
|
|
|
//获取有哪些部门
|
|
|
|
|
deptList.clear();
|
|
|
|
|
personList.clear();
|
|
|
|
|
getDeptPerson(access_token, dept_id);
|
|
|
|
|
getDeptList(access_token, dept_id);
|
|
|
|
|
for (int i = 0; i < deptList.size(); i++) {
|
|
|
|
|
getDeptPerson(access_token, deptList.get(i).getInt("dept_id"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//TODO
|
|
|
|
|
public static void syncPerson(String accessToken, String orgName) throws ApiException {
|
|
|
|
|
Record rOrg = getOrgByOrgName(orgName);
|
|
|
|
|
int bureauId = rOrg.getInt("org_id");
|
|
|
|
|
int sortId = rOrg.getInt("sort_id");
|
|
|
|
|
|
|
|
|
|
List<Record> list = DingTalkUtil.getDeptPerson(bureauId);
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
Record r = list.get(i);
|
|
|
|
|
long deptId = r.getLong("dingtalk_dept_id");
|
|
|
|
|
int person_id = r.getInt("person_id");
|
|
|
|
|
String person_name = r.getStr("person_name");
|
|
|
|
|
String tel = ChineseMobileNumberGenerator.getInstance().generate();
|
|
|
|
|
DingTalkUtil.createPerson(accessToken, String.valueOf(deptId), String.valueOf(person_id), person_name, tel, "教师");
|
|
|
|
|
CommonUtil.Print("成功加入人员:" + person_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* -----------------------------------------------------下面是数据库操作---------------------------------------------
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public static List<Record> getOrgList(int orgId) {
|
|
|
|
|
// 学校及学校下的部门
|
|
|
|
@ -411,7 +476,7 @@ public class DingTalkUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Record> getPersonList(int bureau_id) {
|
|
|
|
|
public static List<Record> getDeptPerson(int bureau_id) {
|
|
|
|
|
String sql = "select t1.person_id,t1.person_name,t2.dingtalk_dept_id from t_base_person as t1 " +
|
|
|
|
|
"inner join t_base_organization as t2 on t1.org_id=t2.org_id " +
|
|
|
|
|
" where t1.bureau_id=? and t1.b_use=1";
|
|
|
|
@ -431,7 +496,7 @@ public class DingTalkUtil {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Record getOrgByOrgName(String org_name) {
|
|
|
|
|
String sql = "select org_id,org_name,sort_id from t_base_organization where org_name = ?";
|
|
|
|
|
String sql = "select org_id,org_name,sort_id,dingtalk_dept_id from t_base_organization where org_name = ?";
|
|
|
|
|
return Db.findFirst(sql, org_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|