|
@@ -470,12 +470,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
|
|
|
//根据关键词查询微信通讯录人员的openid
|
|
|
//keyword不可为空格或空字符串,否则请求参数错误
|
|
|
- private HashMap<String, Object> getOpenId(String corpId,String keyword,String cursor) {
|
|
|
- HashMap<String, Object> result = new HashMap<>();
|
|
|
- Object[] user = null;
|
|
|
- String nextCursor = "";
|
|
|
- result.put("user",user);
|
|
|
- result.put("nextCursor",nextCursor);
|
|
|
+ private HashMap<String, List> getOpenId(String corpId,String keyword,String cursor) {
|
|
|
+ HashMap<String, List> result = new HashMap<>();
|
|
|
+ List<Object> user = new ArrayList<>();
|
|
|
+ String itemCursor = "";
|
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/service/contact/search?provider_access_token=ACCESS_TOKEN";
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
@@ -503,16 +501,17 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
if (!queryResult.isEmpty()){
|
|
|
JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
|
if (jsonArray!=null){
|
|
|
- user = jsonArray.toArray();
|
|
|
+ Object[] objects = jsonArray.toArray();
|
|
|
+ for (Object object : objects) {
|
|
|
+ user.add(object);
|
|
|
+ }
|
|
|
}
|
|
|
}else{
|
|
|
System.err.println("==================通讯录查询请求无userid列表===================");
|
|
|
}
|
|
|
- JSONObject isLast = respJson.getJSONObject("is_last");
|
|
|
- if (isLast!=null){
|
|
|
- if (!respJson.getBoolean("is_last")){
|
|
|
- nextCursor = respJson.getString("next_cursor");
|
|
|
- }
|
|
|
+ Boolean is_last = respJson.getBoolean("is_last");
|
|
|
+ if (!is_last){
|
|
|
+ itemCursor = respJson.getString("next_cursor");
|
|
|
}
|
|
|
}else {
|
|
|
System.err.println("===================通讯录查询请求失败=================");
|
|
@@ -521,6 +520,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
}else {
|
|
|
System.out.println("=============token查询失败=================");
|
|
|
}
|
|
|
+ List<Object> nextCursor = new ArrayList<>();
|
|
|
+ nextCursor.add(itemCursor);
|
|
|
+ result.put("nextCursor",nextCursor);
|
|
|
+ result.put("user",user);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -536,12 +539,12 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
//当企业开启了微信通讯录的情况下
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1 && departmentId == -1){
|
|
|
System.out.println("====================开始查询通讯录名单======================");
|
|
|
- HashMap<String, Object> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
- Object users = result.get("user");
|
|
|
- if (users!=null){
|
|
|
+ HashMap<String, List> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
+ List users = result.get("user");
|
|
|
+ if (users.size()!=0){
|
|
|
List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
|
data.put("records",realUser);
|
|
|
- data.put("nextCursor",result.get("nextCursor"));
|
|
|
+ data.put("nextCursor",result.get("nextCursor").get(0));
|
|
|
return httpRespMsg;
|
|
|
}else {
|
|
|
System.err.println("======================user列表没有查询到数据===========================");
|
|
@@ -2148,42 +2151,35 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|
|
String token = request.getHeader("TOKEN");
|
|
|
User user = userMapper.selectById(token);
|
|
|
String nextCursor = "";
|
|
|
- QueryWrapper<User> wrapper = new QueryWrapper<User>().select("id, name, phone, job_number, department_id").eq("company_id", user.getCompanyId()).eq("is_active", 1);
|
|
|
- if (departmentId != null) {
|
|
|
- //获取全部子部门
|
|
|
- List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
|
|
|
- List<Integer> deptIds = departmentService.getDeptIncludeSubDeptIds(departmentId, allDeptList);
|
|
|
- wrapper.in("department_id", deptIds);
|
|
|
- }
|
|
|
- List<User> userList = userMapper.selectList(wrapper);
|
|
|
//企业微信通讯录搜索功能
|
|
|
Integer WXCompanyId = user.getCompanyId();
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", WXCompanyId));
|
|
|
//当企业开启了微信通讯录的情况下
|
|
|
if (org.apache.commons.lang3.StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1){
|
|
|
- HashMap<String, Object> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
+ HashMap<String, List> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
HashMap<String, Object> msgResult = new HashMap<>();
|
|
|
- List<User> retUser = new ArrayList<>();
|
|
|
- nextCursor = result.get("nextCursor").toString();
|
|
|
- Object users = result.get("user");
|
|
|
- msgResult.put("retUser",retUser);
|
|
|
+ nextCursor = result.get("nextCursor").get(0).toString();
|
|
|
+ List users = result.get("user");
|
|
|
msgResult.put("nextCursor",nextCursor);
|
|
|
- msg.data = result;
|
|
|
+ msg.data = msgResult;
|
|
|
if (users!=null){
|
|
|
List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
|
- for (User item : userList) {
|
|
|
- for (User realItem : realUser) {
|
|
|
- if (item.getId().equals(realItem.getId())){
|
|
|
- retUser.add(realItem);
|
|
|
- continue;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ msgResult.put("retUser",realUser);
|
|
|
return msg;
|
|
|
}else {
|
|
|
+ ArrayList<User> nullUser = new ArrayList<>();
|
|
|
+ msgResult.put("retUser",nullUser);
|
|
|
return msg;
|
|
|
}
|
|
|
}else {
|
|
|
+ QueryWrapper<User> wrapper = new QueryWrapper<User>().select("id, name, phone, job_number, department_id").eq("company_id", user.getCompanyId()).eq("is_active", 1);
|
|
|
+ if (departmentId != null) {
|
|
|
+ //获取全部子部门
|
|
|
+ List<Department> allDeptList = departmentMapper.selectList(new QueryWrapper<Department>().eq("company_id", user.getCompanyId()));
|
|
|
+ List<Integer> deptIds = departmentService.getDeptIncludeSubDeptIds(departmentId, allDeptList);
|
|
|
+ wrapper.in("department_id", deptIds);
|
|
|
+ }
|
|
|
+ List<User> userList = userMapper.selectList(wrapper);
|
|
|
msg.data = userList;
|
|
|
return msg;
|
|
|
}
|