|
@@ -870,7 +870,11 @@ public class WeiXinCorpController {
|
|
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");
|
|
|
|
+ int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
|
|
|
|
+
|
|
Department department = new Department();
|
|
Department department = new Department();
|
|
|
|
+ department.setCorpwxDeptid(deptId);
|
|
|
|
+ department.setCorpwxDeptpid(parentId);
|
|
department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
department.setCompanyId(companyId);
|
|
department.setCompanyId(companyId);
|
|
departmentMapper.insert(department);
|
|
departmentMapper.insert(department);
|
|
@@ -1466,20 +1470,23 @@ public class WeiXinCorpController {
|
|
return wxCorpInfoService.syncMembByCardTime(wxCorpInfo);
|
|
return wxCorpInfoService.syncMembByCardTime(wxCorpInfo);
|
|
}
|
|
}
|
|
|
|
|
|
- //老版本
|
|
|
|
- @RequestMapping("/getCorpMembsOld")
|
|
|
|
- public HttpRespMsg getCorpMembsOld(String corpId) {
|
|
|
|
-
|
|
|
|
- WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectById(corpId);
|
|
|
|
-
|
|
|
|
- Company company = companyMapper.selectById(wxCorpInfo.getCompanyId());
|
|
|
|
|
|
+ //改造老版的接口,从平台获取客户通讯录
|
|
|
|
+ @RequestMapping("/getCorpMembsFromPlatform")
|
|
|
|
+ public HttpRespMsg getCorpMembsFromPlatform(Integer companyId) {
|
|
|
|
+ Company company = companyMapper.selectById(companyId);
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
|
+ if (wxCorpInfo == null) {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ msg.setError("仅企业微信用户支持该操作");
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
String curCorpAccessToken = null;
|
|
String curCorpAccessToken = null;
|
|
try {
|
|
try {
|
|
curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
curCorpAccessToken = getCorpAccessToken(wxCorpInfo);
|
|
} catch (Exception exception) {
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
- int companyId = company.getId();
|
|
|
|
|
|
+ //默认普通员工的角色
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
int companyRootDeptId = 1;
|
|
int companyRootDeptId = 1;
|
|
JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
|
|
JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
|
|
@@ -1499,6 +1506,7 @@ public class WeiXinCorpController {
|
|
.setCompanyId(companyId)
|
|
.setCompanyId(companyId)
|
|
.setName(userJson.getString("name"))
|
|
.setName(userJson.getString("name"))
|
|
.setCorpwxUserid(curUserid)
|
|
.setCorpwxUserid(curUserid)
|
|
|
|
+ .setJobNumber(curUserid)
|
|
.setColor(ColorUtil.randomColor());
|
|
.setColor(ColorUtil.randomColor());
|
|
|
|
|
|
//检查用户是否已经存在
|
|
//检查用户是否已经存在
|
|
@@ -1513,6 +1521,18 @@ public class WeiXinCorpController {
|
|
|
|
|
|
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");
|
|
|
|
+ int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
|
|
|
|
+ //部门不存在的话要生成部门
|
|
|
|
+ Department curDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", deptId));
|
|
|
|
+ if (curDept == null) {
|
|
|
|
+ Department department = new Department();
|
|
|
|
+ department.setCorpwxDeptid(deptId);
|
|
|
|
+ department.setCorpwxDeptpid(parentId);
|
|
|
|
+ department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
|
|
+ department.setCompanyId(companyId);
|
|
|
|
+ departmentMapper.insert(department);
|
|
|
|
+ curDept = department;
|
|
|
|
+ }
|
|
|
|
|
|
JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
for (int m=0;m<userList.size(); m++) {
|
|
for (int m=0;m<userList.size(); m++) {
|
|
@@ -1526,17 +1546,45 @@ public class WeiXinCorpController {
|
|
.setRoleId(defaultRole.getId())//默认普通员工
|
|
.setRoleId(defaultRole.getId())//默认普通员工
|
|
.setRoleName(defaultRole.getRolename())
|
|
.setRoleName(defaultRole.getRolename())
|
|
.setCompanyId(companyId)
|
|
.setCompanyId(companyId)
|
|
- .setDepartmentId(0)
|
|
|
|
|
|
+ .setDepartmentId(curDept.getDepartmentId())
|
|
.setName(userJson.getString("name"))
|
|
.setName(userJson.getString("name"))
|
|
.setCorpwxUserid(curUserid)
|
|
.setCorpwxUserid(curUserid)
|
|
- .setColor(ColorUtil.randomColor());
|
|
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(curUserid);
|
|
|
|
|
|
//检查用户是否已经存在
|
|
//检查用户是否已经存在
|
|
if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
userMapper.insert(user);
|
|
userMapper.insert(user);
|
|
|
|
+ } else {
|
|
|
|
+ //更新信息
|
|
|
|
+ User oldUser = userMapper.selectList(new QueryWrapper<User>().eq("corpwx_userid", curUserid).eq("company_id", companyId).orderByDesc("create_time")).get(0);
|
|
|
|
+ oldUser.setName(userJson.getString("name"));
|
|
|
|
+ oldUser.setDepartmentId(curDept.getDepartmentId());
|
|
|
|
+ userMapper.updateById(oldUser);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ List<Department> needUpdateDepts = new ArrayList<>();
|
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", companyId));
|
|
|
|
+ for (int i=0;i<allDeptList.size(); i++) {
|
|
|
|
+ Department firstLevel = allDeptList.get(i);
|
|
|
|
+ if (firstLevel.getCorpwxDeptpid() != null) {
|
|
|
|
+ Optional<Department> first = allDeptList.stream().filter(one -> firstLevel.getCorpwxDeptpid().equals(one.getCorpwxDeptid())).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ if (!first.get().getDepartmentId().equals(firstLevel.getSuperiorId())) {
|
|
|
|
+ //结构发生变动,需要更新
|
|
|
|
+ Department updateDpt = new Department();
|
|
|
|
+ updateDpt.setDepartmentId(firstLevel.getDepartmentId());
|
|
|
|
+ updateDpt.setSuperiorId(first.get().getDepartmentId());
|
|
|
|
+ needUpdateDepts.add(updateDpt);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ if (needUpdateDepts.size() > 0) {
|
|
|
|
+ departmentService.updateBatchById(needUpdateDepts);
|
|
|
|
+ }
|
|
|
|
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|