use of com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse in project MaxKey by dromara.
the class DingtalkUsersService method sync.
public void sync() {
_logger.info("Sync Dingtalk Users...");
try {
List<SynchroRelated> synchroRelateds = synchroRelatedService.findOrgs(this.synchronizer);
for (SynchroRelated relatedOrg : synchroRelateds) {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/list");
OapiV2UserListRequest req = new OapiV2UserListRequest();
_logger.debug("DingTalk deptId : {}", relatedOrg.getOriginId());
req.setDeptId(Long.parseLong(relatedOrg.getOriginId()));
req.setCursor(0L);
req.setSize(100L);
req.setOrderField("modify_desc");
req.setContainAccessLimit(true);
req.setLanguage("zh_CN");
OapiV2UserListResponse rsp = client.execute(req, access_token);
_logger.trace("response : {}", rsp.getBody());
if (rsp.getErrcode() == 0) {
for (ListUserResponse user : rsp.getResult().getList()) {
_logger.debug("name : {} , {} , {}", user.getName(), user.getLoginId(), user.getUserid());
UserInfo userInfo = buildUserInfo(user, relatedOrg);
_logger.trace("userInfo {}", userInfo);
userInfo.setPassword(userInfo.getUsername() + UserInfo.DEFAULT_PASSWORD_SUFFIX);
userInfoService.saveOrUpdate(userInfo);
SynchroRelated synchroRelated = new SynchroRelated(userInfo.getId(), userInfo.getUsername(), userInfo.getDisplayName(), UserInfo.CLASS_TYPE, synchronizer.getId(), synchronizer.getName(), user.getUnionid(), user.getName(), user.getUserid(), "", synchronizer.getInstId());
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, UserInfo.CLASS_TYPE);
socialsAssociate(synchroRelated, "dingtalk");
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations