|
@@ -1466,8 +1466,38 @@ public class WeiXinCorpController {
|
|
//默认普通员工的角色
|
|
//默认普通员工的角色
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
int companyRootDeptId = 1;
|
|
int companyRootDeptId = 1;
|
|
|
|
+ JSONArray allCorpWxUserJsonArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
|
+ System.out.println("获取到公司下的员工数量="+allCorpWxUserJsonArray.size());
|
|
SysRole defaultRole = sysRoleMapper.selectOne(
|
|
SysRole defaultRole = sysRoleMapper.selectOne(
|
|
new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
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);
|
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
|
+ //跳过非激活状态的员工
|
|
|
|
+ if (userJson.getInteger("status") != 1) continue;
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+ JSONArray userDeptArray = userJson.getJSONArray("department");
|
|
|
|
+ //取最末级的,也就是最大的deptId
|
|
|
|
+ int maxDeptId = 1;
|
|
|
|
+ for (int i=0;i<userDeptArray.size(); i++) {
|
|
|
|
+ int curId = userDeptArray.getInteger(i);
|
|
|
|
+ if (curId > maxDeptId) maxDeptId = curId;
|
|
|
|
+ }
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setPhone(userJson.getString("mobile"))
|
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(curUserid)
|
|
|
|
+ .setCorpwxDeptid(maxDeptId);
|
|
|
|
+ System.out.println("姓名=="+user.getName());
|
|
|
|
+ allCorpWxUserList.add(user);
|
|
|
|
+ }
|
|
|
|
|
|
//获取部门
|
|
//获取部门
|
|
JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
@@ -1495,46 +1525,47 @@ public class WeiXinCorpController {
|
|
//有父部门需要更新
|
|
//有父部门需要更新
|
|
curDept.setCorpwxDeptpid(parentId);
|
|
curDept.setCorpwxDeptpid(parentId);
|
|
departmentMapper.updateById(curDept);
|
|
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("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
-
|
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setDepartmentId(deptId == companyRootDeptId?null:curDept.getDepartmentId())
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setCorpwxUserid(curUserid)
|
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
|
- .setJobNumber(curUserid);
|
|
|
|
|
|
|
|
- //检查用户是否已经存在
|
|
|
|
- if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)) == 0) {
|
|
|
|
- userMapper.insert(user);
|
|
|
|
- } else {
|
|
|
|
- //更新信息
|
|
|
|
- System.out.println("更新人员信息== 部门id=="+curDept.getDepartmentId());
|
|
|
|
- User oldUser = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId)).get(0);
|
|
|
|
- oldUser.setName(userJson.getString("name"));
|
|
|
|
- oldUser.setDepartmentId(curDept.getDepartmentId());
|
|
|
|
- userMapper.updateById(oldUser);
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//更新部门层级关系
|
|
//更新部门层级关系
|
|
updateDeptHierachyByCorpWx(companyId);
|
|
updateDeptHierachyByCorpWx(companyId);
|
|
|
|
+
|
|
|
|
+ //设置人员所属部门
|
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ List<User> existingUsers = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
|
+ List<User> newUserList = allCorpWxUserList.stream().filter(newItem -> !existingUsers.stream().anyMatch(existingItem -> newItem.getCorpwxUserid().equals(existingItem.getCorpwxUserid()))).collect(Collectors.toList());
|
|
|
|
+ newUserList.forEach(newItem->{
|
|
|
|
+ if (newItem.getCorpwxDeptid() != 1) {
|
|
|
|
+ int deptId = allDeptList.stream().filter(all->all.getCorpwxDeptid().equals(newItem.getCorpwxDeptid())).findFirst().get().getDepartmentId();
|
|
|
|
+ newItem.setDepartmentId(deptId);
|
|
|
|
+ newItem.setDepartmentCascade(convertDepartmentIdToCascade(deptId, allDeptList));
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ 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 = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId).in("corpwx_deptid", corpWxDeptIds));
|
|
|
|
+ updateUserList.forEach(u->{
|
|
|
|
+ if (u.getCorpwxDeptid() != 1) {
|
|
|
|
+ u.setDepartmentId(departmentList.stream().filter(d->d.getCorpwxDeptid().equals(u.getCorpwxDeptid())).findFirst().get().getDepartmentId());
|
|
|
|
+ //设置层级部门
|
|
|
|
+ u.setDepartmentCascade(convertDepartmentIdToCascade(u.getDepartmentId(), allDeptList));
|
|
|
|
+ } else {
|
|
|
|
+ u.setDepartmentId(0);
|
|
|
|
+ u.setDepartmentCascade("0");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
@RequestMapping("/getCorpMembs")
|
|
@RequestMapping("/getCorpMembs")
|
|
public HttpRespMsg getCorpMembs(String corpId, @RequestParam(required = false, defaultValue = "1") Integer syncMembs) {
|
|
public HttpRespMsg getCorpMembs(String corpId, @RequestParam(required = false, defaultValue = "1") Integer syncMembs) {
|