Compare commits

...

4 Commits

Author SHA1 Message Date
黄海 bc5c1c50c3 'commit'
2 years ago
黄海 8a0d8ab74d 变更
2 years ago
黄海 1e5bf57d60 变更
2 years ago
黄海 5fd816963c 变更
2 years ago

@ -13,18 +13,7 @@
</properties>
<repositories>
<repository>
<id>ali-maven</id>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
</repository>
</repositories>
<dependencies>

@ -1,11 +1,10 @@
package UnitTest;
import com.alibaba.druid.filter.stat.StatFilter;
import com.dsideal.FengHuang.DingTalk.Common;
import com.dsideal.FengHuang.DingTalk.Model;
import com.dsideal.FengHuang.DingTalk.OrgPerson;
import com.dsideal.FengHuang.DingTalk.RolePerson;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.dsideal.FengHuang.DingTalk.Common;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.Record;
@ -13,6 +12,8 @@ import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
import com.jfinal.plugin.druid.DruidPlugin;
import com.jfinal.plugin.redis.RedisPlugin;
import java.util.List;
public class TestDingTalk {
public static DruidPlugin createDruidPlugin(String url, String username, String password, String driverClass) {
DruidPlugin druidPlugin = new DruidPlugin(url, username, password, driverClass);
@ -68,10 +69,10 @@ public class TestDingTalk {
Record rOrg = Model.getOrgByOrgName(orgName);
//同步组织机构
OrgPerson.syncOrg(accessToken, rOrg);
//OrgPerson.syncOrg(accessToken, rOrg);
//从数据库中获取最新的部门列表(已与钉钉匹配完毕)
Model.fillDeptListByDataBase(rOrg);
//Model.fillDeptListByDataBase(rOrg);
//删除所有的组织机构
//OrgPerson.delAllDept(accessToken);
@ -82,23 +83,32 @@ public class TestDingTalk {
//删除单位下所有人员(开发测试时使用)
// OrgPerson.delBureauPerson(accessToken, rOrg);
//创建角色组
//创建角色组【执行一次即可】
//RolePerson.createRoleGroup(accessToken, "义务教育阶段角色组"); ---> 3779920123
long groupId = 3779920123L;
//获取指定角色组下有哪些角色
RolePerson.getRoleList(accessToken, groupId);
// RolePerson.createRole(accessToken, "校长", groupId);
// RolePerson.createRole(accessToken, "副校长", groupId);
// RolePerson.createRole(accessToken, "教导主任", groupId);
// RolePerson.createRole(accessToken, "后勤主任", groupId);
// RolePerson.createRole(accessToken, "班主任", groupId);
// RolePerson.createRole(accessToken, "普通教师", groupId);
//
// RolePerson.getRoleList(accessToken, groupId);
//System.out.println(RolePerson.getRolePersonList(accessToken,role_id));
//List<Record> list = RolePerson.getRoleList(accessToken, groupId);
//System.out.println(list);
//删除指定角色组下的角色
//RolePerson.delGroupRole(accessToken,groupId);
//同步角色
//RolePerson.syncRole(accessToken, groupId);
//获取钉钉侧指定角色下人员信息
RolePerson.getRolePersonList(accessToken, 3780868223L, 0);
for (int i = 0; i < RolePerson.rolePersonList.size(); i++) {
System.out.println(RolePerson.rolePersonList.get(i));
}
//获取云平台侧指定角色下人员信息
List<Record> list2 = Model.getRolePersonReleation();
//尝试同步两个人员信息
CommonUtil.Print("恭喜,所有操作成功完成!");
}

@ -28,7 +28,6 @@ public class Model {
}
}
public static List<Record> getDeptPerson(int bureau_id) {
String sql = "select t1.person_id,t1.person_name,t2.dingtalk_dept_id,t1.tel from t_base_person as t1 " +
"inner join t_base_organization as t2 on t1.org_id=t2.org_id " +
@ -52,4 +51,21 @@ public class Model {
String sql = "select org_id,org_name,sort_id,dingtalk_dept_id from t_base_organization where org_name = ?";
return Db.findFirst(sql, org_name);
}
public static List<Record> getRoleList() {
String sql = "select * from t_im_role";
return Db.find(sql);
}
public static void writeDingTalkRoleId(int role_id, long dt_role_id) {
String sql = "update t_im_role set dingtalk_role_id=? where role_id=?";
Db.update(sql, dt_role_id, role_id);
}
// 需要同步哪些人员角色信息
public static List<Record> getRolePersonReleation() {
String sql = "select t1.person_id,t1.role_id,t2.dingtalk_role_id from t_sys_person_role as t1 inner join t_im_role as t2 on t1.role_id=t2.role_id where t1.bureau_id=?";
List<Record> list=Db.find(sql);
return list;
}
}

@ -15,7 +15,6 @@ import com.dingtalk.api.response.*;
import com.dsideal.FengHuang.Util.CommonUtil;
import com.jfinal.kit.Kv;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.taobao.api.ApiException;
@ -90,7 +89,6 @@ public class OrgPerson {
*/
public static List<Kv> deptList = new ArrayList();
public static void getDeptList(String access_token, long dept_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();

@ -1,31 +1,46 @@
package com.dsideal.FengHuang.DingTalk;
import com.alibaba.fastjson.JSONArray;
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.dsideal.FengHuang.Util.CommonUtil;
import com.jfinal.plugin.activerecord.Record;
import com.taobao.api.ApiException;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class RolePerson {
//暂未改修改,因为我们的角色与测试架构的角色存在冲突,不能在人家的环境中实现全部测试功能,需要搭建自己的专用服务器+架构
/*
--
select * from t_sys_role;
--
select * from t_sys_person_role where bureau_id=? and role_id in ();
DROP TABLE IF EXISTS `t_im_role`;
CREATE TABLE `t_im_role` (
`role_id` int NOT NULL COMMENT 'ID',
`role_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '',
`dingtalk_role_id` bigint NULL DEFAULT NULL COMMENT 'ID',
PRIMARY KEY (`role_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Compact;
-- ----------------------------
-- Records of t_im_role
-- ----------------------------
INSERT INTO `t_im_role` VALUES (174, '', NULL);
INSERT INTO `t_im_role` VALUES (323, '', NULL);
insert into `t_im_role` VALUES (4,'',NULL);
TODO
//让产品经理想好加入到此表中表示需要与IM钉钉系统对接的角色
*/
//创建用户组,这个概念似乎不重要,可以手动创建即可
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
}
/**
@ -35,23 +50,105 @@ public class RolePerson {
* @param group_id
* @throws ApiException
*/
public static void getRoleList(String access_token, long group_id) throws ApiException {
public static List<Record> 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());
JSONObject jo = JSONObject.parseObject(rsp.getBody());
JSONArray ja = jo.getJSONObject("role_group").getJSONArray("roles");
List<Record> list = new ArrayList();
for (int i = 0; i < ja.size(); i++) {
Record record = new Record();
record.set("role_id", ((JSONObject) ja.get(i)).getLong("role_id"));
record.set("role_name", ((JSONObject) ja.get(i)).getString("role_name"));
list.add(record);
}
return list;
}
public static void createRole(String access_token, String role_name, long group_id) throws ApiException {
public static long 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);
JSONObject jo = JSONObject.parseObject(rsp.getBody());
return jo.getLong("roleId");
}
public static void delRole(String access_token, long role_id) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/deleterole");
OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
req.setRoleId(role_id);
OapiRoleDeleteroleResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
public static void updateRole(String access_token, long role_id, String role_name) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/update_role");
OapiRoleUpdateRoleRequest req = new OapiRoleUpdateRoleRequest();
req.setRoleId(role_id);
req.setRoleName(role_name);
OapiRoleUpdateRoleResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
public static void clearGroupRole(String access_token, long group_id) throws ApiException {
List<Record> list = getRoleList(access_token, group_id);
for (int i = 0; i < list.size(); i++) {
delRole(access_token, list.get(i).getLong("role_id"));
}
}
/**
*
*
* @param access_token
* @param group_id
* @throws ApiException
*/
public static void syncRole(String access_token, long group_id) throws ApiException {
//1、钉钉侧有哪些角色
List<Record> listA = getRoleList(access_token, group_id);
//2、数据库有哪些角色
List<Record> listB = Model.getRoleList();
boolean flag;
//3、在A不在B删除之
for (int i = 0; i < listA.size(); i++) {
flag = false;
for (int j = 0; j < listB.size(); j++) {
if (listB.get(j).get("dingtalk_role_id") != null && listA.get(i).getLong("role_id") == listB.get(j).getLong("dingtalk_role_id")) {
flag = true;
break;
}
}
if (!flag) {
delRole(access_token, listA.get(i).getLong("role_id"));
CommonUtil.Print("成功删除钉钉侧角色:" + listA.get(i).getStr("role_name"));
}
}
//4、在B不在A增加之
for (int i = 0; i < listB.size(); i++) {
flag = false;
for (int j = 0; j < listA.size(); j++) {
if (listB.get(j).get("dingtalk_role_id") != null && listA.get(i).getLong("role_id") == listB.get(j).getLong("dingtalk_role_id")) {
flag = true;
break;
}
}
if (!flag) {
long dt_role_id = createRole(access_token, listB.get(i).getStr("role_name"), group_id);
//回写
Model.writeDingTalkRoleId(listB.get(i).getInt("role_id"), dt_role_id);
CommonUtil.Print("成功创建角色:" + listB.get(i).getStr("role_name"));
}
}
//5、在A也在B看看是不是角色名称需要修改
//TODO,因为角色名称不般不随意变化不写这块代码也是OK的
}
/**
*
*
@ -59,21 +156,36 @@ public class RolePerson {
* @param role_id
* @throws ApiException
*/
public static List<String> getRolePersonList(String access_token, long role_id) throws ApiException {
public static List<Record> rolePersonList = new ArrayList<>();
public static long SZ = 2l;
public static void getRolePersonList(String access_token, long role_id, long start) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/simplelist");
List<String> res = new ArrayList<>();
long start = 0;
while (true) {
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest();
req.setRoleId(role_id);
req.setSize(20L);
req.setSize(SZ);
req.setOffset(start);
OapiRoleSimplelistResponse rsp = client.execute(req, access_token);
JSONObject jo = JSONObject.parseObject(rsp.getBody());
System.out.println(jo);
break;
JSONArray ja = jo.getJSONObject("result").getJSONArray("list");
for (int i = 0; i < ja.size(); i++) {
Record record = new Record();
String name = ((JSONObject) ja.get(i)).getString("name");
String userid = ((JSONObject) ja.get(i)).getString("userid");
record.set("person_name", name);
record.set("person_id", userid);
rolePersonList.add(record);
}
if (jo.getJSONObject("result").getBoolean("hasMore")) {
getRolePersonList(access_token, role_id, start + SZ);
}
return res;
}
public static void syncRolePersonReleation() {
//getRolePersonList();
//Model.getRolePersonReleation();
}
/**
@ -92,15 +204,6 @@ public class RolePerson {
}
public static void createRole(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/add_role");
OapiRoleAddRoleRequest req = new OapiRoleAddRoleRequest();
req.setRoleName("测试1");
req.setGroupId(1507113595L);
OapiRoleAddRoleResponse rsp = client.execute(req, accessToken);
System.out.println(rsp.getBody());
}
public static void updateRole(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/role/update_role");
OapiRoleUpdateRoleRequest req = new OapiRoleUpdateRoleRequest();
@ -110,13 +213,6 @@ public class RolePerson {
System.out.println(rsp.getBody());
}
public static void delRole(String accessToken) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/role/deleterole");
OapiRoleDeleteroleRequest req = new OapiRoleDeleteroleRequest();
req.setRoleId(1581321999L);
OapiRoleDeleteroleResponse rsp = client.execute(req, accessToken);
System.out.println(rsp.getBody());
}
public static void addRolePerson(String accessToken, String role_id, String ids) throws ApiException {
//一次最多20个人员

Loading…
Cancel
Save