|
@@ -1386,11 +1386,6 @@ public class WeiXinCorpController {
|
|
oldUser.setName(user.getName());
|
|
oldUser.setName(user.getName());
|
|
userMapper.updateById(oldUser);
|
|
userMapper.updateById(oldUser);
|
|
}
|
|
}
|
|
-// //判断部门是否要更新
|
|
|
|
-// if (oldUser.getDepartmentId() != 0) {
|
|
|
|
-// oldUser.setDepartmentId(0);
|
|
|
|
-// userMapper.updateById(oldUser);
|
|
|
|
-// }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1398,14 +1393,15 @@ public class WeiXinCorpController {
|
|
JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
|
|
|
- List<Department> sysDeptList = new ArrayList<>();
|
|
|
|
|
|
+// List<Department> sysDeptList = new ArrayList<>();
|
|
for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
Department department = new Department();
|
|
Department department = new Department();
|
|
-// department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
|
|
department.setCompanyId(companyId);
|
|
department.setCompanyId(companyId);
|
|
//设置企业微信的部门id
|
|
//设置企业微信的部门id
|
|
- department.setCorpwxDeptid(deptObjJSONArray.getJSONObject(i).getInteger("id"));
|
|
|
|
|
|
+ JSONObject cutDeptJson = deptObjJSONArray.getJSONObject(i);
|
|
|
|
+ department.setCorpwxDeptid(cutDeptJson.getInteger("id"));
|
|
|
|
+ department.setCorpwxDeptpid(cutDeptJson.getInteger("parentid"));
|
|
System.out.println("开始远程获取部门详情=====");
|
|
System.out.println("开始远程获取部门详情=====");
|
|
String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", corpContactAccessToken).replace("DEPTID", ""+deptId);
|
|
String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", corpContactAccessToken).replace("DEPTID", ""+deptId);
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
@@ -1424,21 +1420,22 @@ public class WeiXinCorpController {
|
|
if (oldDept == null) {
|
|
if (oldDept == null) {
|
|
if (deptId != 1) {
|
|
if (deptId != 1) {
|
|
//忽略根,根是公司名称
|
|
//忽略根,根是公司名称
|
|
|
|
+ departmentMapper.insert(department);
|
|
//按名称比对
|
|
//按名称比对
|
|
- oldDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("department_name", department.getDepartmentName()).last("limit 1"));
|
|
|
|
- if (oldDept == null) {
|
|
|
|
- departmentMapper.insert(department);
|
|
|
|
- } else {
|
|
|
|
- //按照企业微信部门id进行更新
|
|
|
|
- oldDept.setCorpwxDeptid(department.getCorpwxDeptid());
|
|
|
|
- departmentMapper.updateById(oldDept);
|
|
|
|
- }
|
|
|
|
|
|
+// oldDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("department_name", department.getDepartmentName()).last("limit 1"));
|
|
|
|
+// if (oldDept == null) {
|
|
|
|
+// departmentMapper.insert(department);
|
|
|
|
+// } else {
|
|
|
|
+// //按照企业微信部门id进行更新
|
|
|
|
+// oldDept.setCorpwxDeptid(department.getCorpwxDeptid());
|
|
|
|
+// departmentMapper.updateById(oldDept);
|
|
|
|
+// }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
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 userList = getDeptUserInfo(curCorpAccessToken, deptId);
|
|
@@ -1541,26 +1538,28 @@ public class WeiXinCorpController {
|
|
|
|
|
|
//再来更新部门的层级关系
|
|
//再来更新部门的层级关系
|
|
List<Department> needUpdateDepts = new ArrayList<>();
|
|
List<Department> needUpdateDepts = new ArrayList<>();
|
|
- for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
|
- JSONObject deptJson = deptObjJSONArray.getJSONObject(i);
|
|
|
|
- int pid = deptJson.getInteger("parentid");
|
|
|
|
- if (pid != 1) {
|
|
|
|
- //根部门Id = 1
|
|
|
|
- Integer sysDeptId = deptJson.getInteger("sys_dept_id");
|
|
|
|
- if (sysDeptId != null) {
|
|
|
|
- Department department = sysDeptList.stream().filter(d -> d.getDepartmentId() != null && d.getDepartmentId().equals(sysDeptId)).findFirst().get();
|
|
|
|
- //从deptjson数组中寻找parent item
|
|
|
|
- for (int m=0;m<deptObjJSONArray.size(); m++) {
|
|
|
|
- JSONObject item = deptObjJSONArray.getJSONObject(m);
|
|
|
|
- if (item.getInteger("id").equals(pid)) {
|
|
|
|
- department.setSuperiorId(item.getInteger("sys_dept_id"));
|
|
|
|
- break;
|
|
|
|
- }
|
|
|
|
|
|
+ List<Department> allDbDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ for (Department department : allDbDeptList) {
|
|
|
|
+ int corpwxpid = department.getCorpwxDeptpid();
|
|
|
|
+ if (corpwxpid == 1) {
|
|
|
|
+ //父部门是根部门
|
|
|
|
+// if (department.getSuperiorId() != null) {
|
|
|
|
+// department.setSuperiorId(0);
|
|
|
|
+// needUpdateDepts.add(department);
|
|
|
|
+// }
|
|
|
|
+ } else {
|
|
|
|
+ Optional<Department> first = allDbDeptList.stream().filter(all -> all.getCorpwxDeptid().intValue() == corpwxpid).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ //按照企业微信的部门父部门找到了
|
|
|
|
+ Integer sysPid = first.get().getDepartmentId();
|
|
|
|
+ if (!sysPid.equals(department.getSuperiorId())) {
|
|
|
|
+ department.setSuperiorId(sysPid);
|
|
|
|
+ needUpdateDepts.add(department);
|
|
}
|
|
}
|
|
- needUpdateDepts.add(department);
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
if (needUpdateDepts.size() > 0) {
|
|
if (needUpdateDepts.size() > 0) {
|
|
departmentService.updateBatchById(needUpdateDepts);
|
|
departmentService.updateBatchById(needUpdateDepts);
|
|
}
|
|
}
|
|
@@ -1601,6 +1600,38 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ @RequestMapping("/updateDeptHierachyByCorpWx")
|
|
|
|
+ public HttpRespMsg updateDeptHierachyByCorpWx(Integer companyId) {
|
|
|
|
+ //再来更新部门的层级关系
|
|
|
|
+ List<Department> needUpdateDepts = new ArrayList<>();
|
|
|
|
+ List<Department> allDbDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ for (Department department : allDbDeptList) {
|
|
|
|
+ int corpwxpid = department.getCorpwxDeptpid();
|
|
|
|
+ if (corpwxpid == 1) {
|
|
|
|
+ //父部门是根部门
|
|
|
|
+// if (department.getSuperiorId() != null) {
|
|
|
|
+// department.setSuperiorId(0);
|
|
|
|
+// needUpdateDepts.add(department);
|
|
|
|
+// }
|
|
|
|
+ } else {
|
|
|
|
+ Optional<Department> first = allDbDeptList.stream().filter(all -> all.getCorpwxDeptid().intValue() == corpwxpid).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ //按照企业微信的部门父部门找到了
|
|
|
|
+ Integer sysPid = first.get().getDepartmentId();
|
|
|
|
+ if (!sysPid.equals(department.getSuperiorId())) {
|
|
|
|
+ department.setSuperiorId(sysPid);
|
|
|
|
+ needUpdateDepts.add(department);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (needUpdateDepts.size() > 0) {
|
|
|
|
+ departmentService.updateBatchById(needUpdateDepts);
|
|
|
|
+ }
|
|
|
|
+ return new HttpRespMsg();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
//直接通过企业的通讯录secret获取到组织架构,但是如果调用的服务器是第三方服务商会被腾讯识别并拦截
|
|
//直接通过企业的通讯录secret获取到组织架构,但是如果调用的服务器是第三方服务商会被腾讯识别并拦截
|
|
@RequestMapping("/getCorpMembsWithContactSEC")
|
|
@RequestMapping("/getCorpMembsWithContactSEC")
|