|
@@ -2707,75 +2707,77 @@ public class WeiXinCorpController {
|
|
for (int p=0;p<remoteDeptUserList.size(); p++) {
|
|
for (int p=0;p<remoteDeptUserList.size(); p++) {
|
|
corpUserIds.add(remoteDeptUserList.getJSONObject(p).getString("userid"));
|
|
corpUserIds.add(remoteDeptUserList.getJSONObject(p).getString("userid"));
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, corpUserIds);
|
|
|
|
- for (int w=0;w<array.size(); w++) {
|
|
|
|
- JSONObject jsonObject = array.getJSONObject(w);
|
|
|
|
- String userid = jsonObject.getString("userid");
|
|
|
|
- String openUserid = jsonObject.getString("open_userid");
|
|
|
|
- //替换userid
|
|
|
|
- for (int m=0;m<remoteDeptUserList.size(); m++) {
|
|
|
|
- JSONObject remoteUser = remoteDeptUserList.getJSONObject(m);
|
|
|
|
- if (remoteUser.getString("userid").equals(userid)) {
|
|
|
|
- remoteUser.put("openUserid", openUserid);
|
|
|
|
- break;
|
|
|
|
|
|
+ if (corpUserIds.size() > 0) {
|
|
|
|
+ try {
|
|
|
|
+ JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, corpUserIds);
|
|
|
|
+ for (int w=0;w<array.size(); w++) {
|
|
|
|
+ JSONObject jsonObject = array.getJSONObject(w);
|
|
|
|
+ String userid = jsonObject.getString("userid");
|
|
|
|
+ String openUserid = jsonObject.getString("open_userid");
|
|
|
|
+ //替换userid
|
|
|
|
+ for (int m=0;m<remoteDeptUserList.size(); m++) {
|
|
|
|
+ JSONObject remoteUser = remoteDeptUserList.getJSONObject(m);
|
|
|
|
+ if (remoteUser.getString("userid").equals(userid)) {
|
|
|
|
+ remoteUser.put("openUserid", openUserid);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ //msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
+ msg.setError(MessageUtils.message("wx.synError",exception.getMessage()));
|
|
|
|
+ return msg;
|
|
}
|
|
}
|
|
- } catch (Exception exception) {
|
|
|
|
- exception.printStackTrace();
|
|
|
|
- //msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
- msg.setError(MessageUtils.message("wx.synError",exception.getMessage()));
|
|
|
|
- return msg;
|
|
|
|
- }
|
|
|
|
- for (int m=0;m<userList.size(); m++) {
|
|
|
|
- JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
|
- String openUserid = userJson.getString("open_userid");
|
|
|
|
- //跳过已经获取过的
|
|
|
|
- if (allCorpWxUserList.stream().anyMatch(item->item.getCorpwxUserid().equals(openUserid))) {
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
- JSONArray userDeptArray = userJson.getJSONArray("department");
|
|
|
|
- //取最末级的,也就是最大的deptId
|
|
|
|
- int maxDeptId = 1;
|
|
|
|
- for (int t=0;t<userDeptArray.size(); t++) {
|
|
|
|
- int curId = userDeptArray.getInteger(t);
|
|
|
|
- if (curId > maxDeptId) maxDeptId = curId;
|
|
|
|
- }
|
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setDepartmentId(departmentId)
|
|
|
|
- .setPhone(userJson.getString("mobile"))
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setCorpwxUserid(openUserid)
|
|
|
|
- .setCorpwxDeptid(maxDeptId)
|
|
|
|
- .setColor(ColorUtil.randomColor());
|
|
|
|
- //获取姓名
|
|
|
|
- if (remoteDeptUserList != null) {
|
|
|
|
- for (int t=0;t<remoteDeptUserList.size(); t++) {
|
|
|
|
- JSONObject remoteUserJson = remoteDeptUserList.getJSONObject(t);
|
|
|
|
- if (remoteUserJson.getString("openUserid").equals(curUserid)) {
|
|
|
|
- //匹配到了。设置姓名
|
|
|
|
- System.out.println("远程的用户匹配到了:"+remoteUserJson.getString("name"));
|
|
|
|
- user.setName(remoteUserJson.getString("name"));
|
|
|
|
- user.setJobNumber(remoteUserJson.getString("userid"));
|
|
|
|
- user.setPhone(remoteUserJson.getString("mobile"));
|
|
|
|
- user.setCorpwxRealUserid(remoteUserJson.getString("userid"));
|
|
|
|
- break;
|
|
|
|
|
|
+
|
|
|
|
+ for (int m=0;m<userList.size(); m++) {
|
|
|
|
+ JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
|
+ String openUserid = userJson.getString("open_userid");
|
|
|
|
+ //跳过已经获取过的
|
|
|
|
+ if (allCorpWxUserList.stream().anyMatch(item->item.getCorpwxUserid().equals(openUserid))) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+ JSONArray userDeptArray = userJson.getJSONArray("department");
|
|
|
|
+ //取最末级的,也就是最大的deptId
|
|
|
|
+ int maxDeptId = 1;
|
|
|
|
+ for (int t=0;t<userDeptArray.size(); t++) {
|
|
|
|
+ int curId = userDeptArray.getInteger(t);
|
|
|
|
+ if (curId > maxDeptId) maxDeptId = curId;
|
|
|
|
+ }
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setDepartmentId(departmentId)
|
|
|
|
+ .setPhone(userJson.getString("mobile"))
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setCorpwxUserid(openUserid)
|
|
|
|
+ .setCorpwxDeptid(maxDeptId)
|
|
|
|
+ .setColor(ColorUtil.randomColor());
|
|
|
|
+ //获取姓名
|
|
|
|
+ if (remoteDeptUserList != null) {
|
|
|
|
+ for (int t=0;t<remoteDeptUserList.size(); t++) {
|
|
|
|
+ JSONObject remoteUserJson = remoteDeptUserList.getJSONObject(t);
|
|
|
|
+ if (remoteUserJson.getString("openUserid").equals(curUserid)) {
|
|
|
|
+ //匹配到了。设置姓名
|
|
|
|
+ System.out.println("远程的用户匹配到了:"+remoteUserJson.getString("name"));
|
|
|
|
+ user.setName(remoteUserJson.getString("name"));
|
|
|
|
+ user.setJobNumber(remoteUserJson.getString("userid"));
|
|
|
|
+ user.setPhone(remoteUserJson.getString("mobile"));
|
|
|
|
+ user.setCorpwxRealUserid(remoteUserJson.getString("userid"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ allCorpWxUserList.add(user);
|
|
}
|
|
}
|
|
- allCorpWxUserList.add(user);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|