parent
b5564c592a
commit
6987ac8381
|
@ -1,7 +1,12 @@
|
|||
package com.hzya.frame.dingtalk.service;
|
||||
|
||||
import com.dingtalk.api.request.OapiV2UserListRequest;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 钉钉service
|
||||
|
@ -26,6 +31,14 @@ public interface IDingTalkService {
|
|||
*/
|
||||
OapiV2UserGetResponse.UserGetResponse getUserById(String userId);
|
||||
|
||||
/**
|
||||
* 获取部门用户列表
|
||||
* @param req 请求参数
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @return
|
||||
*/
|
||||
OapiV2UserListResponse.PageResult getUserListByDeptId(OapiV2UserListRequest req, String appKey, String appSecret);
|
||||
/**
|
||||
* 根据部门id获取部门详情
|
||||
* @param deptId 钉钉部门id
|
||||
|
@ -41,4 +54,13 @@ public interface IDingTalkService {
|
|||
* @return
|
||||
*/
|
||||
OapiV2DepartmentGetResponse.DeptGetResponse getDeptById(Long deptId);
|
||||
|
||||
/**
|
||||
* 获取部门列表,此接口只会返回下一级部门信息
|
||||
* @param deptId 部门id,如果不传则查询一级部门
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @return
|
||||
*/
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> getDeptList(Long deptId,String appKey,String appSecret);
|
||||
}
|
||||
|
|
|
@ -4,9 +4,13 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiV2DepartmentGetRequest;
|
||||
import com.dingtalk.api.request.OapiV2DepartmentListsubRequest;
|
||||
import com.dingtalk.api.request.OapiV2UserGetRequest;
|
||||
import com.dingtalk.api.request.OapiV2UserListRequest;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2DepartmentListsubResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserGetResponse;
|
||||
import com.dingtalk.api.response.OapiV2UserListResponse;
|
||||
import com.hzya.frame.dingtalk.service.IDingTalkService;
|
||||
import com.hzya.frame.dingtalk.util.DingTalkAccessToken;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -14,6 +18,8 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description 钉钉service
|
||||
* @Author xiangerlin
|
||||
|
@ -67,6 +73,30 @@ public class DingTalkServiceImpl implements IDingTalkService {
|
|||
return getUserById(userId,dAppKey,dAppSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门用户列表
|
||||
*
|
||||
* @param req 请求参数
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public OapiV2UserListResponse.PageResult getUserListByDeptId(OapiV2UserListRequest req, String appKey, String appSecret) {
|
||||
try {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
|
||||
req.setSize(100L);//每页最大只能查100条
|
||||
req.setOrderField("modify_desc");
|
||||
req.setContainAccessLimit(false);
|
||||
req.setLanguage("zh_CN");
|
||||
OapiV2UserListResponse rsp = client.execute(req, DingTalkAccessToken.getAccessToken(appKey,appSecret));
|
||||
OapiV2UserListResponse.PageResult result = rsp.getResult();
|
||||
return result;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据部门id获取部门详情
|
||||
|
@ -107,4 +137,28 @@ public class DingTalkServiceImpl implements IDingTalkService {
|
|||
return getDeptById(deptId,dAppKey,dAppSecret);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取部门列表,此接口只会返回下一级部门信息
|
||||
* @param deptId 部门id,如果不传则查询一级部门
|
||||
* @param appKey
|
||||
* @param appSecret
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<OapiV2DepartmentListsubResponse.DeptBaseResponse> getDeptList(Long deptId,String appKey,String appSecret) {
|
||||
try {
|
||||
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
|
||||
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
|
||||
req.setDeptId(deptId);
|
||||
req.setLanguage("zh_CN");
|
||||
OapiV2DepartmentListsubResponse rsp = client.execute(req, DingTalkAccessToken.getAccessToken(appKey,appSecret));
|
||||
if (rsp.isSuccess()){
|
||||
List<OapiV2DepartmentListsubResponse.DeptBaseResponse> result = rsp.getResult();
|
||||
return result;
|
||||
}
|
||||
}catch (Exception e){
|
||||
logger.error("获取部门列表接口出错:{}",e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue