|
@@ -67,7 +67,7 @@ public class WeiXinCorpController {
|
|
public static final String AUTH_CALLBACK_URL = "http://ymhh.yunsu.cn/wxcorp/authcallback";
|
|
public static final String AUTH_CALLBACK_URL = "http://ymhh.yunsu.cn/wxcorp/authcallback";
|
|
//网页获取企业用户信息
|
|
//网页获取企业用户信息
|
|
public static final String GET_CORP_USERINFO_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE";
|
|
public static final String GET_CORP_USERINFO_URL = "https://qyapi.weixin.qq.com/cgi-bin/service/getuserinfo3rd?suite_access_token=SUITE_ACCESS_TOKEN&code=CODE";
|
|
-
|
|
|
|
|
|
+ public static final String GET_LIST_MEMB_AUTH = "https://qyapi.weixin.qq.com/cgi-bin/user/list_member_auth?access_token=ACCESS_TOKEN";
|
|
//获取员工打卡日报统计信息
|
|
//获取员工打卡日报统计信息
|
|
public static final String GET_CHECKIN_DAYDATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=ACCESS_TOKEN";
|
|
public static final String GET_CHECKIN_DAYDATA = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckin_daydata?access_token=ACCESS_TOKEN";
|
|
|
|
|
|
@@ -77,6 +77,8 @@ public class WeiXinCorpController {
|
|
|
|
|
|
public static final String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
|
|
public static final String GET_CORP_TOKEN = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ID&corpsecret=SECRET";
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
@Value("${suitId}")
|
|
@Value("${suitId}")
|
|
private String suitId;
|
|
private String suitId;
|
|
@Value("${suitSecret}")
|
|
@Value("${suitSecret}")
|
|
@@ -551,7 +553,15 @@ public class WeiXinCorpController {
|
|
if (jsonObject.has("AuthCode")) {
|
|
if (jsonObject.has("AuthCode")) {
|
|
//企业授权通知
|
|
//企业授权通知
|
|
String authCode = jsonObject.getString("AuthCode");
|
|
String authCode = jsonObject.getString("AuthCode");
|
|
- handleCorpAuth(authCode);
|
|
|
|
|
|
+ new Thread(){
|
|
|
|
+ public void run() {
|
|
|
|
+ try {
|
|
|
|
+ handleCorpAuth(authCode);
|
|
|
|
+ } catch (Exception exception) {
|
|
|
|
+ exception.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }.start();
|
|
} else if (jsonObject.has("SuiteTicket")) {
|
|
} else if (jsonObject.has("SuiteTicket")) {
|
|
//ticket推送
|
|
//ticket推送
|
|
String ticket = jsonObject.getString("SuiteTicket");
|
|
String ticket = jsonObject.getString("SuiteTicket");
|
|
@@ -839,6 +849,9 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ } else if ("change_auth".equals(jsonObject.get("InfoType"))) {
|
|
|
|
+ String corpId = jsonObject.getString("AuthCorpId");
|
|
|
|
+ getCorpAuthInfo(corpId);
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
// 解密失败,失败原因请查看异常
|
|
// 解密失败,失败原因请查看异常
|
|
@@ -925,7 +938,6 @@ 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 = true;
|
|
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
String resp = responseEntity.getBody();
|
|
String resp = responseEntity.getBody();
|
|
log.info(resp);
|
|
log.info(resp);
|
|
@@ -958,6 +970,8 @@ public class WeiXinCorpController {
|
|
if (jsonObject.getString("name").equals("工时管家")) {
|
|
if (jsonObject.getString("name").equals("工时管家")) {
|
|
int agentId = jsonObject.getInteger("agentid");
|
|
int agentId = jsonObject.getInteger("agentid");
|
|
data.setAgentid(agentId);
|
|
data.setAgentid(agentId);
|
|
|
|
+ //授权模式:0为管理员授权;1为成员授权
|
|
|
|
+ data.setAuthMode(jsonObject.getInteger("auth_mode"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1054,34 +1068,24 @@ public class WeiXinCorpController {
|
|
//生成工作时长
|
|
//生成工作时长
|
|
TimeType timeType = new TimeType();
|
|
TimeType timeType = new TimeType();
|
|
timeType.setCompanyId(company.getId());
|
|
timeType.setCompanyId(company.getId());
|
|
- if (enableNewVersion) {
|
|
|
|
- timeType.setFinanceJobnumEnabled(1);//启用工号来导入财务匹配
|
|
|
|
- }
|
|
|
|
|
|
+ timeType.setFinanceJobnumEnabled(1);//启用工号来导入财务匹配
|
|
timeTypeMapper.insert(timeType);
|
|
timeTypeMapper.insert(timeType);
|
|
|
|
|
|
managerRole = sysRoleService.generateDefaultRoles(company.getId());
|
|
managerRole = sysRoleService.generateDefaultRoles(company.getId());
|
|
}
|
|
}
|
|
data.setCompanyId(company.getId());
|
|
data.setCompanyId(company.getId());
|
|
- data.setSaasSyncContact(enableNewVersion?1:0);
|
|
|
|
|
|
+ data.setSaasSyncContact(1);
|
|
wxCorpInfoMapper.insert(data);
|
|
wxCorpInfoMapper.insert(data);
|
|
//默认普通员工的角色
|
|
//默认普通员工的角色
|
|
- JSONObject userDetail = getUserInfo(curCorpAccessToken, userId);
|
|
|
|
//检查授权人是否存在
|
|
//检查授权人是否存在
|
|
int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", userId));
|
|
int cnt = userMapper.selectCount(new QueryWrapper<User>().eq("corpwx_userid", userId));
|
|
if (cnt == 0) {
|
|
if (cnt == 0) {
|
|
//创建企业负责人账号
|
|
//创建企业负责人账号
|
|
- log.info("===userDetail==" + userDetail.toJSONString());
|
|
|
|
Long id = SnowFlake.nextId();
|
|
Long id = SnowFlake.nextId();
|
|
String name = data.getAuthUsername();
|
|
String name = data.getAuthUsername();
|
|
if (name == null) {
|
|
if (name == null) {
|
|
name = userId;
|
|
name = userId;
|
|
}
|
|
}
|
|
- if (!enableNewVersion) {
|
|
|
|
- //老版本的要兼容转化姓名
|
|
|
|
- if (name.length() > 10) {
|
|
|
|
- name = MessageUtils.message("entry.unknown");
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
|
|
User user = new User()
|
|
User user = new User()
|
|
.setId(id.toString())
|
|
.setId(id.toString())
|
|
@@ -1092,7 +1096,8 @@ public class WeiXinCorpController {
|
|
.setCorpwxUserid(openUserId)
|
|
.setCorpwxUserid(openUserId)
|
|
.setColor(ColorUtil.randomColor())
|
|
.setColor(ColorUtil.randomColor())
|
|
.setCompanyId(company.getId())
|
|
.setCompanyId(company.getId())
|
|
- .setJobNumber(openUserId.equals(userId)?null:userId);
|
|
|
|
|
|
+ .setJobNumber(openUserId.equals(userId)?null:userId)
|
|
|
|
+ .setCorpwxRealUserid(userId);
|
|
userMapper.insert(user);
|
|
userMapper.insert(user);
|
|
//todo: 生成初始测试项目及任务
|
|
//todo: 生成初始测试项目及任务
|
|
Project project=new Project();
|
|
Project project=new Project();
|
|
@@ -1146,9 +1151,7 @@ public class WeiXinCorpController {
|
|
|
|
|
|
int companyId = company.getId();
|
|
int companyId = company.getId();
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
//获取公司根部门人员,也就是没有分配部门的人员
|
|
- if (enableNewVersion) {
|
|
|
|
- getCorpMembsFromPlatform(companyId);
|
|
|
|
- }
|
|
|
|
|
|
+ getCorpMembsFromPlatform(companyId);
|
|
} else {
|
|
} else {
|
|
//企业已经存在
|
|
//企业已经存在
|
|
Integer companyId = data.getCompanyId();
|
|
Integer companyId = data.getCompanyId();
|
|
@@ -1694,170 +1697,224 @@ public class WeiXinCorpController {
|
|
} catch (Exception exception) {
|
|
} catch (Exception exception) {
|
|
exception.printStackTrace();
|
|
exception.printStackTrace();
|
|
}
|
|
}
|
|
- //默认普通员工的角色
|
|
|
|
- //获取公司根部门人员,也就是没有分配部门的人员
|
|
|
|
- int companyRootDeptId = 1;
|
|
|
|
- JSONArray usersUnderRootArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
|
- System.out.println("获取到公司下的员工数量="+usersUnderRootArray.size());
|
|
|
|
- SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
- new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
- List<User> allCorpWxUserList = new ArrayList<>();
|
|
|
|
- for (int m=0;m<usersUnderRootArray.size(); m++) {
|
|
|
|
- JSONObject userJson = usersUnderRootArray.getJSONObject(m);
|
|
|
|
- System.out.println(userJson.toString());
|
|
|
|
- String curUserid = userJson.getString("userid");
|
|
|
|
- String openUserid = userJson.getString("open_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;
|
|
|
|
|
|
+ if (wxCorpInfo.getAuthMode() == 0) {
|
|
|
|
+ //管理员授权模式下,获取部门人员
|
|
|
|
+ int companyRootDeptId = 1;
|
|
|
|
+ JSONArray usersUnderRootArray = getDeptUserInfo(curCorpAccessToken, companyRootDeptId);
|
|
|
|
+ System.out.println("获取到公司下的员工数量="+usersUnderRootArray.size());
|
|
|
|
+ SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
+ new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
|
+ List<User> allCorpWxUserList = new ArrayList<>();
|
|
|
|
+ for (int m=0;m<usersUnderRootArray.size(); m++) {
|
|
|
|
+ JSONObject userJson = usersUnderRootArray.getJSONObject(m);
|
|
|
|
+ System.out.println(userJson.toString());
|
|
|
|
+ String curUserid = userJson.getString("userid");
|
|
|
|
+ String openUserid = userJson.getString("open_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(openUserid)
|
|
|
|
+ .setCorpwxRealUserid(curUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setJobNumber(openUserid.equals(curUserid)?null:curUserid)
|
|
|
|
+ .setCorpwxDeptid(maxDeptId);
|
|
|
|
+ allCorpWxUserList.add(user);
|
|
}
|
|
}
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setPhone(userJson.getString("mobile"))
|
|
|
|
- .setCorpwxUserid(openUserid)
|
|
|
|
- .setCorpwxRealUserid(curUserid)
|
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
- .setJobNumber(openUserid.equals(curUserid)?null:curUserid)
|
|
|
|
- .setCorpwxDeptid(maxDeptId);
|
|
|
|
- allCorpWxUserList.add(user);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- //获取部门
|
|
|
|
- JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
|
|
- JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
|
-
|
|
|
|
- for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
|
- int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
|
- Department curDept = null;
|
|
|
|
- if (deptId != companyRootDeptId) {
|
|
|
|
- int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
|
|
|
|
- //部门不存在的话要生成部门
|
|
|
|
- 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;
|
|
|
|
- } else {
|
|
|
|
- //
|
|
|
|
- System.out.println("找到了已有部门== name=="+curDept.getDepartmentName());
|
|
|
|
- if (parentId != 1 && curDept.getCorpwxDeptpid() == null) {
|
|
|
|
- //有父部门需要更新
|
|
|
|
- curDept.setCorpwxDeptpid(parentId);
|
|
|
|
- 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");
|
|
|
|
- String openUserid = userJson.getString("open_userid");
|
|
|
|
- System.out.println("人员信息:"+userJson.toString());
|
|
|
|
- //不存在的人员, 进行插入
|
|
|
|
- User user = new User();
|
|
|
|
- Optional<User> first = allCorpWxUserList.stream().filter(all -> all.getCorpwxUserid().equals(openUserid)).findFirst();
|
|
|
|
- if (first.isPresent()) {
|
|
|
|
- user = first.get();
|
|
|
|
- user.setCorpwxDeptid(deptId);
|
|
|
|
|
|
+ //获取部门
|
|
|
|
+ JSONObject deptObj = getAllDepartments(curCorpAccessToken);
|
|
|
|
+ JSONArray deptObjJSONArray = deptObj.getJSONArray("department");
|
|
|
|
+
|
|
|
|
+ for (int i=0;i<deptObjJSONArray.size(); i++) {
|
|
|
|
+ int deptId = deptObjJSONArray.getJSONObject(i).getIntValue("id");
|
|
|
|
+ Department curDept = null;
|
|
|
|
+ if (deptId != companyRootDeptId) {
|
|
|
|
+ int parentId = deptObjJSONArray.getJSONObject(i).getIntValue("parentid");
|
|
|
|
+ //部门不存在的话要生成部门
|
|
|
|
+ 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;
|
|
} else {
|
|
} else {
|
|
- //在当前部门下的员工
|
|
|
|
- user.setId(SnowFlake.nextId()+"")
|
|
|
|
- .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
|
- .setRoleName(defaultRole.getRolename())
|
|
|
|
- .setCompanyId(companyId)
|
|
|
|
- .setName(userJson.getString("name"))
|
|
|
|
- .setCorpwxUserid(openUserid)
|
|
|
|
- .setCorpwxRealUserid(curUserid)
|
|
|
|
- .setColor(ColorUtil.randomColor())
|
|
|
|
- .setJobNumber(openUserid.equals(curUserid)?null:curUserid)
|
|
|
|
- .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
- .setCorpwxDeptid(curDept.getCorpwxDeptid());
|
|
|
|
- allCorpWxUserList.add(user);
|
|
|
|
|
|
+ //
|
|
|
|
+ System.out.println("找到了已有部门== name=="+curDept.getDepartmentName());
|
|
|
|
+ if (parentId != 1 && curDept.getCorpwxDeptpid() == null) {
|
|
|
|
+ //有父部门需要更新
|
|
|
|
+ curDept.setCorpwxDeptpid(parentId);
|
|
|
|
+ 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");
|
|
|
|
+ String openUserid = userJson.getString("open_userid");
|
|
|
|
+ System.out.println("人员信息:"+userJson.toString());
|
|
|
|
+ //不存在的人员, 进行插入
|
|
|
|
+ User user = new User();
|
|
|
|
+ Optional<User> first = allCorpWxUserList.stream().filter(all -> all.getCorpwxUserid().equals(openUserid)).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ user = first.get();
|
|
|
|
+ user.setCorpwxDeptid(deptId);
|
|
|
|
+ } else {
|
|
|
|
+ //在当前部门下的员工
|
|
|
|
+ user.setId(SnowFlake.nextId()+"")
|
|
|
|
+ .setRoleId(defaultRole.getId())//默认普通员工
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setCompanyId(companyId)
|
|
|
|
+ .setName(userJson.getString("name"))
|
|
|
|
+ .setCorpwxUserid(openUserid)
|
|
|
|
+ .setCorpwxRealUserid(curUserid)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setJobNumber(openUserid.equals(curUserid)?null:curUserid)
|
|
|
|
+ .setPassword(MD5Util.getPassword("000000"))
|
|
|
|
+ .setCorpwxDeptid(curDept.getCorpwxDeptid());
|
|
|
|
+ allCorpWxUserList.add(user);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- //更新部门层级关系
|
|
|
|
- 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) {
|
|
|
|
- Integer deptId = allDeptList.stream().filter(all->all.getCorpwxDeptid() != null && all.getCorpwxDeptid().equals(newItem.getCorpwxDeptid())).findFirst().get().getDepartmentId();
|
|
|
|
- newItem.setDepartmentId(deptId);
|
|
|
|
- newItem.setDepartmentCascade(convertDepartmentIdToCascade(deptId, allDeptList));
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- if (newUserList.size() > 0) {
|
|
|
|
- userService.saveBatch(newUserList);
|
|
|
|
- }
|
|
|
|
- //姓名,部门,账号的同步更新
|
|
|
|
- List<User> finalUpdateUserList = new ArrayList<>();
|
|
|
|
- for (User userItem : allCorpWxUserList) {
|
|
|
|
- Optional<User> first = existingUsers.stream().filter(ex -> userItem.getCorpwxUserid().equals(ex.getCorpwxUserid())).findFirst();
|
|
|
|
- if (first.isPresent()) {
|
|
|
|
- User oldUser = first.get();
|
|
|
|
- User changeUser = new User();
|
|
|
|
- if (userItem.getJobNumber() != null && !userItem.getJobNumber().equals(oldUser.getJobNumber())) {
|
|
|
|
- changeUser.setId(oldUser.getId());
|
|
|
|
- changeUser.setJobNumber(userItem.getJobNumber());
|
|
|
|
- }
|
|
|
|
- if (userItem.getCorpwxRealUserid() != null && !userItem.getCorpwxRealUserid().equals(oldUser.getCorpwxRealUserid())) {
|
|
|
|
- changeUser.setId(oldUser.getId());
|
|
|
|
- changeUser.setCorpwxRealUserid(userItem.getCorpwxRealUserid());
|
|
|
|
|
|
+ //更新部门层级关系
|
|
|
|
+ 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) {
|
|
|
|
+ Integer deptId = allDeptList.stream().filter(all->all.getCorpwxDeptid() != null && all.getCorpwxDeptid().equals(newItem.getCorpwxDeptid())).findFirst().get().getDepartmentId();
|
|
|
|
+ newItem.setDepartmentId(deptId);
|
|
|
|
+ newItem.setDepartmentCascade(convertDepartmentIdToCascade(deptId, allDeptList));
|
|
}
|
|
}
|
|
- if (!userItem.getName().equals(oldUser.getName())) {
|
|
|
|
- changeUser.setId(oldUser.getId());
|
|
|
|
- changeUser.setName(userItem.getName());
|
|
|
|
- }
|
|
|
|
- if (!userItem.getCorpwxDeptid().equals(oldUser.getCorpwxDeptid())) {
|
|
|
|
- changeUser.setId(oldUser.getId());
|
|
|
|
- if (userItem.getCorpwxDeptid() != 1) {
|
|
|
|
- changeUser.setDepartmentId(allDeptList.stream().filter(d->d.getCorpwxDeptid() != null && d.getCorpwxDeptid().equals(userItem.getCorpwxDeptid())).findFirst().get().getDepartmentId());
|
|
|
|
- //设置层级部门
|
|
|
|
- changeUser.setDepartmentCascade(convertDepartmentIdToCascade(changeUser.getDepartmentId(), allDeptList));
|
|
|
|
- } else {
|
|
|
|
- changeUser.setDepartmentId(0);
|
|
|
|
- changeUser.setDepartmentCascade("0");
|
|
|
|
|
|
+ });
|
|
|
|
+ if (newUserList.size() > 0) {
|
|
|
|
+ userService.saveBatch(newUserList);
|
|
|
|
+ }
|
|
|
|
+ //姓名,部门,账号的同步更新
|
|
|
|
+ List<User> finalUpdateUserList = new ArrayList<>();
|
|
|
|
+ for (User userItem : allCorpWxUserList) {
|
|
|
|
+ Optional<User> first = existingUsers.stream().filter(ex -> userItem.getCorpwxUserid().equals(ex.getCorpwxUserid())).findFirst();
|
|
|
|
+ if (first.isPresent()) {
|
|
|
|
+ User oldUser = first.get();
|
|
|
|
+ User changeUser = new User();
|
|
|
|
+ if (userItem.getJobNumber() != null && !userItem.getJobNumber().equals(oldUser.getJobNumber())) {
|
|
|
|
+ changeUser.setId(oldUser.getId());
|
|
|
|
+ changeUser.setJobNumber(userItem.getJobNumber());
|
|
}
|
|
}
|
|
|
|
+ if (userItem.getCorpwxRealUserid() != null && !userItem.getCorpwxRealUserid().equals(oldUser.getCorpwxRealUserid())) {
|
|
|
|
+ changeUser.setId(oldUser.getId());
|
|
|
|
+ changeUser.setCorpwxRealUserid(userItem.getCorpwxRealUserid());
|
|
|
|
+ }
|
|
|
|
+ if (!userItem.getName().equals(oldUser.getName())) {
|
|
|
|
+ changeUser.setId(oldUser.getId());
|
|
|
|
+ changeUser.setName(userItem.getName());
|
|
|
|
+ }
|
|
|
|
+ if (!userItem.getCorpwxDeptid().equals(oldUser.getCorpwxDeptid())) {
|
|
|
|
+ changeUser.setId(oldUser.getId());
|
|
|
|
+ if (userItem.getCorpwxDeptid() != 1) {
|
|
|
|
+ changeUser.setDepartmentId(allDeptList.stream().filter(d->d.getCorpwxDeptid() != null && d.getCorpwxDeptid().equals(userItem.getCorpwxDeptid())).findFirst().get().getDepartmentId());
|
|
|
|
+ //设置层级部门
|
|
|
|
+ changeUser.setDepartmentCascade(convertDepartmentIdToCascade(changeUser.getDepartmentId(), allDeptList));
|
|
|
|
+ } else {
|
|
|
|
+ changeUser.setDepartmentId(0);
|
|
|
|
+ changeUser.setDepartmentCascade("0");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (oldUser.getCorpwxRealUserid() == null || !userItem.getCorpwxRealUserid().equals(oldUser.getCorpwxRealUserid())) {
|
|
|
|
+ changeUser.setId(oldUser.getId());
|
|
|
|
+ changeUser.setCorpwxRealUserid(userItem.getCorpwxRealUserid());
|
|
|
|
+ }
|
|
|
|
+ if (changeUser.getId() != null) {
|
|
|
|
+ //有变动
|
|
|
|
+ finalUpdateUserList.add(changeUser);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ System.out.println("没找到用户:"+userItem.getName()+", "+userItem.getCorpwxUserid());
|
|
}
|
|
}
|
|
- if (oldUser.getCorpwxRealUserid() == null || !userItem.getCorpwxRealUserid().equals(oldUser.getCorpwxRealUserid())) {
|
|
|
|
- changeUser.setId(oldUser.getId());
|
|
|
|
- changeUser.setCorpwxRealUserid(userItem.getCorpwxRealUserid());
|
|
|
|
- }
|
|
|
|
- if (changeUser.getId() != null) {
|
|
|
|
- //有变动
|
|
|
|
- finalUpdateUserList.add(changeUser);
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- System.out.println("没找到用户:"+userItem.getName()+", "+userItem.getCorpwxUserid());
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- if (finalUpdateUserList.size() > 0) {
|
|
|
|
- userService.updateBatchById(finalUpdateUserList);
|
|
|
|
|
|
+ if (finalUpdateUserList.size() > 0) {
|
|
|
|
+ userService.updateBatchById(finalUpdateUserList);
|
|
|
|
+ }
|
|
|
|
+ } else if (wxCorpInfo.getAuthMode() == 1){
|
|
|
|
+ getMembAuthListLater(curCorpAccessToken, wxCorpInfo);
|
|
}
|
|
}
|
|
|
|
+
|
|
return new HttpRespMsg();
|
|
return new HttpRespMsg();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void getMembAuthListLater(String curCorpAccessToken, WxCorpInfo wxCorpInfo) {
|
|
|
|
+ new Thread(){
|
|
|
|
+ public void run() {
|
|
|
|
+ try {
|
|
|
|
+ //延迟1秒,不然企业微信那边会取不到
|
|
|
|
+ sleep(1000);
|
|
|
|
+ //成员授权模式下,通过获取成员列表来同步人员
|
|
|
|
+ String url = GET_LIST_MEMB_AUTH.replace("ACCESS_TOKEN", curCorpAccessToken);
|
|
|
|
+ System.out.println("请求="+url);
|
|
|
|
+ String result = restTemplate.getForObject(url, String.class);
|
|
|
|
+ System.out.println("第三方应用获取成员授权列表:"+result);
|
|
|
|
+ JSONObject obj = JSONObject.parseObject(result);
|
|
|
|
+ JSONArray membIdList = obj.getJSONArray("member_auth_list");
|
|
|
|
+ String nextCursor = obj.getString("next_cursor");
|
|
|
|
+ if (!StringUtils.isEmpty(nextCursor)) {
|
|
|
|
+ System.err.println("还有数据没处理,超过1000了");
|
|
|
|
+ }
|
|
|
|
+ if (membIdList.size() > 0) {
|
|
|
|
+ SysRole defaultRole = sysRoleMapper.selectOne(
|
|
|
|
+ new QueryWrapper<SysRole>().eq("company_id", wxCorpInfo.getCompanyId()).eq("is_default", 1));
|
|
|
|
+ List<User> oldUserList = userMapper.selectList(new QueryWrapper<User>().select("id, corpwx_userid").eq("company_id", wxCorpInfo.getCompanyId()));
|
|
|
|
+ List<User> newUserList = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < membIdList.size(); i++) {
|
|
|
|
+ String openUserId = membIdList.getJSONObject(i).getString("open_userid");
|
|
|
|
+ Long id = SnowFlake.nextId();
|
|
|
|
+ User user = new User()
|
|
|
|
+ .setId(id.toString())
|
|
|
|
+ .setRoleId(defaultRole.getId())
|
|
|
|
+ .setRoleName(defaultRole.getRolename())
|
|
|
|
+ .setName(openUserId)
|
|
|
|
+ .setCorpwxUserid(openUserId)
|
|
|
|
+ .setColor(ColorUtil.randomColor())
|
|
|
|
+ .setCompanyId(wxCorpInfo.getCompanyId())
|
|
|
|
+ .setCorpwxRealUserid(openUserId);
|
|
|
|
+ if (!oldUserList.stream().anyMatch(old->old.getCorpwxUserid().equals(openUserId))) {
|
|
|
|
+ newUserList.add(user);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (newUserList.size() > 0) {
|
|
|
|
+ userService.saveBatch(newUserList);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }.start();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
//新版本, 由于是第三方服务商,需要先获取授权范围内的组织架构(没有部门和人员的名称),再从中转服务器去获取名称
|
|
@RequestMapping("/getCorpMembs")
|
|
@RequestMapping("/getCorpMembs")
|
|
@@ -2779,4 +2836,37 @@ public class WeiXinCorpController {
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @RequestMapping("getCorpAuthInfo")
|
|
|
|
+ public HttpRespMsg getCorpAuthInfo(String corpId) throws Exception {
|
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
|
+ String suiteAccessToken = getSuiteAccessToken();
|
|
|
|
+ String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_auth_info?suite_access_token="+suiteAccessToken;
|
|
|
|
+ WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("corpid", corpId));
|
|
|
|
+ JSONObject map = new JSONObject();
|
|
|
|
+ map.put("auth_corpid",corpId);
|
|
|
|
+ map.put("permanent_code",wxCorpInfo.getPermanentCode());
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
+ HttpEntity<JSONObject> detailEntity = new HttpEntity<>(map, headers);
|
|
|
|
+ ResponseEntity<String> detailResponseEntity = restTemplate.postForEntity(url, detailEntity, String.class);
|
|
|
|
+ JSONObject json = JSONObject.parseObject(detailResponseEntity.getBody());
|
|
|
|
+ if (json.containsKey("auth_corp_info")){
|
|
|
|
+ JSONArray jsonArray = json.getJSONObject("auth_info").getJSONArray("agent");
|
|
|
|
+ for (int i=0;i<jsonArray.size(); i++) {
|
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
|
+ if (jsonObject.getString("name").equals("工时管家")) {
|
|
|
|
+ System.out.println(jsonObject);
|
|
|
|
+ Integer authMode = jsonObject.getInteger("auth_mode");
|
|
|
|
+ if (!wxCorpInfo.getAuthMode().equals(authMode)) {
|
|
|
|
+ wxCorpInfo.setAuthMode(authMode);
|
|
|
|
+ wxCorpInfoMapper.updateById(wxCorpInfo);
|
|
|
|
+ }
|
|
|
|
+ msg.data = jsonObject.toString();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return msg;
|
|
|
|
+ }
|
|
}
|
|
}
|