@ -1,7 +1,5 @@
package com.dsideal.FengHuang.DingTalk ;
import cn.binarywang.tools.generator.ChineseMobileNumberGenerator ;
import cn.hutool.core.util.PhoneUtil ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.dingtalk.api.DefaultDingTalkClient ;
@ -9,8 +7,6 @@ import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.* ;
import com.dingtalk.api.response.* ;
import com.dsideal.FengHuang.Util.CommonUtil ;
import com.jfinal.kit.StrKit ;
import com.jfinal.plugin.activerecord.Db ;
import com.jfinal.plugin.activerecord.Record ;
import com.taobao.api.ApiException ;
@ -36,14 +32,6 @@ public class RolePerson {
insert into ` t_im_role ` VALUES ( 4 , ' 普 通 教 师 ' , NULL ) ;
TODO
//让产品经理想好, 加入到此表中, 表示需要与IM钉钉系统对接的角色
- - 需 要 同 步 哪 些 人 员 角 色 信 息
select * from t_sys_person_role where bureau_id = ? and role_id in ( select role_id from t_im_role ) ;
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 = 2002543
* /
//创建用户组,这个概念似乎不重要,可以手动创建即可
@ -53,8 +41,6 @@ public class RolePerson {
req . setName ( group_name ) ;
OapiRoleAddrolegroupResponse rsp = client . execute ( req , access_token ) ;
System . out . println ( rsp . getBody ( ) ) ;
//创建成功后, 需要将角色组信息记录到自己的表中, 钉钉未提供查询有哪些角色组的API
//groupId --> write to --->database
}
/ * *
@ -108,13 +94,20 @@ public class RolePerson {
System . out . println ( rsp . getBody ( ) ) ;
}
public static void del GroupRole( String access_token , long group_id ) throws ApiException {
public static void clear GroupRole( 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 ) ;
@ -149,10 +142,11 @@ public class RolePerson {
//回写
Model . writeDingTalkRoleId ( listB . get ( i ) . getInt ( "role_id" ) , dt_role_id ) ;
CommonUtil . Print ( "成功创建角色:" + listB . get ( i ) . getStr ( "role_name" ) ) ;
CommonUtil . Print ( "成功创建角色:" + listB . get ( i ) . getStr ( "role_name" ) ) ;
}
}
//5、在A也在B, 看看是不是角色名称需要修改
//TODO,因为角色名称不般不随意变化, 不写这块代码也是OK的
}
/ * *
@ -162,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 . setOffset ( start ) ;
OapiRoleSimplelistResponse rsp = client . execute ( req , access_token ) ;
JSONObject jo = JSONObject . parseObject ( rsp . getBody ( ) ) ;
System . out . println ( jo ) ;
break ;
OapiRoleSimplelistRequest req = new OapiRoleSimplelistRequest ( ) ;
req . setRoleId ( role_id ) ;
req . setSize ( SZ ) ;
req . setOffset ( start ) ;
OapiRoleSimplelistResponse rsp = client . execute ( req , access_token ) ;
JSONObject jo = JSONObject . parseObject ( rsp . getBody ( ) ) ;
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 ) ;
}
return res ;
if ( jo . getJSONObject ( "result" ) . getBoolean ( "hasMore" ) ) {
getRolePersonList ( access_token , role_id , start + SZ ) ;
}
}
public static void syncRolePersonReleation ( ) {
//getRolePersonList();
//Model.getRolePersonReleation();
}
/ * *