|
20Java金币
接口事件
public class OrganizationSynchronousImpl implements
OrganizationSynchronousInterface {
public void synchronousCompany(CompanyModel model, int action) {
if(action == OrganizationSyncEvent.ADD) {
System.out.println("增加了单位模型:" + model._companyName);
}
if(action == OrganizationSyncEvent.MODIFY) {
System.out.println("修改了单位模型:" + model._companyName);
}
if(action == OrganizationSyncEvent.REMOVE) {
System.out.println("删除了单位模型:" + model._companyName);
}
//TODO 编写组织结构同步事件的代码
}
public void synchronousDepartment(DepartmentModel model, int action) {
if(action == OrganizationSyncEvent.ADD) {
System.out.println("增加了部门模型:" + model._departmentName);
}
if(action == OrganizationSyncEvent.MODIFY) {
System.out.println("修改了部门模型:" + model._departmentName);
}
if(action == OrganizationSyncEvent.REMOVE) {
System.out.println("删除了部门模型:" + model._departmentName);
}
//TODO 编写组织结构同步事件的代码
}
public void synchronousUser(UserModel model, int action) {
if(action == OrganizationSyncEvent.ADD) {
System.out.println("增加了人员模型:" + model._userName);
}
if(action == OrganizationSyncEvent.MODIFY) {
System.out.println("修改了人员模型:" + model._userName);
}
if(action == OrganizationSyncEvent.REMOVE) {
System.out.println("删除了人员模型:" + model._userName);
}
// TODO 编写组织结构同步事件的代码
}
}
demo文件
public class Demo {
public static void main(String[] args) throws Exception {
try {
List<Department> departments = new ArrayList<Department>();
departments = DepartmentHelper.listDepartments(AuthHelper.getAccessToken(), "1");
JSONObject usersJSON = new JSONObject();
System.out.println("depart num:"+departments.size());
for(int i = 0;i<departments.size();i++){
JSONObject userDepJSON = new JSONObject();
System.out.println("dep:"+departments.get(i).toString());
long offset = 0;
int size = 5;
CorpUserList corpUserList = new CorpUserList();
while (true) {
corpUserList = UserHelper.getDepartmentUser(AuthHelper.getAccessToken(), Long.valueOf(departments.get(i).getId())
, offset, size, null);
System.out.println(JSON.toJSONString(corpUserList));
if (Boolean.TRUE.equals(corpUserList.isHasMore())) {
offset += size;
} else {
break;
}
}
if(corpUserList.getUserlist().size()==0){
continue;
}
for(int j = 0;j<corpUserList.getUserlist().size();j++){
String user = JSON.toJSONString(corpUserList.getUserlist().get(j));
userDepJSON.put(j+"", JSONObject.parseObject(user, CorpUserDetail.class));
}
usersJSON.put(departments.get(i).getName(), userDepJSON);
System.out.println("user:"+usersJSON.toString());
}
System.out.println("depart:"+usersJSON.toJSONString());
// 获取access token
String accessToken = AuthHelper.getAccessToken();
log("成功获取access token: ", accessToken);
// 获取jsapi ticket
String ticket = AuthHelper.getJsapiTicket(accessToken);
log("成功获取jsapi ticket: ", ticket);
// 获取签名
String nonceStr = "nonceStr";
long timeStamp = System.currentTimeMillis();
String url = "http://www.dingtalk.com";
String signature = AuthHelper.sign(ticket, nonceStr, timeStamp, url);
log("成功签名: ", signature);
// 创建部门
String name = "TestDept.34";
String parentId = "1";
String order = "1";
boolean createDeptGroup = true;
long departmentId = Long.parseLong(DepartmentHelper.createDepartment(accessToken, name, parentId, order, createDeptGroup));
log("成功创建部门", name, " 部门id=", departmentId);
// 更新部门
name = "hahahaha";
boolean autoAddUser = true;
String deptManagerUseridList = null;
boolean deptHiding = false;
String deptPerimits = "aa|qq";
DepartmentHelper.updateDepartment(accessToken, departmentId, name, parentId, order, createDeptGroup,
autoAddUser, deptManagerUseridList, deptHiding, deptPerimits, null,
null, null, null, null);
log("成功更新部门", " 部门id=", departmentId);
//新建用户
CorpUserDetail userDetail = new CorpUserDetail();
userDetail.setUserid("id_yuhuan");
userDetail.setName("name_yuhuan");
userDetail.setEmail("yuhuan@abc.com");
userDetail.setMobile("18612124567");
userDetail.setDepartment(new ArrayList());
userDetail.getDepartment().add(departmentId);
UserHelper.createUser(accessToken, userDetail);
log("成功创建成员", "成员信息=", userDetail);
// 更新成员
userDetail.setMobile("11177776666");
UserHelper.updateUser(accessToken, userDetail);
log("成功更新成员", "成员信息=", userDetail);
// 获取成员
CorpUserDetail userDetail11 = UserHelper.getUser(accessToken, userDetail.getUserid());
log("成功获取成员", "成员userid=", userDetail11.getUserid());
// 获取部门成员
CorpUserList userList = UserHelper.getDepartmentUser(accessToken, departmentId, null, null, null);
log("成功获取部门成员", "部门成员user=", userList.getUserlist());
// 获取部门成员(详情)
CorpUserDetailList userList2 = UserHelper.getUserDetails(accessToken, departmentId, null, null, null);
log("成功获取部门成员详情", "部门成员详情user=", userList2.getUserlist());
// 批量删除成员
// User user2 = new User("id_yuhuan2", "name_yuhuan2");
// user2.email = "yuhua2n@abc.com";
// user2.mobile = "18611111111";
// user2.department = new ArrayList();
// user2.department.add(departmentId);
// UserHelper.createUser(accessToken, user2);
CorpUserDetail userDetail2 = new CorpUserDetail();
userDetail2.setUserid("id_yuhuan2");
userDetail2.setName("name_yuhuan2");
userDetail2.setEmail("yuhua2n@abc.com");
userDetail2.setMobile("18612124926");
userDetail2.setDepartment(new ArrayList());
userDetail2.getDepartment().add(departmentId);
UserHelper.createUser(accessToken, userDetail2);
List<String> useridlist = new ArrayList();
useridlist.add(userDetail.getUserid());
useridlist.add(userDetail2.getUserid());
UserHelper.batchDeleteUser(accessToken, useridlist);
log("成功批量删除成员", "成员列表useridlist=", useridlist);
// 删除成员
// User user3 = new User("id_yuhuan3", "name_yuhuan3");
// user3.email = "yuhua2n@abc.com";
// user3.mobile = "18611111111";
// user3.department = new ArrayList();
// user3.department.add(departmentId);
CorpUserDetail userDetail3 = new CorpUserDetail();
userDetail3.setUserid("id_yuhuan3");
userDetail3.setName("name_yuhuan3");
userDetail3.setMobile("13146654734");
userDetail3.setDepartment(new ArrayList());
userDetail3.getDepartment().add(departmentId);
UserHelper.createUser(accessToken, userDetail3);
UserHelper.deleteUser(accessToken, userDetail3.getUserid());
log("成功删除成员", "成员userid=", userDetail3.getUserid());
// 删除部门
DepartmentHelper.deleteDepartment(accessToken, departmentId);
log("成功删除部门", " 部门id=", departmentId);
} catch (OApiException e) {
e.printStackTrace();
}
}
private static void log(Object... msgs) {
StringBuilder sb = new StringBuilder();
for (Object o : msgs) {
if (o != null) {
sb.append(o.toString());
}
}
System.out.println(sb.toString());
}
}
问:
1、我需要在demo里如何调用接口事件;
2、如何将接口文件中的值model._companyName/model._departmentName/model._userName传给DEMO中;
3、如何定义DEMO的执行System.out.println("depart:"+usersJSON.toJSONString());
新手,麻烦说明的详细些,非常感谢!
|
|