|
@@ -423,42 +423,45 @@ public class WeiXinCorpController {
|
|
} else {
|
|
} else {
|
|
curUserWXDeptid = Integer.valueOf(department);
|
|
curUserWXDeptid = Integer.valueOf(department);
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
|
|
+ } else if (jsonObject.has("MainDepartment")) {
|
|
//取主部门
|
|
//取主部门
|
|
curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println("部门未变更,不处理");
|
|
}
|
|
}
|
|
-
|
|
|
|
- JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
|
- if (userObj != null) {
|
|
|
|
- //成功获取到通讯录的个人详情
|
|
|
|
- JSONArray department = userObj.getJSONArray("department");
|
|
|
|
- curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
|
- Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
|
-
|
|
|
|
- User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", corpWxUserId));
|
|
|
|
- User changeUser = new User();
|
|
|
|
- changeUser.setId(user.getId());
|
|
|
|
-
|
|
|
|
- boolean change = false;
|
|
|
|
- //姓名变化
|
|
|
|
- if (!user.getName().equals(userObj.getString("name"))) {
|
|
|
|
- changeUser.setName(userObj.getString("name"));
|
|
|
|
- change = true;
|
|
|
|
- }
|
|
|
|
- if (sysDept != null && !user.getDepartmentId().equals(sysDept.getDepartmentId())) {
|
|
|
|
- changeUser.setDepartmentId(sysDept.getDepartmentId());
|
|
|
|
- change = true;
|
|
|
|
- }
|
|
|
|
- if (userObj.containsKey("direct_leader") && userObj.getJSONArray("direct_leader").size() > 0) {
|
|
|
|
- String directLeader = userObj.getJSONArray("direct_leader").getString(0);
|
|
|
|
- User leader = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", directLeader));
|
|
|
|
- if (leader != null && !leader.equals(user.getSuperiorId())) {
|
|
|
|
- changeUser.setSuperiorId(leader.getId());
|
|
|
|
|
|
+ if (curUserWXDeptid != 0) {
|
|
|
|
+ JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid, curCorpAccessToken);
|
|
|
|
+ if (userObj != null) {
|
|
|
|
+ //成功获取到通讯录的个人详情
|
|
|
|
+ JSONArray department = userObj.getJSONArray("department");
|
|
|
|
+ curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
|
+ Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
|
+
|
|
|
|
+ User user = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", corpWxUserId));
|
|
|
|
+ User changeUser = new User();
|
|
|
|
+ changeUser.setId(user.getId());
|
|
|
|
+
|
|
|
|
+ boolean change = false;
|
|
|
|
+ //姓名变化
|
|
|
|
+ if (!user.getName().equals(userObj.getString("name"))) {
|
|
|
|
+ changeUser.setName(userObj.getString("name"));
|
|
change = true;
|
|
change = true;
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (change) {
|
|
|
|
- userMapper.updateById(changeUser);
|
|
|
|
|
|
+ if (sysDept != null && !user.getDepartmentId().equals(sysDept.getDepartmentId())) {
|
|
|
|
+ changeUser.setDepartmentId(sysDept.getDepartmentId());
|
|
|
|
+ change = true;
|
|
|
|
+ }
|
|
|
|
+ if (userObj.containsKey("direct_leader") && userObj.getJSONArray("direct_leader").size() > 0) {
|
|
|
|
+ String directLeader = userObj.getJSONArray("direct_leader").getString(0);
|
|
|
|
+ User leader = userMapper.selectOne(new QueryWrapper<User>().eq("company_id", companyId).eq("corpwx_userid", directLeader));
|
|
|
|
+ if (leader != null && !leader.equals(user.getSuperiorId())) {
|
|
|
|
+ changeUser.setSuperiorId(leader.getId());
|
|
|
|
+ change = true;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (change) {
|
|
|
|
+ userMapper.updateById(changeUser);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -487,6 +490,45 @@ public class WeiXinCorpController {
|
|
departmentMapper.insert(department);
|
|
departmentMapper.insert(department);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } else if ("update_party".equals(changeType)) {
|
|
|
|
+ //变更部门,父部门变化
|
|
|
|
+ String corpId = jsonObject.getString("AuthCorpId");
|
|
|
|
+ Integer deptId = jsonObject.getInt("Id");
|
|
|
|
+ Integer parentDeptId = jsonObject.getInt("ParentId");
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
|
+ if (wxCorpInfo != null && !StringUtils.isEmpty(wxCorpInfo.getContactSecret())) {
|
|
|
|
+ if (parentDeptId != null) {
|
|
|
|
+ //发生父部门的结构变化了
|
|
|
|
+ Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
|
+ if (department != null) {
|
|
|
|
+ Department parentDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", parentDeptId));
|
|
|
|
+ if (parentDept != null) {
|
|
|
|
+ department.setSuperiorId(parentDept.getDepartmentId());
|
|
|
|
+ departmentMapper.updateById(department);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (jsonObject.getString("Name") != null) {
|
|
|
|
+ //发生了部门名称变化
|
|
|
|
+ System.out.println("部门名称变化了,请处理==企业微信部门id="+deptId);
|
|
|
|
+ String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", remoteCorpConcactAccessToken).replace("DEPTID", ""+deptId);
|
|
|
|
+ String result = restTemplate.getForObject(url, String.class);
|
|
|
|
+ System.out.println("部门返回数据:"+result);
|
|
|
|
+ JSONObject resultObj = JSONObject.parseObject(JSONObject.parseObject(result).getString("data"));
|
|
|
|
+ if (resultObj.getInteger("errcode") == 0) {
|
|
|
|
+ JSONObject serverDept = resultObj.getJSONObject("department");
|
|
|
|
+ String name = serverDept.getString("name");
|
|
|
|
+ Department department = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", wxCorpInfo.getCompanyId()).eq("corpwx_deptid", deptId));
|
|
|
|
+ department.setDepartmentName(name);
|
|
|
|
+ departmentMapper.updateById(department);
|
|
|
|
+ } else {
|
|
|
|
+ System.err.println("同步获取部门详情报错:"+resultObj.toString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
@@ -1342,7 +1384,7 @@ public class WeiXinCorpController {
|
|
|
|
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
@RequestMapping("/getCorpMembs")
|
|
@RequestMapping("/getCorpMembs")
|
|
- public HttpRespMsg getCorpMembs(String corpId) {
|
|
|
|
|
|
+ public HttpRespMsg getCorpMembs(String corpId, @RequestParam(required = false, defaultValue = "1") Integer syncMembs) {
|
|
System.out.println("============新版getCorpMembs=========");
|
|
System.out.println("============新版getCorpMembs=========");
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
@@ -1370,93 +1412,97 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
int companyId = company.getId();
|
|
int companyId = company.getId();
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
|
|
+ List<JSONObject> hasDirectLdMembs = new ArrayList<>();
|
|
|
|
+ SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
+ new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
+
|
|
int companyRootDeptId = 1;
|
|
int companyRootDeptId = 1;
|
|
- JSONArray unAssignedUserList = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
|
- //获取远程的带姓名的详情,通过企业通讯录的token获取
|
|
|
|
- JSONArray remoteUnAUserList = null;
|
|
|
|
- if (unAssignedUserList.size() > 0) {
|
|
|
|
- remoteUnAUserList = remoteGetDeptUserDetail(corpContactAccessToken, companyRootDeptId);
|
|
|
|
- //做id转化
|
|
|
|
- List<String> userIds = new ArrayList<>();
|
|
|
|
- for (int i=0;i<remoteUnAUserList.size(); i++) {
|
|
|
|
- userIds.add(remoteUnAUserList.getJSONObject(i).getString("userid"));
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
|
|
|
|
- for (int i=0;i<array.size(); i++) {
|
|
|
|
- JSONObject jsonObject = array.getJSONObject(i);
|
|
|
|
- String userid = jsonObject.getString("userid");
|
|
|
|
- String openUserid = jsonObject.getString("open_userid");
|
|
|
|
- //替换userid
|
|
|
|
- for (int m=0;m<remoteUnAUserList.size(); m++) {
|
|
|
|
- JSONObject remoteUser = remoteUnAUserList.getJSONObject(m);
|
|
|
|
- if (remoteUser.getString("userid").equals(userid)) {
|
|
|
|
- remoteUser.put("userid", openUserid);
|
|
|
|
- break;
|
|
|
|
|
|
+ if (syncMembs == 1) {
|
|
|
|
+ JSONArray unAssignedUserList = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
|
+ //获取远程的带姓名的详情,通过企业通讯录的token获取
|
|
|
|
+ JSONArray remoteUnAUserList = null;
|
|
|
|
+ if (unAssignedUserList.size() > 0) {
|
|
|
|
+ remoteUnAUserList = remoteGetDeptUserDetail(corpContactAccessToken, companyRootDeptId);
|
|
|
|
+ //做id转化
|
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
|
+ for (int i=0;i<remoteUnAUserList.size(); i++) {
|
|
|
|
+ userIds.add(remoteUnAUserList.getJSONObject(i).getString("userid"));
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
|
|
|
|
+ for (int i=0;i<array.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = array.getJSONObject(i);
|
|
|
|
+ String userid = jsonObject.getString("userid");
|
|
|
|
+ String openUserid = jsonObject.getString("open_userid");
|
|
|
|
+ //替换userid
|
|
|
|
+ for (int m=0;m<remoteUnAUserList.size(); m++) {
|
|
|
|
+ JSONObject remoteUser = remoteUnAUserList.getJSONObject(m);
|
|
|
|
+ if (remoteUser.getString("userid").equals(userid)) {
|
|
|
|
+ remoteUser.put("userid", openUserid);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
+ return msg;
|
|
}
|
|
}
|
|
- } catch (Exception exception) {
|
|
|
|
- exception.printStackTrace();
|
|
|
|
- msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
- return msg;
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
- new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
- List<JSONObject> hasDirectLdMembs = new ArrayList<>();
|
|
|
|
- for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
|
- JSONObject userJson = unAssignedUserList.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);
|
|
|
|
- }
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
|
|
|
|
- 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());
|
|
|
|
- //获取姓名
|
|
|
|
- if (remoteUnAUserList != null) {
|
|
|
|
- for (int i=0;i<remoteUnAUserList.size(); i++) {
|
|
|
|
- JSONObject remoteUserJson = remoteUnAUserList.getJSONObject(i);
|
|
|
|
- if (remoteUserJson.getString("userid").equals(curUserid)) {
|
|
|
|
- user.setName(remoteUserJson.getString("name"));
|
|
|
|
- break;
|
|
|
|
|
|
+ for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
|
+ JSONObject userJson = unAssignedUserList.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);
|
|
|
|
+ }
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+
|
|
|
|
+ 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());
|
|
|
|
+ //获取姓名
|
|
|
|
+ if (remoteUnAUserList != null) {
|
|
|
|
+ for (int i=0;i<remoteUnAUserList.size(); i++) {
|
|
|
|
+ JSONObject remoteUserJson = remoteUnAUserList.getJSONObject(i);
|
|
|
|
+ if (remoteUserJson.getString("userid").equals(curUserid)) {
|
|
|
|
+ user.setName(remoteUserJson.getString("name"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- //检查用户是否已经存在
|
|
|
|
- User oldUser = userMapper.selectOne(new QueryWrapper<User>().select("id, name, role_name").eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
|
-
|
|
|
|
- if (oldUser == null) {
|
|
|
|
- //先检查姓名+手机号是否存在,如果存在,则更新corpwxId
|
|
|
|
- User sameNameUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", user.getName()).eq("phone", user.getPhone()).eq("company_id", companyId).isNull("corpwx_userid").last("limit 1"));
|
|
|
|
- if (sameNameUser != null) {
|
|
|
|
- User upUser = new User();
|
|
|
|
- upUser.setId(sameNameUser.getId());
|
|
|
|
- upUser.setCorpwxUserid(user.getCorpwxUserid());
|
|
|
|
- userMapper.updateById(upUser);
|
|
|
|
|
|
+ //检查用户是否已经存在
|
|
|
|
+ User oldUser = userMapper.selectOne(new QueryWrapper<User>().select("id, name, role_name").eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
|
+
|
|
|
|
+ if (oldUser == null) {
|
|
|
|
+ //先检查姓名+手机号是否存在,如果存在,则更新corpwxId
|
|
|
|
+ User sameNameUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", user.getName()).eq("phone", user.getPhone()).eq("company_id", companyId).isNull("corpwx_userid").last("limit 1"));
|
|
|
|
+ if (sameNameUser != null) {
|
|
|
|
+ User upUser = new User();
|
|
|
|
+ upUser.setId(sameNameUser.getId());
|
|
|
|
+ upUser.setCorpwxUserid(user.getCorpwxUserid());
|
|
|
|
+ userMapper.updateById(upUser);
|
|
|
|
+ } else {
|
|
|
|
+ userMapper.insert(user);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- userMapper.insert(user);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- if (oldUser.getRoleName().equals("超级管理员") && !oldUser.getName().equals(user.getName())) {
|
|
|
|
- //姓名不一致,需要更新
|
|
|
|
- System.out.println("===更新超管姓名==="+user.getName());
|
|
|
|
- user.setId(oldUser.getId());
|
|
|
|
- oldUser.setName(user.getName());
|
|
|
|
- userMapper.updateById(oldUser);
|
|
|
|
|
|
+ if (oldUser.getRoleName().equals("超级管理员") && !oldUser.getName().equals(user.getName())) {
|
|
|
|
+ //姓名不一致,需要更新
|
|
|
|
+ System.out.println("===更新超管姓名==="+user.getName());
|
|
|
|
+ user.setId(oldUser.getId());
|
|
|
|
+ oldUser.setName(user.getName());
|
|
|
|
+ userMapper.updateById(oldUser);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1504,106 +1550,126 @@ public class WeiXinCorpController {
|
|
// }
|
|
// }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
|
|
+ //比较是否有更新
|
|
|
|
+ boolean hasChange = false;
|
|
|
|
+ if (!oldDept.getDepartmentName().equals(department.getDepartmentName())) {
|
|
|
|
+ oldDept.setDepartmentName(department.getDepartmentName());
|
|
|
|
+ hasChange = true;
|
|
|
|
+ }
|
|
|
|
+ if (!department.getCorpwxDeptpid().equals(oldDept.getCorpwxDeptpid())) {
|
|
|
|
+ oldDept.setCorpwxDeptpid(department.getCorpwxDeptpid());
|
|
|
|
+ Department newParentDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", oldDept.getCorpwxDeptpid()));
|
|
|
|
+ if (newParentDept != null) {
|
|
|
|
+ oldDept.setSuperiorId(newParentDept.getDepartmentId());
|
|
|
|
+ }
|
|
|
|
+ hasChange = true;
|
|
|
|
+ }
|
|
|
|
+ if (hasChange) {
|
|
|
|
+ System.out.println("更新部门结构=="+oldDept.getDepartmentName());
|
|
|
|
+ departmentMapper.updateById(oldDept);
|
|
|
|
+ }
|
|
department = oldDept;
|
|
department = oldDept;
|
|
}
|
|
}
|
|
|
|
|
|
// sysDeptList.add(department);
|
|
// sysDeptList.add(department);
|
|
deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
|
|
deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
|
|
Integer departmentId = department.getDepartmentId();
|
|
Integer departmentId = department.getDepartmentId();
|
|
- JSONArray userList = getDeptUserInfo(curCorpAccessToken, deptId);
|
|
|
|
- JSONArray remoteDeptUserList = null;
|
|
|
|
- if (userList.size() > 0) {
|
|
|
|
- remoteDeptUserList = remoteGetDeptUserDetail(corpContactAccessToken, deptId);
|
|
|
|
- //做id转化
|
|
|
|
- List<String> userIds = new ArrayList<>();
|
|
|
|
- for (int p=0;p<remoteDeptUserList.size(); p++) {
|
|
|
|
- userIds.add(remoteDeptUserList.getJSONObject(p).getString("userid"));
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
|
|
|
|
- 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("userid", openUserid);
|
|
|
|
- break;
|
|
|
|
|
|
+ if (syncMembs == 1) {
|
|
|
|
+ JSONArray userList = getDeptUserInfo(curCorpAccessToken, deptId);
|
|
|
|
+ JSONArray remoteDeptUserList = null;
|
|
|
|
+ if (userList.size() > 0) {
|
|
|
|
+ remoteDeptUserList = remoteGetDeptUserDetail(corpContactAccessToken, deptId);
|
|
|
|
+ //做id转化
|
|
|
|
+ List<String> userIds = new ArrayList<>();
|
|
|
|
+ for (int p=0;p<remoteDeptUserList.size(); p++) {
|
|
|
|
+ userIds.add(remoteDeptUserList.getJSONObject(p).getString("userid"));
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ JSONArray array = convertUserIdToOpenUserId(curCorpAccessToken, userIds);
|
|
|
|
+ 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("userid", openUserid);
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
+ return msg;
|
|
}
|
|
}
|
|
- } catch (Exception exception) {
|
|
|
|
- exception.printStackTrace();
|
|
|
|
- msg.setError("同步失败:"+exception.getMessage());
|
|
|
|
- return msg;
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- for (int m=0;m<userList.size(); m++) {
|
|
|
|
- JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
-
|
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultRole.getId())
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setDepartmentId(departmentId)
|
|
|
|
- .setPhone(userJson.getString("mobile"))
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setCorpwxUserid(curUserid)
|
|
|
|
- .setColor(ColorUtil.randomColor());
|
|
|
|
- //获取姓名
|
|
|
|
- if (remoteDeptUserList != null) {
|
|
|
|
- for (int t=0;t<remoteDeptUserList.size(); t++) {
|
|
|
|
- JSONObject remoteUserJson = remoteDeptUserList.getJSONObject(t);
|
|
|
|
- if (remoteUserJson.getString("userid").equals(curUserid)) {
|
|
|
|
- //匹配到了。设置姓名
|
|
|
|
- System.out.println("远程的用户匹配到了:"+remoteUserJson.getString("name"));
|
|
|
|
- user.setName(remoteUserJson.getString("name"));
|
|
|
|
- break;
|
|
|
|
|
|
+ for (int m=0;m<userList.size(); m++) {
|
|
|
|
+ JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setDepartmentId(departmentId)
|
|
|
|
+ .setPhone(userJson.getString("mobile"))
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor());
|
|
|
|
+ //获取姓名
|
|
|
|
+ if (remoteDeptUserList != null) {
|
|
|
|
+ for (int t=0;t<remoteDeptUserList.size(); t++) {
|
|
|
|
+ JSONObject remoteUserJson = remoteDeptUserList.getJSONObject(t);
|
|
|
|
+ if (remoteUserJson.getString("userid").equals(curUserid)) {
|
|
|
|
+ //匹配到了。设置姓名
|
|
|
|
+ System.out.println("远程的用户匹配到了:"+remoteUserJson.getString("name"));
|
|
|
|
+ user.setName(remoteUserJson.getString("name"));
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- //检查用户是否已经存在
|
|
|
|
- User oldUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
|
- if (oldUser == null) {
|
|
|
|
- //先检查姓名是否存在,如果存在,则更新corpwxId
|
|
|
|
- User sameNameUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", user.getName()).eq("phone", user.getPhone()).eq("company_id", companyId).isNull("corpwx_userid").last("limit 1"));
|
|
|
|
- if (sameNameUser != null) {
|
|
|
|
- User upUser = new User();
|
|
|
|
- upUser.setId(sameNameUser.getId());
|
|
|
|
- upUser.setCorpwxUserid(user.getCorpwxUserid());
|
|
|
|
- userMapper.updateById(upUser);
|
|
|
|
|
|
+ //检查用户是否已经存在
|
|
|
|
+ User oldUser = userMapper.selectOne(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
|
+ if (oldUser == null) {
|
|
|
|
+ //先检查姓名是否存在,如果存在,则更新corpwxId
|
|
|
|
+ User sameNameUser = userMapper.selectOne(new QueryWrapper<User>().eq("name", user.getName()).eq("phone", user.getPhone()).eq("company_id", companyId).isNull("corpwx_userid").last("limit 1"));
|
|
|
|
+ if (sameNameUser != null) {
|
|
|
|
+ User upUser = new User();
|
|
|
|
+ upUser.setId(sameNameUser.getId());
|
|
|
|
+ upUser.setCorpwxUserid(user.getCorpwxUserid());
|
|
|
|
+ userMapper.updateById(upUser);
|
|
|
|
+ } else {
|
|
|
|
+ //姓名也不存在,则插入新记录
|
|
|
|
+ userMapper.insert(user);
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- //姓名也不存在,则插入新记录
|
|
|
|
- userMapper.insert(user);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- boolean shouldUpdate = false;
|
|
|
|
- if (oldUser.getRoleName().equals("超级管理员") && !oldUser.getName().equals(user.getName())) {
|
|
|
|
- //姓名不一致,需要更新
|
|
|
|
- System.out.println("===更新超管姓名==="+user.getName());
|
|
|
|
- user.setId(oldUser.getId());
|
|
|
|
- oldUser.setName(user.getName());
|
|
|
|
- shouldUpdate = true;
|
|
|
|
- }
|
|
|
|
- if (!oldUser.getDepartmentId().equals(user.getDepartmentId())) {
|
|
|
|
- oldUser.setDepartmentId(user.getDepartmentId());
|
|
|
|
- shouldUpdate = true;
|
|
|
|
- }
|
|
|
|
- if (shouldUpdate) {
|
|
|
|
- userMapper.updateById(oldUser);
|
|
|
|
- }
|
|
|
|
|
|
+ boolean shouldUpdate = false;
|
|
|
|
+ if (oldUser.getRoleName().equals("超级管理员") && !oldUser.getName().equals(user.getName())) {
|
|
|
|
+ //姓名不一致,需要更新
|
|
|
|
+ System.out.println("===更新超管姓名==="+user.getName());
|
|
|
|
+ user.setId(oldUser.getId());
|
|
|
|
+ oldUser.setName(user.getName());
|
|
|
|
+ shouldUpdate = true;
|
|
|
|
+ }
|
|
|
|
+ if (!oldUser.getDepartmentId().equals(user.getDepartmentId())) {
|
|
|
|
+ oldUser.setDepartmentId(user.getDepartmentId());
|
|
|
|
+ shouldUpdate = true;
|
|
|
|
+ }
|
|
|
|
+ if (shouldUpdate) {
|
|
|
|
+ userMapper.updateById(oldUser);
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|