|
@@ -36,7 +36,7 @@ public class WeiXinCorpController {
|
|
|
public static final String TRANSMIT_SERVER_GET_DEPTDETAIL = "http://47.101.180.183:10010/wxcorp/getCorpDeptDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
public static final String TRANSMIT_SERVER_GET_DEPTMEMBDETAIL = "http://47.101.180.183:10010/wxcorp/getDeptUserDetail?accessToken=ACCESS_TOKEN&deptId=DEPTID";
|
|
|
public static final String TRANSMIT_SERVER_GET_CONTACT_TOKEN = "http://47.101.180.183:10010/wxcorp/getCorpConcactAccessToken?corpid=CORPID&contactSecret=CONTACT_SECRET";
|
|
|
- public static final String TRANSMIT_SERVER_GET_USERDETAIL = "http://47.101.180.183:10010/wxcorp/getUserInfoFromTranServer?accessToken=ACCESS_TOKEN&userId=USERID";
|
|
|
+ public static final String TRANSMIT_SERVER_GET_USERDETAIL = "http://47.101.180.183:10010/wxcorp/getUserInfoFromTranServer?accessToken=ACCESS_TOKEN&userId=USERID&deptId=DEPTID";
|
|
|
|
|
|
public static final String POST_CONVERT_USERID = "https://qyapi.weixin.qq.com/cgi-bin/batch/userid_to_openuserid?access_token=ACCESS_TOKEN";
|
|
|
|
|
@@ -372,12 +372,14 @@ public class WeiXinCorpController {
|
|
|
SysRole defaultRole = sysRoleMapper.selectOne(new QueryWrapper<SysRole>().eq("company_id", companyId).eq("is_default", 1));
|
|
|
//通过通讯录secret获取到员工姓名
|
|
|
String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId);
|
|
|
+ org.json.JSONArray departmentArray = jsonObject.getJSONArray("department");
|
|
|
+ Integer curUserWXDeptid = departmentArray.getInt(departmentArray.length() - 1);
|
|
|
+ JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid);
|
|
|
if (userObj.getInteger("errcode") == 0) {
|
|
|
//成功获取到通讯录的个人详情
|
|
|
Long id = SnowFlake.nextId();
|
|
|
JSONArray department = userObj.getJSONArray("department");
|
|
|
- Integer curUserWXDeptid = department.getInteger(department.size() - 1);
|
|
|
+ curUserWXDeptid = getMaxDeptIdFromArray(department);
|
|
|
Department sysDept = departmentMapper.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", curUserWXDeptid));
|
|
|
|
|
|
User user = new User()
|
|
@@ -410,11 +412,25 @@ public class WeiXinCorpController {
|
|
|
//只有授权通讯录同步的,才有机会更新部门或者上级
|
|
|
if (!StringUtils.isEmpty(wxCorpInfo.getContactSecret())) {
|
|
|
String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
- JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId);
|
|
|
+ Integer curUserWXDeptid = 0;
|
|
|
+ if (jsonObject.has("Department")) {
|
|
|
+ Object departmentJ = jsonObject.get("Department");
|
|
|
+ if (departmentJ instanceof String || departmentJ instanceof Integer) {
|
|
|
+ curUserWXDeptid = jsonObject.getInt("Department");
|
|
|
+ } else if (departmentJ instanceof org.json.JSONArray) {
|
|
|
+ org.json.JSONArray departmentArray = jsonObject.getJSONArray("Department");
|
|
|
+ curUserWXDeptid = getMaxDeptIdFromArray(departmentArray);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //取主部门
|
|
|
+ curUserWXDeptid = jsonObject.getInt("MainDepartment");
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject userObj = remoteGetUserDetail(remoteCorpConcactAccessToken, corpWxUserId, curUserWXDeptid);
|
|
|
if (userObj.getInteger("errcode") == 0) {
|
|
|
//成功获取到通讯录的个人详情
|
|
|
JSONArray department = userObj.getJSONArray("department");
|
|
|
- Integer curUserWXDeptid = department.getInteger(department.size() - 1);
|
|
|
+ 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));
|
|
@@ -444,7 +460,30 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ } else if ("create_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())) {
|
|
|
+ String remoteCorpConcactAccessToken = getRemoteCorpConcactAccessToken(wxCorpInfo);
|
|
|
+ Integer companyId = wxCorpInfo.getCompanyId();
|
|
|
+ Department department = new Department();
|
|
|
+ department.setCompanyId(companyId);
|
|
|
+ department.setCorpwxDeptid(deptId);
|
|
|
+ JSONObject deptJson = remoteGetDeptDetail(remoteCorpConcactAccessToken, deptId);
|
|
|
+ if (deptJson != null) {
|
|
|
+ //成功获取到了
|
|
|
+ String name = deptJson.getString("name");
|
|
|
+ department.setDepartmentName(name);
|
|
|
+ Department parentDept = department.selectOne(new QueryWrapper<Department>().eq("company_id", companyId).eq("corpwx_deptid", parentDeptId));
|
|
|
+ if (parentDept != null) {
|
|
|
+ department.setSuperiorId(parentDeptId);
|
|
|
+ }
|
|
|
+ departmentMapper.insert(department);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -455,6 +494,24 @@ public class WeiXinCorpController {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
+ private Integer getMaxDeptIdFromArray(JSONArray department) {
|
|
|
+ int deptId=0;
|
|
|
+ for (int i=0;i<department.size(); i++) {
|
|
|
+ if (deptId < department.getInteger(i)) {
|
|
|
+ deptId = department.getInteger(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return deptId;
|
|
|
+ }
|
|
|
+ private Integer getMaxDeptIdFromArray(org.json.JSONArray department) {
|
|
|
+ int deptId=0;
|
|
|
+ for (int i=0;i<department.length(); i++) {
|
|
|
+ if (deptId < department.getInt(i)) {
|
|
|
+ deptId = department.getInt(i);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return deptId;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
//"企业授权微信应用", notes = "企业授权微信应用")
|
|
@@ -1295,7 +1352,8 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
}
|
|
|
//检查用户是否已经存在
|
|
|
- User oldUser = userMapper.selectOne(new QueryWrapper<User>().select("id, name").eq("corpwx_userid", curUserid).eq("company_id", companyId));
|
|
|
+ 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"));
|
|
@@ -1307,12 +1365,14 @@ public class WeiXinCorpController {
|
|
|
} 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);
|
|
|
+ } 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);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1733,6 +1793,20 @@ public class WeiXinCorpController {
|
|
|
return new HttpRespMsg();
|
|
|
}
|
|
|
|
|
|
+ private JSONObject remoteGetDeptDetail(String accessToken, int deptId) {
|
|
|
+ String url = TRANSMIT_SERVER_GET_DEPTDETAIL.replace("ACCESS_TOKEN", accessToken).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");
|
|
|
+ return serverDept;
|
|
|
+ } else {
|
|
|
+ System.err.println("同步获取部门详情报错:"+resultObj.toString());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private JSONArray remoteGetDeptUserDetail(String accessToken, int deptId) {
|
|
|
String url = TRANSMIT_SERVER_GET_DEPTMEMBDETAIL.replace("ACCESS_TOKEN", accessToken).replace("DEPTID", ""+deptId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
@@ -1741,8 +1815,9 @@ public class WeiXinCorpController {
|
|
|
return obj;
|
|
|
}
|
|
|
|
|
|
- private JSONObject remoteGetUserDetail(String accessToken, String userId) {
|
|
|
- String url = TRANSMIT_SERVER_GET_USERDETAIL.replace("ACCESS_TOKEN", accessToken).replace("USERID", userId);
|
|
|
+ private JSONObject remoteGetUserDetail(String accessToken, String userId, Integer deptId) {
|
|
|
+ String url = TRANSMIT_SERVER_GET_USERDETAIL.replace("ACCESS_TOKEN", accessToken).replace("USERID", userId)
|
|
|
+ .replace("DEPTID", deptId+"");
|
|
|
System.out.println("请求URL="+url);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
System.out.println("远程人员详情:"+result);
|
|
@@ -1821,7 +1896,22 @@ public class WeiXinCorpController {
|
|
|
}
|
|
|
//用于从中转服务器获取企业通讯录的单个人员详情
|
|
|
@RequestMapping("/getUserInfoFromTranServer")
|
|
|
- public HttpRespMsg getUserInfoFromTranServer(String accessToken, String userId) {
|
|
|
+ public HttpRespMsg getUserInfoFromTranServer(String accessToken, String userId, Integer deptId) {
|
|
|
+ String sampleOpenUserId = "woy9TkCAAAaAxThm4apuAlWID8HIxh_g";
|
|
|
+ if (userId.length() == sampleOpenUserId.length() && userId.startsWith("woy9Tk")) {
|
|
|
+ //用OpenUserId作userId的情况,需要获取部门下的全部人员进行转化获取
|
|
|
+ System.out.println("人员详情===去获取部门人员详情了===");
|
|
|
+ JSONArray transDeptUserInfo = getTransDeptUserInfo(accessToken, deptId);
|
|
|
+ for (int i=0;i<transDeptUserInfo.size(); i++) {
|
|
|
+ JSONObject userObj = transDeptUserInfo.getJSONObject(i);
|
|
|
+ if (userObj.getString("open_userid").equals(userId)) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+ System.out.println("找到了=="+userObj);
|
|
|
+ msg.data = userObj.toString();
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
String url = GET_USER_INFO_URL.replace("ACCESS_TOKEN", accessToken).replace("USERID", userId);
|
|
|
String result = restTemplate.getForObject(url, String.class);
|
|
|
JSONObject obj = JSONObject.parseObject(result);
|