|
@@ -680,6 +680,7 @@ public class WeiXinCorpController {
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
HttpEntity<String> requestEntity = new HttpEntity<String>(reqParam.toJSONString(), headers);
|
|
ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
ResponseEntity<String> responseEntity = this.restTemplate.exchange(url,
|
|
HttpMethod.POST, requestEntity, String.class);
|
|
HttpMethod.POST, requestEntity, String.class);
|
|
|
|
+ boolean enableNewVersion = false;
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
String resp = responseEntity.getBody();
|
|
String resp = responseEntity.getBody();
|
|
log.info(resp);
|
|
log.info(resp);
|
|
@@ -788,7 +789,9 @@ public class WeiXinCorpController {
|
|
//生成工作时长
|
|
//生成工作时长
|
|
TimeType timeType = new TimeType();
|
|
TimeType timeType = new TimeType();
|
|
timeType.setCompanyId(company.getId());
|
|
timeType.setCompanyId(company.getId());
|
|
- timeType.setFinanceJobnumEnabled(1);//启用工号来导入财务匹配
|
|
|
|
|
|
+ if (enableNewVersion) {
|
|
|
|
+ timeType.setFinanceJobnumEnabled(1);//启用工号来导入财务匹配
|
|
|
|
+ }
|
|
timeTypeMapper.insert(timeType);
|
|
timeTypeMapper.insert(timeType);
|
|
|
|
|
|
managerRole = sysRoleService.generateDefaultRoles(company.getId());
|
|
managerRole = sysRoleService.generateDefaultRoles(company.getId());
|
|
@@ -808,6 +811,13 @@ public class WeiXinCorpController {
|
|
if (name == null) {
|
|
if (name == null) {
|
|
name = userId;
|
|
name = userId;
|
|
}
|
|
}
|
|
|
|
+ if (!enableNewVersion) {
|
|
|
|
+ //老版本的要兼容转化姓名
|
|
|
|
+ if (name.length() > 10) {
|
|
|
|
+ name = "未知";
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
User user = new User()
|
|
User user = new User()
|
|
.setId(id.toString())
|
|
.setId(id.toString())
|
|
.setRoleId(managerRole.getId())
|
|
.setRoleId(managerRole.getId())
|
|
@@ -824,46 +834,10 @@ public class WeiXinCorpController {
|
|
int companyId = company.getId();
|
|
int companyId = company.getId();
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
int companyRootDeptId = 1;
|
|
int companyRootDeptId = 1;
|
|
- JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
|
|
|
|
- for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
|
- JSONObject userJson = unAssignedUserList.getJSONObject(m);
|
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
|
- log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
-
|
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultUserRole.getId())//默认普通员工
|
|
|
|
- .setRoleName(defaultUserRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setCorpwxUserid(curUserid)
|
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
|
- .setJobNumber(curUserid);//工号就是企业微信的用户ID
|
|
|
|
-
|
|
|
|
- //检查用户是否已经存在
|
|
|
|
- if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
|
|
- userMapper.insert(user);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-// 获取部门
|
|
|
|
- JSONObject deptObj = getDepartments(curCorpAccessToken);
|
|
|
|
- JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
|
-
|
|
|
|
- List<Department> sysDeptList = new ArrayList<>();
|
|
|
|
- for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
|
- int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
|
- Department department = new Department();
|
|
|
|
- department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
|
|
- department.setCompanyId(companyId);
|
|
|
|
- departmentMapper.insert(department);
|
|
|
|
- sysDeptList.add(department);
|
|
|
|
- deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
|
|
|
|
- Integer departmentId = department.getDepartmentId();
|
|
|
|
- JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
|
|
- for (int m=0;m<userList.size(); m++) {
|
|
|
|
- JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
|
|
+ if (enableNewVersion) {
|
|
|
|
+ JSONArray unAssignedUserList = getDeptUserSimple(curCorpAccessToken, companyRootDeptId);
|
|
|
|
+ for (int m=0;m<unAssignedUserList.size(); m++) {
|
|
|
|
+ JSONObject userJson = unAssignedUserList.getJSONObject(m);
|
|
String curUserid = userJson.getString("userid");
|
|
String curUserid = userJson.getString("userid");
|
|
log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
//不存在的人员, 进行插入
|
|
//不存在的人员, 进行插入
|
|
@@ -873,48 +847,86 @@ public class WeiXinCorpController {
|
|
.setRoleId(defaultUserRole.getId())//默认普通员工
|
|
.setRoleId(defaultUserRole.getId())//默认普通员工
|
|
.setRoleName(defaultUserRole.getRolename())
|
|
.setRoleName(defaultUserRole.getRolename())
|
|
.setCompanyId(companyId)
|
|
.setCompanyId(companyId)
|
|
- .setDepartmentId(departmentId)
|
|
|
|
.setName(userJson.getString("name"))
|
|
.setName(userJson.getString("name"))
|
|
.setCorpwxUserid(curUserid)
|
|
.setCorpwxUserid(curUserid)
|
|
.setColor(ColorUtil.randomColor())
|
|
.setColor(ColorUtil.randomColor())
|
|
- .setJobNumber(userId);//工号就是企业微信的用户ID
|
|
|
|
|
|
+ .setJobNumber(curUserid);//工号就是企业微信的用户ID
|
|
|
|
|
|
//检查用户是否已经存在
|
|
//检查用户是否已经存在
|
|
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(departmentId);
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
- userMapper.updateById(oldUser);
|
|
|
|
|
|
+// 获取部门
|
|
|
|
+ JSONObject deptObj = getDepartments(curCorpAccessToken);
|
|
|
|
+ JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
|
+
|
|
|
|
+ List<Department> sysDeptList = new ArrayList<>();
|
|
|
|
+ for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
|
+ int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
|
+ Department department = new Department();
|
|
|
|
+ department.setDepartmentName(deptObjJSONArray.getJSONObject(i).getString("name"));
|
|
|
|
+ department.setCompanyId(companyId);
|
|
|
|
+ departmentMapper.insert(department);
|
|
|
|
+ sysDeptList.add(department);
|
|
|
|
+ deptObjJSONArray.getJSONObject(i).put("sys_dept_id", department.getDepartmentId());
|
|
|
|
+ Integer departmentId = department.getDepartmentId();
|
|
|
|
+ JSONArray userList = getDeptUserSimple(curCorpAccessToken, deptId);
|
|
|
|
+ for (int m=0;m<userList.size(); m++) {
|
|
|
|
+ JSONObject userJson = userList.getJSONObject(m);
|
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
|
+ log.info("userid="+curUserid+", name=" + userJson.getString("name")+", mobile="+userJson.getString("mobile"));
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(defaultUserRole.getId())//默认普通员工
|
|
|
|
+ .setRoleName(defaultUserRole.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setDepartmentId(departmentId)
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setCorpwxUserid(curUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(userId);//工号就是企业微信的用户ID
|
|
|
|
+
|
|
|
|
+ //检查用户是否已经存在
|
|
|
|
+ if (userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", curUserid)) == 0) {
|
|
|
|
+ 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(departmentId);
|
|
|
|
+
|
|
|
|
+ userMapper.updateById(oldUser);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
// 再来更新部门的层级关系
|
|
// 再来更新部门的层级关系
|
|
- 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
|
|
|
|
- int sysDeptId = deptJson.getInteger("sys_dept_id");
|
|
|
|
- Department department = sysDeptList.stream().filter(d -> 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> 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
|
|
|
|
+ int sysDeptId = deptJson.getInteger("sys_dept_id");
|
|
|
|
+ Department department = sysDeptList.stream().filter(d -> 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;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
+ needUpdateDepts.add(department);
|
|
}
|
|
}
|
|
- needUpdateDepts.add(department);
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
- if (needUpdateDepts.size() > 0) {
|
|
|
|
- departmentService.updateBatchById(needUpdateDepts);
|
|
|
|
|
|
+ if (needUpdateDepts.size() > 0) {
|
|
|
|
+ departmentService.updateBatchById(needUpdateDepts);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
//企业已经存在
|
|
//企业已经存在
|