main
黄海 2 years ago
parent b9adbbfc66
commit 60699a7abf

@ -46,8 +46,8 @@ public class Increment {
Progress.syncOrg(accessToken, rOrg);
//2、人员
// dt = Progress.getLastSyncTime("t_base_person");
//
Progress.syncPerson(accessToken, rOrg);
// //3、人员角色关系
// dt = Progress.getLastSyncTime("t_sys_person_role");

@ -1,5 +1,7 @@
package com.dsideal.FengHuang.DingTalk.Util;
import cn.binarywang.tools.generator.ChineseMobileNumberGenerator;
import cn.hutool.core.util.PhoneUtil;
import com.alibaba.druid.filter.stat.StatFilter;
import com.aliyun.dingtalkoauth2_1_0.models.CreateJsapiTicketResponse;
import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenResponse;
@ -7,6 +9,7 @@ import com.aliyun.dingtalkoauth2_1_0.models.GetSsoAccessTokenRequest;
import com.aliyun.dingtalkoauth2_1_0.models.GetSsoAccessTokenResponse;
import com.aliyun.tea.TeaException;
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.jfinal.plugin.druid.DruidPlugin;
@ -158,4 +161,13 @@ public class DingTalkCommon {
int remain_count = record.getInt("remain_count");
CommonUtil.Print("钉钉本月剩余API调用次数" + remain_count + "");
}
public static String getLawfulTel(String tel) {
//模拟处理一下手机号
if (StrKit.isBlank(tel) || !PhoneUtil.isMobile(tel)) {
tel = ChineseMobileNumberGenerator.getInstance().generate();//生成一个随机临时测试用的手机号
tel = "14" + tel.substring(2);//以14段开头避开已存在的号码
}
return tel;
}
}

@ -92,6 +92,11 @@ public class Model {
return Db.find(sql, org_id, dt);
}
public static List<Record> getIncrementPerson(int org_id, Date dt) {
String sql = "select person_id,person_name,org_id,b_use,dingtalk_person_id from t_base_person where bureau_id=? and last_update_time>?";
return Db.find(sql, org_id, dt);
}
public static long getDingTalkOrgId(int org_id) {
String sql = "select dingtalk_dept_id from t_base_organization where org_id=?";
return Db.findFirst(sql, org_id).getLong("dingtalk_dept_id");

@ -155,14 +155,14 @@ public class OrgPerson {
* @param zhiWei
* @throws ApiException
*/
public static void createPerson(String access_token, String deptId, int userId, String personName, String tel, String zhiWei) throws ApiException {
public static void createPerson(String access_token, long deptId, int userId, String personName, String tel, String zhiWei) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/create");
OapiV2UserCreateRequest req = new OapiV2UserCreateRequest();
req.setUserid(String.valueOf(userId));
req.setName(personName);
req.setMobile(tel);
req.setTitle(zhiWei);
req.setDeptIdList(deptId);
req.setDeptIdList(String.valueOf(deptId));
OapiV2UserCreateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
}
@ -174,18 +174,18 @@ public class OrgPerson {
* @param userId
* @throws ApiException
*/
public static void delPerson(String access_token, String userId) throws ApiException {
public static void delPerson(String access_token, int userId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/delete");
OapiV2UserDeleteRequest req = new OapiV2UserDeleteRequest();
req.setUserid(userId);
req.setUserid(String.valueOf(userId));
OapiV2UserDeleteResponse rsp = client.execute(req, access_token);
//System.out.println(rsp.getBody());
System.out.println(rsp.getBody());
}
public static void updatePerson(String access_token, String person_id, String person_name) throws ApiException {
public static void updatePerson(String access_token, int person_id, String person_name) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/update");
OapiV2UserUpdateRequest req = new OapiV2UserUpdateRequest();
req.setUserid(person_id);
req.setUserid(String.valueOf(person_id));
req.setName(person_name);
OapiV2UserUpdateResponse rsp = client.execute(req, access_token);
System.out.println(rsp.getBody());
@ -253,13 +253,9 @@ public class OrgPerson {
int person_id = record.getInt("person_id");
String person_name = record.getStr("person_name");
String tel = record.getStr("tel");
//模拟处理一下手机号
if (StrKit.isBlank(tel) || !PhoneUtil.isMobile(tel)) {
tel = ChineseMobileNumberGenerator.getInstance().generate();//生成一个随机临时测试用的手机号
tel = "14" + tel.substring(2);//以14段开头避开已存在的号码
}
tel = DingTalkCommon.getLawfulTel(tel);
long deptId = record.getLong("dingtalk_dept_id");
createPerson(accessToken, String.valueOf(deptId), person_id, person_name, tel, "教师");
createPerson(accessToken, deptId, person_id, person_name, tel, "教师");
//回写标识
Model.writePersonDingTalkId(person_id);
@ -281,7 +277,7 @@ public class OrgPerson {
for (int i = 0; i < personList.size(); i++) {
String userid = personList.get(i).getStr("userid");
String person_name = personList.get(i).getStr("name");
delPerson(accessToken, userid);
delPerson(accessToken, Integer.parseInt(userid));
CommonUtil.Print("成功删除:" + person_name);
}
}

@ -48,4 +48,35 @@ public class Progress {
}
}
}
public static void syncPerson(String accessToken, Record rOrg) throws ApiException {
Date dt = Model.getLastSyncTime("t_base_person");
//找出变更信息
List<Record> list = Model.getIncrementPerson(rOrg.getInt("org_id"), dt);
for (Record record : list) {
String person_name = record.getStr("person_name");
int b_use = record.getInt("b_use");
int org_id= record.getInt("org_id");
int person_id=record.getInt("person_id");
String tel=record.getStr("tel");
if (record.get("dingtalk_person_id") == null) {
//新增
long dingtalk_dept_id = Model.getDingTalkOrgId(org_id);
tel = DingTalkCommon.getLawfulTel(tel);
OrgPerson.createPerson(accessToken,dingtalk_dept_id,person_id,person_name,tel,"教师");
CommonUtil.Print("新增人员:" + person_name);
} else {
int dingtalk_dept_id = record.getInt("dingtalk_dept_id");
if (b_use == 1) {
//修改
OrgPerson.updatePerson(accessToken,person_id,person_name);
CommonUtil.Print("修改人员:" + person_name);
} else {
//删除
OrgPerson.delPerson(accessToken, person_id);
CommonUtil.Print("删除人员:" + person_name);
}
}
}
}
}

Loading…
Cancel
Save