|
@@ -1415,13 +1415,14 @@ public class WeiXinCorpController {
|
|
|
//默认普通员工的角色
|
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
|
int companyRootDeptId = 1;
|
|
|
- JSONArray allCorpWxUserJsonArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
- System.out.println("获取到公司下的员工数量="+allCorpWxUserJsonArray.size());
|
|
|
+ JSONArray usersUnderRootArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
+ System.out.println("获取到公司下的员工数量="+usersUnderRootArray.size());
|
|
|
SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
List<User> allCorpWxUserList = new ArrayList<>();
|
|
|
- for (int m=0;m<allCorpWxUserJsonArray.size(); m++) {
|
|
|
- JSONObject userJson = allCorpWxUserJsonArray.getJSONObject(m);
|
|
|
+ for (int m=0;m<usersUnderRootArray.size(); m++) {
|
|
|
+ JSONObject userJson = usersUnderRootArray.getJSONObject(m);
|
|
|
+ System.out.println(userJson.toString());
|
|
|
String curUserid = userJson.getString("userid");
|
|
|
//跳过非激活状态的员工
|
|
|
if (userJson.getInteger("status") != 1) continue;
|
|
@@ -1444,7 +1445,6 @@ public class WeiXinCorpController {
|
|
|
.setColor(ColorUtil.randomColor())
|
|
|
.setJobNumber(curUserid)
|
|
|
.setCorpwxDeptid(maxDeptId);
|
|
|
- System.out.println("姓名=="+user.getName());
|
|
|
allCorpWxUserList.add(user);
|
|
|
}
|
|
|
|
|
@@ -1474,7 +1474,31 @@ public class WeiXinCorpController {
|
|
|
//有父部门需要更新
|
|
|
curDept.setCorpwxDeptpid(parentId);
|
|
|
departmentMapper.updateById(curDept);
|
|
|
-
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //获取部门下的人员
|
|
|
+ JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
|
+ for (int m=0;m<userList.size(); m++) {
|
|
|
+ JSONObject userJson = userList.getJSONObject(m);
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
+ System.out.println("人员信息:"+userJson.toString());
|
|
|
+ //不存在的人员, 进行插入
|
|
|
+ User user = new User();
|
|
|
+ Optional<User> first = allCorpWxUserList.stream().filter(all -> all.getCorpwxUserid().equals(curUserid)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ user = first.get();
|
|
|
+ user.setCorpwxDeptid(deptId);
|
|
|
+ } else {
|
|
|
+ //在当前部门下的员工
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
+ .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
+ .setCompanyId(companyId)
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
+ .setJobNumber(curUserid);
|
|
|
+ allCorpWxUserList.add(user);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -1493,13 +1517,14 @@ public class WeiXinCorpController {
|
|
|
newItem.setDepartmentCascade(convertDepartmentIdToCascade(deptId, allDeptList));
|
|
|
}
|
|
|
});
|
|
|
- userService.saveBatch(newUserList);
|
|
|
+ if (newUserList.size() > 0) {
|
|
|
+ userService.saveBatch(newUserList);
|
|
|
+ }
|
|
|
List<User> updateUserList = allCorpWxUserList.stream().filter(newItem->existingUsers.stream().anyMatch(existingItem->newItem.getCorpwxUserid().equals(existingItem.getCorpwxUserid())
|
|
|
&& (!newItem.getName().equals(existingItem.getName()) || (newItem.getCorpwxDeptid() != null && !newItem.getCorpwxDeptid().equals(existingItem.getCorpwxDeptid()))))).collect(Collectors.toList());
|
|
|
List<Integer> corpWxDeptIds = updateUserList.stream().map(User::getCorpwxDeptid).collect(Collectors.toList());
|
|
|
List<Department> departmentList = null;
|
|
|
if (corpWxDeptIds.size() > 0) {
|
|
|
- //
|
|
|
departmentList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId).in("corpwx_deptid", corpWxDeptIds));
|
|
|
}
|
|
|
final List<Department> fDeptList = departmentList;
|
|
@@ -1514,9 +1539,10 @@ public class WeiXinCorpController {
|
|
|
u.setDepartmentId(0);
|
|
|
u.setDepartmentCascade("0");
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
-
|
|
|
+ if (updateUserList.size() > 0) {
|
|
|
+ userService.updateBatchById(updateUserList);
|
|
|
+ }
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
|
|
@@ -1554,16 +1580,16 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
int companyId = company.getId();
|
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
|
- List<JSONObject> hasDirectLdMembs = new ArrayList<>();
|
|
|
+// List<JSONObject> hasDirectLdMembs = new ArrayList<>();
|
|
|
SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
|
|
int companyRootDeptId = 1;
|
|
|
if (syncMembs == 1) {
|
|
|
- JSONArray unAssignedUserList = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
+ JSONArray allCorpWxUserJsonArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
//获取远程的带姓名的详情,通过企业通讯录的token获取
|
|
|
JSONArray remoteUnAUserList = null;
|
|
|
- if (unAssignedUserList.size() > 0) {
|
|
|
+ if (allCorpWxUserJsonArray.size() > 0) {
|
|
|
remoteUnAUserList = remoteGetDeptUserDetail(wxCorpInfo, corpContactAccessToken, companyRootDeptId);
|
|
|
//做id转化
|
|
|
List<String> corpUserIds = new ArrayList<>();
|
|
@@ -1594,15 +1620,16 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
|
|
|
List<User> updateUserList = new ArrayList<>();
|
|
|
- for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
- JSONObject userJson = unAssignedUserList.getJSONObject(m);
|
|
|
+
|
|
|
+ for (int m=0;m<allCorpWxUserJsonArray.size(); m++) {
|
|
|
+ JSONObject userJson = allCorpWxUserJsonArray.getJSONObject(m);
|
|
|
String curUserid = userJson.getString("userid");
|
|
|
//跳过非激活状态的员工
|
|
|
if (userJson.getInteger("status") != 1) continue;
|
|
|
System.out.println("userid="+curUserid+", name=" + userJson.getString("name")+", department="+userJson.getJSONArray("department"));
|
|
|
- if (userJson.getJSONArray("direct_leader").size() > 0) {
|
|
|
- hasDirectLdMembs.add(userJson);
|
|
|
- }
|
|
|
+// if (userJson.getJSONArray("direct_leader").size() > 0) {
|
|
|
+// hasDirectLdMembs.add(userJson);
|
|
|
+// }
|
|
|
//不存在的人员, 进行插入
|
|
|
User user = new User();
|
|
|
|
|
@@ -1753,9 +1780,9 @@ public class WeiXinCorpController {
|
|
|
String curUserid = userJson.getString("userid");
|
|
|
if (userJson.getInteger("status") != 1) continue;
|
|
|
log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
- if (userJson.getJSONArray("direct_leader").size() > 0) {
|
|
|
- hasDirectLdMembs.add(userJson);
|
|
|
- }
|
|
|
+// if (userJson.getJSONArray("direct_leader").size() > 0) {
|
|
|
+// hasDirectLdMembs.add(userJson);
|
|
|
+// }
|
|
|
//不存在的人员, 进行插入
|
|
|
User user = new User();
|
|
|
|
|
@@ -1843,37 +1870,37 @@ public class WeiXinCorpController {
|
|
|
departmentService.updateBatchById(needUpdateDepts);
|
|
|
}
|
|
|
//更新人员的直属上级
|
|
|
- if (hasDirectLdMembs.size() > 0) {
|
|
|
- List<String> corpwxUids = new ArrayList<>();
|
|
|
- for (JSONObject userJson : hasDirectLdMembs) {
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
- //取第一个leaderId
|
|
|
- JSONArray directLeader = userJson.getJSONArray("direct_leader");
|
|
|
- String string = directLeader.getString(0);
|
|
|
- corpwxUids.add(curUserid);
|
|
|
- if (!corpwxUids.contains(string)) {
|
|
|
- corpwxUids.add(string);
|
|
|
- }
|
|
|
- }
|
|
|
- List<User> userList = userMapper.selectList(new QueryWrapper<User>().select("id, corpwx_userid, superior_id").in("corpwx_userid", corpwxUids));
|
|
|
- List<User> updateUserList = new ArrayList<>();
|
|
|
- for (JSONObject userJson : hasDirectLdMembs) {
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
- User user = userList.stream().filter(u -> u.getCorpwxUserid().equals(curUserid)).findFirst().get();
|
|
|
- JSONArray directLeader = userJson.getJSONArray("direct_leader");
|
|
|
- String leaderCorpWxuid = directLeader.getString(0);
|
|
|
- //查找leader
|
|
|
- User leader = userList.stream().filter(u -> u.getCorpwxUserid().equals(leaderCorpWxuid)).findFirst().get();
|
|
|
- if (!leader.getId().equals(user.getSuperiorId())) {
|
|
|
- user.setSuperiorId(leader.getId());
|
|
|
- updateUserList.add(user);
|
|
|
- }
|
|
|
- }
|
|
|
- if (updateUserList.size() > 0) {
|
|
|
- //批量更新上级领导
|
|
|
- userService.updateBatchById(updateUserList);
|
|
|
- }
|
|
|
- }
|
|
|
+// if (hasDirectLdMembs.size() > 0) {
|
|
|
+// List<String> corpwxUids = new ArrayList<>();
|
|
|
+// for (JSONObject userJson : hasDirectLdMembs) {
|
|
|
+// String curUserid = userJson.getString("userid");
|
|
|
+// //取第一个leaderId
|
|
|
+// JSONArray directLeader = userJson.getJSONArray("direct_leader");
|
|
|
+// String string = directLeader.getString(0);
|
|
|
+// corpwxUids.add(curUserid);
|
|
|
+// if (!corpwxUids.contains(string)) {
|
|
|
+// corpwxUids.add(string);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// List<User> userList = userMapper.selectList(new QueryWrapper<User>().select("id, corpwx_userid, superior_id").in("corpwx_userid", corpwxUids));
|
|
|
+// List<User> updateUserList = new ArrayList<>();
|
|
|
+// for (JSONObject userJson : hasDirectLdMembs) {
|
|
|
+// String curUserid = userJson.getString("userid");
|
|
|
+// User user = userList.stream().filter(u -> u.getCorpwxUserid().equals(curUserid)).findFirst().get();
|
|
|
+// JSONArray directLeader = userJson.getJSONArray("direct_leader");
|
|
|
+// String leaderCorpWxuid = directLeader.getString(0);
|
|
|
+// //查找leader
|
|
|
+// User leader = userList.stream().filter(u -> u.getCorpwxUserid().equals(leaderCorpWxuid)).findFirst().get();
|
|
|
+// if (!leader.getId().equals(user.getSuperiorId())) {
|
|
|
+// user.setSuperiorId(leader.getId());
|
|
|
+// updateUserList.add(user);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// if (updateUserList.size() > 0) {
|
|
|
+// //批量更新上级领导
|
|
|
+// userService.updateBatchById(updateUserList);
|
|
|
+// }
|
|
|
+// }
|
|
|
|
|
|
//更新人员的deptcascade
|
|
|
updateUserDeptCascade(companyId);
|