main
黄海 2 years ago
parent 8caa4494fd
commit fe4c2cb8d9

@ -62,16 +62,14 @@ public class TestDingTalk {
//同步钉钉与云平台中部门信息 //同步钉钉与云平台中部门信息
String orgName = "长春市东光学校"; String orgName = "长春市东光学校";
//同步组织机构 //同步组织机构
//DingTalkUtil.syncOrg(accessToken, orgName); //DingTalkUtil.syncOrg(accessToken, orgName);
//同步人员
//DingTalkUtil.syncPerson(accessToken,orgName);
//删除单位下所有人员(开发测试时使用) //删除单位下所有人员(开发测试时使用)
DingTalkUtil.delBureauPerson(accessToken,orgName); //DingTalkUtil.delBureauPerson(accessToken,orgName);
//同步人员
DingTalkUtil.syncPerson(accessToken,orgName);
//CommonUtil.Print(DingTalkUtil.getPerson(accessToken, "003")); //CommonUtil.Print(DingTalkUtil.getPerson(accessToken, "003"));
//CommonUtil.Print(DingTalkUtil.getPersonToken(appKey, appSecret)); //CommonUtil.Print(DingTalkUtil.getPersonToken(appKey, appSecret));

@ -271,11 +271,10 @@ public class DingTalkUtil {
Record rOrg = getOrgByOrgName(orgName); Record rOrg = getOrgByOrgName(orgName);
int bureauId = rOrg.getInt("org_id"); int bureauId = rOrg.getInt("org_id");
int sortId = rOrg.getInt("sort_id"); int sortId = rOrg.getInt("sort_id");
//获取部门信息
deptList.clear();
//获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下 //获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下
long DT_BureauId = getDtDeptId(bureauId); long DT_BureauId = getDtDeptId(bureauId);
//获取部门信息
deptList.clear();
JSONObject jRes = getDeptInfo(accessToken, DT_BureauId); JSONObject jRes = getDeptInfo(accessToken, DT_BureauId);
if (jRes.getLong("errcode") > 0) { if (jRes.getLong("errcode") > 0) {
DT_BureauId = createDept(accessToken, orgName, 1, sortId); DT_BureauId = createDept(accessToken, orgName, 1, sortId);
@ -404,12 +403,11 @@ public class DingTalkUtil {
//System.out.println(rsp.getBody()); //System.out.println(rsp.getBody());
} }
public static void updatePerson(String access_token, String person_id, String person_name, String tel) throws ApiException { public static void updatePerson(String access_token, String person_id, String person_name) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/update"); DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/update");
OapiV2UserUpdateRequest req = new OapiV2UserUpdateRequest(); OapiV2UserUpdateRequest req = new OapiV2UserUpdateRequest();
req.setUserid(person_id); req.setUserid(person_id);
req.setName(person_name); req.setName(person_name);
req.setMobile(tel);
OapiV2UserUpdateResponse rsp = client.execute(req, access_token); OapiV2UserUpdateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody()); System.out.println(rsp.getBody());
} }
@ -482,6 +480,10 @@ public class DingTalkUtil {
Record rOrg = getOrgByOrgName(orgName); Record rOrg = getOrgByOrgName(orgName);
int bureauId = rOrg.getInt("org_id"); int bureauId = rOrg.getInt("org_id");
//获取数据库中记录的钉钉端的dept_id,但不一定准确存在,需要继续判断一下
long DT_BureauId = getDtDeptId(bureauId);
getBureauPerson(accessToken, DT_BureauId);
Set<String> keysOfA = new HashSet<>(); Set<String> keysOfA = new HashSet<>();
Map<String, JSONObject> mapOfA = new HashMap<>(); Map<String, JSONObject> mapOfA = new HashMap<>();
Set<String> keysOfB = new HashSet<>(); Set<String> keysOfB = new HashSet<>();
@ -509,6 +511,7 @@ public class DingTalkUtil {
String tel = r.getStr("tel"); String tel = r.getStr("tel");
if (StrKit.isBlank(tel) || !PhoneUtil.isMobile(tel)) { if (StrKit.isBlank(tel) || !PhoneUtil.isMobile(tel)) {
tel = ChineseMobileNumberGenerator.getInstance().generate();//生成一个随机临时测试用的手机号 tel = ChineseMobileNumberGenerator.getInstance().generate();//生成一个随机临时测试用的手机号
tel = "14" + tel.substring(2);//以14段开头避开已存在的号码
} }
keysOfB.add(String.valueOf(person_id)); keysOfB.add(String.valueOf(person_id));
JSONObject jo = new JSONObject(); JSONObject jo = new JSONObject();
@ -527,8 +530,14 @@ public class DingTalkUtil {
delPerson(accessToken, key); delPerson(accessToken, key);
} else { } else {
// key在A和B中都存在 // key在A和B中都存在
updatePerson(accessToken, key, mapOfB.get(key).getString("person_name"), mapOfB.get(key).getString("tel")); String aName = mapOfA.get(key).getString("person_name");
CommonUtil.Print("暴力修改钉钉与云平台间部门人员姓名、手机号!,person_name=" + mapOfB.get(key).getString("person_name")); String bName = mapOfB.get(key).getString("person_name");
if (!aName.equals(bName)) {
updatePerson(accessToken, key, mapOfB.get(key).getString("person_name"));
CommonUtil.Print("发现钉钉与云平台间部门人员姓名不一致,将修改,person_name=" + mapOfB.get(key).getString("person_name"));
} else {
CommonUtil.Print("钉钉与云平台间部门人员姓名一致,无需修改,person_name=" + mapOfB.get(key).getString("person_name"));
}
} }
} }

Loading…
Cancel
Save