|
|
|
@ -1,43 +1,92 @@
|
|
|
|
|
package com.dsideal.FengHuang.DingTalk;
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
import com.dingtalk.api.DefaultDingTalkClient;
|
|
|
|
|
import com.dingtalk.api.DingTalkClient;
|
|
|
|
|
import com.dingtalk.api.request.*;
|
|
|
|
|
import com.dingtalk.api.response.*;
|
|
|
|
|
import com.taobao.api.ApiException;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class RolePerson {
|
|
|
|
|
//暂未改修改,因为我们的角色与测试架构的角色存在冲突,不能在人家的环境中实现全部测试功能,需要搭建自己的专用服务器+架构
|
|
|
|
|
|
|
|
|
|
public static void createRoleGroup(String access_token, String group_name) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role_group");
|
|
|
|
|
OapiRoleAddrolegroupRequest req = new OapiRoleAddrolegroupRequest();
|
|
|
|
|
req.setName(group_name);
|
|
|
|
|
OapiRoleAddrolegroupResponse rsp = client.execute(req, access_token);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
//创建成功后,需要将角色组信息记录到自己的表中,钉钉未提供查询有哪些角色组的API
|
|
|
|
|
//groupId --> write to --->database
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取角色列表
|
|
|
|
|
* 功能:获取指定角色组下有哪些角色
|
|
|
|
|
*
|
|
|
|
|
* @param accessToken
|
|
|
|
|
* @param access_token
|
|
|
|
|
* @param group_id
|
|
|
|
|
* @throws ApiException
|
|
|
|
|
*/
|
|
|
|
|
public static void getRoleList(String accessToken) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list");
|
|
|
|
|
OapiRoleListRequest req = new OapiRoleListRequest();
|
|
|
|
|
req.setSize(20L);
|
|
|
|
|
req.setOffset(0L);
|
|
|
|
|
OapiRoleListResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
public static void getRoleList(String access_token, long group_id) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/getrolegroup");
|
|
|
|
|
OapiRoleGetrolegroupRequest req = new OapiRoleGetrolegroupRequest();
|
|
|
|
|
req.setGroupId(group_id);
|
|
|
|
|
OapiRoleGetrolegroupResponse rsp = client.execute(req, access_token);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void createRole(String access_token, String role_name, long group_id) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role");
|
|
|
|
|
OapiRoleAddRoleRequest req = new OapiRoleAddRoleRequest();
|
|
|
|
|
req.setRoleName(role_name);
|
|
|
|
|
req.setGroupId(group_id);
|
|
|
|
|
OapiRoleAddRoleResponse rsp = client.execute(req, access_token);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取指定角色的员工列表
|
|
|
|
|
* 功能:角色下人员列表
|
|
|
|
|
*
|
|
|
|
|
* @param accessToken
|
|
|
|
|
* @param access_token
|
|
|
|
|
* @param role_id
|
|
|
|
|
* @throws ApiException
|
|
|
|
|
*/
|
|
|
|
|
public static void getRolePersonList(String accessToken) throws ApiException {
|
|
|
|
|
public static List<String> getRolePersonList(String access_token, long role_id) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/simplelist");
|
|
|
|
|
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest();
|
|
|
|
|
req.setRoleId(1203141L);
|
|
|
|
|
List<String> res = new ArrayList<>();
|
|
|
|
|
long start = 0;
|
|
|
|
|
while (true) {
|
|
|
|
|
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest();
|
|
|
|
|
req.setRoleId(role_id);
|
|
|
|
|
req.setSize(20L);
|
|
|
|
|
req.setOffset(start);
|
|
|
|
|
OapiRoleSimplelistResponse rsp = client.execute(req, access_token);
|
|
|
|
|
JSONObject jo = JSONObject.parseObject(rsp.getBody());
|
|
|
|
|
System.out.println(jo);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取角色列表
|
|
|
|
|
*
|
|
|
|
|
* @param accessToken
|
|
|
|
|
* @throws ApiException
|
|
|
|
|
*/
|
|
|
|
|
public static void getRoleList(String accessToken) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/list");
|
|
|
|
|
OapiRoleListRequest req = new OapiRoleListRequest();
|
|
|
|
|
req.setSize(20L);
|
|
|
|
|
req.setOffset(0L);
|
|
|
|
|
OapiRoleSimplelistResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
OapiRoleListResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void createRole(String accessToken) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role");
|
|
|
|
|
OapiRoleAddRoleRequest req = new OapiRoleAddRoleRequest();
|
|
|
|
@ -64,20 +113,21 @@ public class RolePerson {
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void addRolePerson(String accessToken) throws ApiException {
|
|
|
|
|
public static void addRolePerson(String accessToken, String role_id, String ids) throws ApiException {
|
|
|
|
|
//一次最多20个人员
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/addrolesforemps");
|
|
|
|
|
OapiRoleAddrolesforempsRequest req = new OapiRoleAddrolesforempsRequest();
|
|
|
|
|
req.setRoleIds("1507113584,1507113589");
|
|
|
|
|
req.setUserIds("user1,user2");
|
|
|
|
|
req.setRoleIds(role_id);
|
|
|
|
|
req.setUserIds(ids);
|
|
|
|
|
OapiRoleAddrolesforempsResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void delRolePerson(String accessToken) throws ApiException {
|
|
|
|
|
public static void delRolePerson(String accessToken, String role_id, String ids) throws ApiException {
|
|
|
|
|
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/removerolesforemps");
|
|
|
|
|
OapiRoleRemoverolesforempsRequest req = new OapiRoleRemoverolesforempsRequest();
|
|
|
|
|
req.setRoleIds("1507113578");
|
|
|
|
|
req.setUserIds("user100,user101");
|
|
|
|
|
req.setRoleIds(role_id);
|
|
|
|
|
req.setUserIds(ids);
|
|
|
|
|
OapiRoleRemoverolesforempsResponse rsp = client.execute(req, accessToken);
|
|
|
|
|
System.out.println(rsp.getBody());
|
|
|
|
|
}
|
|
|
|
|