|
@@ -11,6 +11,7 @@ import com.management.platform.entity.vo.SysRichFunction;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.DepartmentService;
|
|
|
import com.management.platform.service.ExcelExportService;
|
|
|
+import com.management.platform.service.WxCorpInfoService;
|
|
|
import com.management.platform.util.ExcelUtil;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.ListUtil;
|
|
@@ -72,6 +73,8 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
private WxCorpInfoMapper wxCorpInfoMapper;
|
|
|
@Resource
|
|
|
private ExcelExportService excelExportService;
|
|
|
+ @Resource
|
|
|
+ private WxCorpInfoService wxCorpInfoService;
|
|
|
|
|
|
@Value("${corpId}")
|
|
|
private String corpId;
|
|
@@ -799,6 +802,7 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
//合计
|
|
|
List<String> sumRow = new ArrayList<String>();
|
|
|
//sumRow.add("合计");
|
|
|
+ //sumRow.add("合计");
|
|
|
sumRow.add(MessageUtils.message("entry.total"));
|
|
|
sumRow.add("");
|
|
|
if(functionTimeList.size()>0){
|
|
@@ -825,96 +829,98 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
return httpRespMsg;
|
|
|
}
|
|
|
|
|
|
- //获取provider_access_token
|
|
|
- private String getProviderAccessToken() {
|
|
|
- if (UserServiceImpl.provider_access_token == null || UserServiceImpl.providerTokenExpireTime < System.currentTimeMillis()) {
|
|
|
- //失效了,需要重新获取
|
|
|
- String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
- headers.setContentType(type);
|
|
|
- headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
- JSONObject reqParam = new JSONObject();
|
|
|
- reqParam.put("corpid", corpId);
|
|
|
- reqParam.put("provider_secret", providerSecret);
|
|
|
- HttpEntity<JSONObject> Entity = new HttpEntity<>(reqParam, headers);
|
|
|
- ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, Entity, String.class);
|
|
|
- if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
- String resp = responseEntity.getBody();
|
|
|
- JSONObject obj = JSONObject.parseObject(resp);
|
|
|
- if (obj.getIntValue("errcode") == 0) {
|
|
|
- UserServiceImpl.provider_access_token = obj.getString("provider_access_token");
|
|
|
- UserServiceImpl.providerTokenExpireTime = System.currentTimeMillis() + obj.getIntValue("expires_in")*1000;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return UserServiceImpl.provider_access_token;
|
|
|
- }
|
|
|
+// //获取provider_access_token
|
|
|
+// private String getProviderAccessToken() {
|
|
|
+// if (UserServiceImpl.provider_access_token == null || UserServiceImpl.providerTokenExpireTime < System.currentTimeMillis()) {
|
|
|
+// //失效了,需要重新获取
|
|
|
+// String url = "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token";
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
+// RestTemplate restTemplate = new RestTemplate();
|
|
|
+// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+// headers.setContentType(type);
|
|
|
+// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+// JSONObject reqParam = new JSONObject();
|
|
|
+// reqParam.put("corpid", corpId);
|
|
|
+// reqParam.put("provider_secret", providerSecret);
|
|
|
+// HttpEntity<JSONObject> Entity = new HttpEntity<>(reqParam, headers);
|
|
|
+// ResponseEntity<String> responseEntity = restTemplate.postForEntity(url, Entity, String.class);
|
|
|
+// if (responseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+// String resp = responseEntity.getBody();
|
|
|
+// JSONObject obj = JSONObject.parseObject(resp);
|
|
|
+// if (obj.getIntValue("errcode") == 0) {
|
|
|
+// UserServiceImpl.provider_access_token = obj.getString("provider_access_token");
|
|
|
+// UserServiceImpl.providerTokenExpireTime = System.currentTimeMillis() + obj.getIntValue("expires_in")*1000;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return UserServiceImpl.provider_access_token;
|
|
|
+// }
|
|
|
|
|
|
//根据关键词查询微信通讯录人员的openid以及部门
|
|
|
//keyword不可为空格或空字符串,否则请求参数错误
|
|
|
- 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();
|
|
|
- MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
- headers.setContentType(type);
|
|
|
- headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
- String providerToken = getProviderAccessToken();
|
|
|
- if (providerToken!=null){
|
|
|
- //搜索通讯录名单
|
|
|
- url = url.replace("ACCESS_TOKEN", providerToken);
|
|
|
- JSONObject requestMap = new JSONObject();
|
|
|
- requestMap.put("auth_corpid", corpId);
|
|
|
- requestMap.put("query_word", keyword);
|
|
|
- requestMap.put("query_type", 0);
|
|
|
- requestMap.put("query_range", 1);
|
|
|
- requestMap.put("limit", 20);
|
|
|
- requestMap.put("cursor", cursor);
|
|
|
- HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
- ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
- if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
- String resp = ResponseEntity.getBody();
|
|
|
- JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
- if (respJson.getInteger("errcode")==0){
|
|
|
- JSONObject queryResult = respJson.getJSONObject("query_result");
|
|
|
- if (!queryResult.isEmpty()){
|
|
|
- JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
|
- if (jsonArray!=null){
|
|
|
- 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");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- List<Object> nextCursor = new ArrayList<>();
|
|
|
- nextCursor.add(itemCursor);
|
|
|
- result.put("nextCursor",nextCursor);
|
|
|
- result.put("user",user);
|
|
|
- return result;
|
|
|
- }
|
|
|
+// 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();
|
|
|
+// MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+// headers.setContentType(type);
|
|
|
+// headers.add("Accept", MediaType.APPLICATION_JSON.toString());
|
|
|
+// String providerToken = getProviderAccessToken();
|
|
|
+// if (providerToken!=null){
|
|
|
+// //搜索通讯录名单
|
|
|
+// url = url.replace("ACCESS_TOKEN", providerToken);
|
|
|
+// JSONObject requestMap = new JSONObject();
|
|
|
+// requestMap.put("auth_corpid", corpId);
|
|
|
+// requestMap.put("query_word", keyword);
|
|
|
+// requestMap.put("query_type", 0);
|
|
|
+// requestMap.put("query_range", 1);
|
|
|
+// requestMap.put("limit", 20);
|
|
|
+// requestMap.put("cursor", cursor);
|
|
|
+// HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
+// ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+// if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+// String resp = ResponseEntity.getBody();
|
|
|
+// JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
+// if (respJson.getInteger("errcode")==0){
|
|
|
+// JSONObject queryResult = respJson.getJSONObject("query_result");
|
|
|
+// if (!queryResult.isEmpty()){
|
|
|
+// JSONArray jsonArray = queryResult.getJSONObject("user").getJSONArray("open_userid");
|
|
|
+// if (jsonArray!=null){
|
|
|
+// 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");
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+// List<Object> nextCursor = new ArrayList<>();
|
|
|
+// nextCursor.add(itemCursor);
|
|
|
+// result.put("nextCursor",nextCursor);
|
|
|
+// result.put("user",user);
|
|
|
+// return result;
|
|
|
+// }
|
|
|
|
|
|
@Override
|
|
|
- public HttpRespMsg listAllMemb(HttpServletRequest request,String keyword,String cursor) {
|
|
|
+ public HttpRespMsg listAllMemb(HttpServletRequest request,String keyword,String cursor) throws Exception {
|
|
|
Integer companyId = userMapper.selectById(request.getHeader("TOKEN")).getCompanyId();
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
List<HashMap> userMapList = new ArrayList<>();
|
|
|
+ List<HashMap> deptMapList = new ArrayList<>();
|
|
|
//通讯录查询人员
|
|
|
WxCorpInfo wxCorpInfo = wxCorpInfoMapper.selectOne(new QueryWrapper<WxCorpInfo>().eq("company_id", companyId));
|
|
|
if (StringUtils.isNotBlank(keyword) && wxCorpInfo!=null && wxCorpInfo.getSaasSyncContact()==1){
|
|
|
- HashMap<String, List> result = getOpenId(wxCorpInfo.getCorpid(), keyword, cursor);
|
|
|
+ HashMap<String, List> result = wxCorpInfoService.getOpenId(wxCorpInfo.getCorpid(), keyword, cursor,0,20);
|
|
|
List users = result.get("user");
|
|
|
+ List depts = result.get("dept");
|
|
|
if (users.size()!=0){
|
|
|
List<User> realUser = userMapper.selectList(new QueryWrapper<User>().in("corpwx_userid", users));
|
|
|
if (realUser.size()!=0){
|
|
@@ -945,6 +951,26 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
return msg;
|
|
|
}
|
|
|
}
|
|
|
+ if (depts.size()!=0){
|
|
|
+ List<Department> departmentList = departmentMapper.selectList(new QueryWrapper<Department>().in("corpwx_deptid", depts));
|
|
|
+ List<User> userList = userMapper.selectList(new QueryWrapper<User>().eq("company_id", companyId));
|
|
|
+ List<DepartmentOtherManager> departmentOtherManagerList = departmentOtherManagerMapper.selectList(new QueryWrapper<DepartmentOtherManager>().eq("company_id", companyId));
|
|
|
+ //结果列表
|
|
|
+ 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);
|
|
|
+ });
|
|
|
+ //处理部门下人员列表
|
|
|
+ List<DepartmentVO> userListWithDept = getUserListWithDept(userList, list);
|
|
|
+ HashMap<String, Object> data = new HashMap<>();
|
|
|
+ data.put("data",userListWithDept);
|
|
|
+ data.put("nextCursor","");
|
|
|
+ msg.data = data;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
ArrayList<Object> emptyList = new ArrayList<>();
|
|
|
msg.data = emptyList;
|
|
|
return msg;
|
|
@@ -972,6 +998,25 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public List<DepartmentVO> getUserListWithDept(List<User> userList,List<DepartmentVO> departmentVOList ){
|
|
|
+ if(departmentVOList!=null&&departmentVOList.size()>0){
|
|
|
+ for (DepartmentVO departmentVO : departmentVOList) {
|
|
|
+ List<HashMap> userMapList = new ArrayList<>();
|
|
|
+ List<User> collect = userList.stream().filter(ul -> ul.getDepartmentId() != null && ul.getDepartmentId().equals(departmentVO.getId())).collect(Collectors.toList());
|
|
|
+ for (User u : collect) {
|
|
|
+ HashMap<String, Object> user = new HashMap<String, Object>();
|
|
|
+ user.put("id", u.getId());
|
|
|
+ user.put("name", u.getName());
|
|
|
+ user.put("departmentId", u.getDepartmentId());
|
|
|
+ userMapList.add(user);
|
|
|
+ }
|
|
|
+ departmentVO.setUserList(userMapList);
|
|
|
+ getUserListWithDept(userList,departmentVO.getChildren());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return departmentVOList;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public HttpRespMsg listMyMembs(HttpServletRequest request) {
|
|
|
User currentUser = userMapper.selectById(request.getHeader("TOKEN"));
|