|
|
|
@ -15,6 +15,7 @@ import com.dingtalk.api.response.*;
|
|
|
|
|
import com.dsideal.FengHuang.Util.CommonUtil;
|
|
|
|
|
import com.jfinal.kit.Kv;
|
|
|
|
|
import com.jfinal.kit.StrKit;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Db;
|
|
|
|
|
import com.jfinal.plugin.activerecord.Record;
|
|
|
|
|
import com.taobao.api.ApiException;
|
|
|
|
|
|
|
|
|
@ -110,17 +111,10 @@ public class OrgPerson {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void delAllDept(String access_token, String orgName) throws ApiException {
|
|
|
|
|
Record rOrg = Model.getOrgByOrgName(orgName);
|
|
|
|
|
int bureauId = rOrg.getInt("org_id");
|
|
|
|
|
//获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下
|
|
|
|
|
long DT_BureauId = Model.getDtDeptId(bureauId);
|
|
|
|
|
delDept(access_token, DT_BureauId);
|
|
|
|
|
|
|
|
|
|
deptList.clear();
|
|
|
|
|
getDeptList(access_token, DT_BureauId);
|
|
|
|
|
public static void delAllDept(String access_token) throws ApiException {
|
|
|
|
|
for (int i = 0; i < deptList.size(); i++) {
|
|
|
|
|
delDept(access_token, deptList.get(i).getLong("dept_id"));
|
|
|
|
|
CommonUtil.Print("成功删除部门:"+deptList.get(i).getStr("name"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -139,23 +133,23 @@ public class OrgPerson {
|
|
|
|
|
return jo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void syncOrg(String accessToken, String orgName) throws ApiException {
|
|
|
|
|
Record rOrg = Model.getOrgByOrgName(orgName);
|
|
|
|
|
int bureauId = rOrg.getInt("org_id");
|
|
|
|
|
int sortId = rOrg.getInt("sort_id");
|
|
|
|
|
public static void syncOrg(String accessToken, Record rOrg) throws ApiException {
|
|
|
|
|
String orgName = rOrg.getStr("org_name");
|
|
|
|
|
int bureau_id = rOrg.getInt("org_id");
|
|
|
|
|
int sort_id = rOrg.getInt("sort_id");
|
|
|
|
|
//获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下
|
|
|
|
|
long DT_BureauId = Model.getDtDeptId(bureauId);
|
|
|
|
|
long dingtalk_dept_id = Model.getDtDeptId(bureau_id);
|
|
|
|
|
|
|
|
|
|
JSONObject jRes = getDeptInfo(accessToken, DT_BureauId);
|
|
|
|
|
JSONObject jRes = getDeptInfo(accessToken, dingtalk_dept_id);
|
|
|
|
|
if (jRes.getLong("errcode") > 0) {
|
|
|
|
|
DT_BureauId = createDept(accessToken, orgName, 1, sortId, true);
|
|
|
|
|
Model.writeDtDeptId(bureauId, String.valueOf(DT_BureauId));//记得要回写
|
|
|
|
|
dingtalk_dept_id = createDept(accessToken, orgName, 1, sort_id, true);
|
|
|
|
|
Model.writeDtDeptId(bureau_id, String.valueOf(dingtalk_dept_id));//记得要回写
|
|
|
|
|
CommonUtil.Print("单位名称:" + orgName + "不存在!已创建!");
|
|
|
|
|
} else {
|
|
|
|
|
CommonUtil.Print("单位名称:" + orgName + "已存在,保留!");
|
|
|
|
|
//获取下属部门的列表
|
|
|
|
|
getDeptList(accessToken, dingtalk_dept_id);
|
|
|
|
|
}
|
|
|
|
|
//获取下属部门的列表
|
|
|
|
|
getDeptList(accessToken, DT_BureauId);
|
|
|
|
|
|
|
|
|
|
// 云平台->集合A,钉钉->集合B
|
|
|
|
|
// (1) x在A中存在,在B中也存在,内容也一致:不处理
|
|
|
|
@ -177,12 +171,12 @@ public class OrgPerson {
|
|
|
|
|
mapOfA.put(deptId, jo);
|
|
|
|
|
}
|
|
|
|
|
//B:云平台
|
|
|
|
|
List<Record> list = Model.getOrgList(bureauId);
|
|
|
|
|
List<Record> list = Model.getOrgList(bureau_id);
|
|
|
|
|
for (int i = 0; i < list.size(); i++) {
|
|
|
|
|
if (list.get(i).get("dingtalk_dept_id") != null) {
|
|
|
|
|
long deptId = list.get(i).getLong("dingtalk_dept_id");
|
|
|
|
|
String org_name = list.get(i).getStr("org_name");
|
|
|
|
|
sortId = list.get(i).getInt("sort_id");
|
|
|
|
|
sort_id = list.get(i).getInt("sort_id");
|
|
|
|
|
int org_id = list.get(i).getInt("org_id");
|
|
|
|
|
int parentId = list.get(i).getInt("parent_id");
|
|
|
|
|
keysOfB.add(deptId);
|
|
|
|
@ -190,7 +184,7 @@ public class OrgPerson {
|
|
|
|
|
JSONObject jo = new JSONObject();
|
|
|
|
|
jo.put("org_id", org_id);
|
|
|
|
|
jo.put("org_name", org_name);
|
|
|
|
|
jo.put("sort_id", sortId);
|
|
|
|
|
jo.put("sort_id", sort_id);
|
|
|
|
|
jo.put("parent_id", parentId);
|
|
|
|
|
mapOfB.put(deptId, jo);
|
|
|
|
|
}
|
|
|
|
@ -233,6 +227,8 @@ public class OrgPerson {
|
|
|
|
|
CommonUtil.Print("成功创建部门:" + org_name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//重新获取下属部门的列表,使得后续的代码不再获取部门列表
|
|
|
|
|
getDeptList(accessToken, dingtalk_dept_id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -316,20 +312,15 @@ public class OrgPerson {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void delBureauPerson(String accessToken, String orgName) throws ApiException {
|
|
|
|
|
Record record = Model.getOrgByOrgName(orgName);
|
|
|
|
|
int dingtalk_dept_id = record.getInt("dingtalk_dept_id");
|
|
|
|
|
|
|
|
|
|
public static void delBureauPerson(String accessToken, Record rOrg) throws ApiException {
|
|
|
|
|
int dingtalk_dept_id = rOrg.getInt("dingtalk_dept_id");
|
|
|
|
|
getBureauPerson(accessToken, dingtalk_dept_id);
|
|
|
|
|
for (int i = 0; i < personList.size(); i++) {
|
|
|
|
|
String userid = personList.get(i).getStr("userid");
|
|
|
|
@ -343,13 +334,11 @@ public class OrgPerson {
|
|
|
|
|
* 功能:同步人员信息
|
|
|
|
|
*
|
|
|
|
|
* @param accessToken
|
|
|
|
|
* @param orgName
|
|
|
|
|
* @param rOrg
|
|
|
|
|
* @throws ApiException
|
|
|
|
|
*/
|
|
|
|
|
public static void syncPerson(String accessToken, String orgName) throws ApiException {
|
|
|
|
|
Record rOrg = Model.getOrgByOrgName(orgName);
|
|
|
|
|
public static void syncPerson(String accessToken, Record rOrg) throws ApiException {
|
|
|
|
|
int bureauId = rOrg.getInt("org_id");
|
|
|
|
|
|
|
|
|
|
//获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下
|
|
|
|
|
long DT_BureauId = Model.getDtDeptId(bureauId);
|
|
|
|
|
getBureauPerson(accessToken, DT_BureauId);
|
|
|
|
|