main
parent
5995ee0c77
commit
b9adbbfc66
@ -0,0 +1,56 @@
|
||||
package com.dsideal.FengHuang.DingTalk;
|
||||
|
||||
import com.dsideal.FengHuang.DingTalk.Util.DingTalkCommon;
|
||||
import com.dsideal.FengHuang.DingTalk.Util.Model;
|
||||
import com.dsideal.FengHuang.DingTalk.Util.OrgPerson;
|
||||
import com.dsideal.FengHuang.DingTalk.Util.Progress;
|
||||
import com.dsideal.FengHuang.Util.CommonUtil;
|
||||
import com.jfinal.kit.PropKit;
|
||||
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.jfinal.plugin.activerecord.dialect.MysqlDialect;
|
||||
import com.jfinal.plugin.druid.DruidPlugin;
|
||||
import com.jfinal.plugin.redis.RedisPlugin;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Increment {
|
||||
|
||||
public static void main(String[] args_) throws Exception {
|
||||
PropKit.use("dingtalk.properties");
|
||||
final String appKey = PropKit.get("appKey");
|
||||
String appSecret = PropKit.get("appSecret");
|
||||
|
||||
DruidPlugin druid = DingTalkCommon.createDruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim(), PropKit.get("driverClassName"));
|
||||
druid.start();
|
||||
|
||||
ActiveRecordPlugin arp = new ActiveRecordPlugin(druid);
|
||||
arp.setDevMode(false);
|
||||
arp.setDialect(new MysqlDialect());
|
||||
arp.start();
|
||||
|
||||
// 用于缓存模块的redis服务
|
||||
RedisPlugin redis = new RedisPlugin("myRedis", PropKit.get("redis_ip"), PropKit.getInt("redis_port"), 10 * 1000);
|
||||
redis.start();
|
||||
|
||||
//accessToken
|
||||
String accessToken = DingTalkCommon.getAccessToken(appKey, appSecret);
|
||||
|
||||
//同步钉钉与云平台中部门信息
|
||||
String orgName = "103中学";
|
||||
Record rOrg = Model.getOrgByOrgName(orgName);
|
||||
|
||||
//1、组织机构
|
||||
Progress.syncOrg(accessToken, rOrg);
|
||||
|
||||
//2、人员
|
||||
// dt = Progress.getLastSyncTime("t_base_person");
|
||||
//
|
||||
// //3、人员角色关系
|
||||
// dt = Progress.getLastSyncTime("t_sys_person_role");
|
||||
|
||||
CommonUtil.Print("恭喜,所有操作成功完成!");
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
ALTER TABLE `dsideal_db`.`t_base_organization`
|
||||
ADD COLUMN `dingtalk_dept_id` BIGINT NULL COMMENT '钉钉架构中机构的代码' AFTER `zydz`;
|
||||
|
||||
ALTER TABLE `dsideal_db`.`t_base_person`
|
||||
ADD COLUMN `dingtalk_person_id` varchar(255) NULL COMMENT '钉钉架构中人员ID' AFTER `pay_rate`;
|
@ -0,0 +1,51 @@
|
||||
package com.dsideal.FengHuang.DingTalk.Util;
|
||||
|
||||
import com.dsideal.FengHuang.Util.CommonUtil;
|
||||
import com.jfinal.plugin.activerecord.Db;
|
||||
import com.jfinal.plugin.activerecord.Record;
|
||||
import com.taobao.api.ApiException;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class Progress {
|
||||
|
||||
|
||||
public static void finishInit() {
|
||||
List<Record> list = Db.findAll("t_dingtalk_progress");
|
||||
for (Record record : list) {
|
||||
Model.saveLastSyncTime(record.getStr("table_name"));
|
||||
}
|
||||
}
|
||||
|
||||
public static void syncOrg(String accessToken, Record rOrg) throws ApiException {
|
||||
Date dt = Model.getLastSyncTime("t_base_organization");
|
||||
//找出变更信息
|
||||
List<Record> list = Model.getIncrementOrg(rOrg.getInt("org_id"), dt);
|
||||
for (Record record : list) {
|
||||
String org_name = record.getStr("org_name");
|
||||
int sort_id = record.getInt("sort_id");
|
||||
int b_use = record.getInt("b_use");
|
||||
|
||||
if (record.get("dingtalk_dept_id") == null) {
|
||||
//新增
|
||||
int parent_id = record.getInt("parent_id");
|
||||
//查询一下它的父亲的dingtalk_dept_id
|
||||
long parent_dingtalk_dept_id = Model.getDingTalkOrgId(parent_id);
|
||||
OrgPerson.createDept(accessToken, org_name, parent_dingtalk_dept_id, sort_id, false);
|
||||
CommonUtil.Print("新增部门:" + org_name);
|
||||
} else {
|
||||
int dingtalk_dept_id = record.getInt("dingtalk_dept_id");
|
||||
if (b_use == 1) {
|
||||
//修改
|
||||
OrgPerson.updateDept(accessToken, dingtalk_dept_id, org_name, sort_id);
|
||||
CommonUtil.Print("修改部门:" + org_name);
|
||||
} else {
|
||||
//删除
|
||||
OrgPerson.delDept(accessToken, dingtalk_dept_id);
|
||||
CommonUtil.Print("删除部门:" + org_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue