|
@@ -368,6 +368,33 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
return httpRespMsg;
|
|
return httpRespMsg;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //获取某个人所在的部门列表
|
|
|
|
+ @Override
|
|
|
|
+ public HttpRespMsg getDepartmentListById(User user) {
|
|
|
|
+ HttpRespMsg httpRespMsg = new HttpRespMsg();
|
|
|
|
+ try {
|
|
|
|
+ //筛选公司下所有的部门
|
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>()
|
|
|
|
+ .eq("department_id", user.getDepartmentId()));
|
|
|
|
+ List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("department_id", user.getDepartmentId()));
|
|
|
|
+ //结果列表
|
|
|
|
+ List<DepartmentVO> list = new ArrayList<>();
|
|
|
|
+ List<Department> rootDepartments = departmentList.stream().filter(dept -> dept.getSuperiorId() == null).collect(Collectors.toList());
|
|
|
|
+ rootDepartments.forEach(root->{
|
|
|
|
+ DepartmentVO rootDeptVO = formatDepartmentToVO(root, departmentOtherManagerList);
|
|
|
|
+ list.add(rootDeptVO);
|
|
|
|
+ fillSubDepartmentList(departmentList, rootDeptVO, departmentOtherManagerList);
|
|
|
|
+ });
|
|
|
|
+ //返回数据
|
|
|
|
+ httpRespMsg.data = list;
|
|
|
|
+ } catch (NullPointerException e) {
|
|
|
|
+ //httpRespMsg.setError("验证失败");
|
|
|
|
+ httpRespMsg.setError(MessageUtils.message("Company.validationError"));
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+ return httpRespMsg;
|
|
|
|
+ }
|
|
|
|
+
|
|
//将部门PO转化为部门VO
|
|
//将部门PO转化为部门VO
|
|
private DepartmentVO formatDepartmentToVO(Department department, List<DepartmentOtherManager> departmentOtherManagerList) {
|
|
private DepartmentVO formatDepartmentToVO(Department department, List<DepartmentOtherManager> departmentOtherManagerList) {
|
|
List<String> collect = departmentOtherManagerList.stream().filter(dm -> dm.getDepartmentId().equals(department.getDepartmentId())).map(vo -> vo.getOtherManagerId()).collect(Collectors.toList());
|
|
List<String> collect = departmentOtherManagerList.stream().filter(dm -> dm.getDepartmentId().equals(department.getDepartmentId())).map(vo -> vo.getOtherManagerId()).collect(Collectors.toList());
|
|
@@ -800,8 +827,10 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
|
|
|
//根据关键词查询微信通讯录人员的openid以及部门
|
|
//根据关键词查询微信通讯录人员的openid以及部门
|
|
//keyword不可为空格或空字符串,否则请求参数错误
|
|
//keyword不可为空格或空字符串,否则请求参数错误
|
|
- private Object[] getOpenId(String corpId,String keyword) {
|
|
|
|
- Object[] user = null;
|
|
|
|
|
|
+ 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";
|
|
String url = "https://qyapi.weixin.qq.com/cgi-bin/service/contact/search?provider_access_token=ACCESS_TOKEN";
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
@@ -817,8 +846,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
requestMap.put("query_word", keyword);
|
|
requestMap.put("query_word", keyword);
|
|
requestMap.put("query_type", 0);
|
|
requestMap.put("query_type", 0);
|
|
requestMap.put("query_range", 1);
|
|
requestMap.put("query_range", 1);
|
|
- requestMap.put("limit", 200);
|
|
|
|
- //requestMap.put("cursor", pageSize);
|
|
|
|
|
|
+ requestMap.put("limit", 20);
|
|
|
|
+ requestMap.put("cursor", cursor);
|
|
HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
@@ -829,17 +858,28 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
if (!queryResult.isEmpty()){
|
|
if (!queryResult.isEmpty()){
|
|
JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
if (jsonArray!=null){
|
|
if (jsonArray!=null){
|
|
- user = jsonArray.toArray();
|
|
|
|
|
|
+ Object[] objects = jsonArray.toArray();
|
|
|
|
+ for (Object object : objects) {
|
|
|
|
+ user.add(object);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ Boolean is_last = respJson.getBoolean("is_last");
|
|
|
|
+ if (!is_last){
|
|
|
|
+ itemCursor = respJson.getString("next_cursor");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return user;
|
|
|
|
|
|
+ List<Object> nextCursor = new ArrayList<>();
|
|
|
|
+ nextCursor.add(itemCursor);
|
|
|
|
+ result.put("nextCursor",nextCursor);
|
|
|
|
+ result.put("user",user);
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public HttpRespMsg listAllMemb(HttpServletRequest request,String keyword) {
|
|
|
|
|
|
+ public HttpRespMsg listAllMemb(HttpServletRequest request,String keyword,String cursor) {
|
|
Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
List<HashMap> userMapList = new ArrayList<>();
|
|
List<HashMap> userMapList = new ArrayList<>();
|
|
@@ -854,21 +894,17 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
//通讯录查询人员
|
|
//通讯录查询人员
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
if (StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1){
|
|
if (StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1){
|
|
- Object[] users = getOpenId(wxCorpInfo.getCorpid(), keyword);
|
|
|
|
|
|
+ HashMap<String, List> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
|
+ List users = result.get("user");
|
|
if (users!=null){
|
|
if (users!=null){
|
|
List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
List<DepartmentVO> temp = new ArrayList<>();
|
|
List<DepartmentVO> temp = new ArrayList<>();
|
|
- //重新封装list集合,把没有查询人员的部门去掉
|
|
|
|
|
|
+ //重新封装list集合
|
|
if (realUser.size()!=0){
|
|
if (realUser.size()!=0){
|
|
- for (DepartmentVO departmentVO : list) {
|
|
|
|
- for (User user : realUser) {
|
|
|
|
- if (departmentVO.getId().equals(user.getDepartmentId())){
|
|
|
|
- temp.add(departmentVO);
|
|
|
|
- continue;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ for (User user : realUser) {
|
|
|
|
+
|
|
|
|
+ temp.add(unAssignedDept);
|
|
}
|
|
}
|
|
- list = temp;
|
|
|
|
for (User u : realUser) {
|
|
for (User u : realUser) {
|
|
HashMap<String, Object> user = new HashMap<String, Object>();
|
|
HashMap<String, Object> user = new HashMap<String, Object>();
|
|
user.put("id", u.getId());
|
|
user.put("id", u.getId());
|
|
@@ -876,9 +912,12 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
user.put("departmentId", u.getDepartmentId());
|
|
user.put("departmentId", u.getDepartmentId());
|
|
userMapList.add(user);
|
|
userMapList.add(user);
|
|
fillDeptUser(list, userMapList);
|
|
fillDeptUser(list, userMapList);
|
|
- msg.data = list;
|
|
|
|
- return msg;
|
|
|
|
}
|
|
}
|
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
|
+ data.put("data",list);
|
|
|
|
+ data.put("nextCursor","");
|
|
|
|
+ msg.data = data;
|
|
|
|
+ return msg;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
ArrayList<Object> emptyList = new ArrayList<>();
|
|
ArrayList<Object> emptyList = new ArrayList<>();
|