use of com.dingtalk.api.response.OapiV2DepartmentListsubResponse in project MaxKey by dromara.
the class DingtalkOrganizationService method sync.
public void sync() {
_logger.info("Sync Dingtalk Organizations ...");
LinkedBlockingQueue<Long> deptsQueue = new LinkedBlockingQueue<Long>();
deptsQueue.add(ROOT_DEPT_ID);
try {
// root
Organizations rootOrganization = organizationsService.get(Organizations.ROOT_ORG_ID);
OapiV2DepartmentGetResponse rootDeptRsp = requestDepartment(access_token, ROOT_DEPT_ID);
_logger.debug("root dept deptId {} , name {} , parentId {}", rootDeptRsp.getResult().getDeptId(), rootDeptRsp.getResult().getName(), rootDeptRsp.getResult().getParentId());
// root
SynchroRelated rootSynchroRelated = buildSynchroRelated(rootOrganization, rootDeptRsp.getResult().getDeptId() + "", rootDeptRsp.getResult().getName(), rootDeptRsp.getResult().getParentId() + "");
synchroRelatedService.updateSynchroRelated(this.synchronizer, rootSynchroRelated, Organizations.CLASS_TYPE);
while (deptsQueue.element() != null) {
OapiV2DepartmentListsubResponse rsp = requestDepartmentList(access_token, deptsQueue.poll());
for (DeptBaseResponse dept : rsp.getResult()) {
_logger.debug("dept deptId {} , name {} , parentId {} ", dept.getDeptId(), dept.getName(), dept.getParentId());
deptsQueue.add(dept.getDeptId());
// synchro Related
SynchroRelated synchroRelated = synchroRelatedService.findByOriginId(this.synchronizer, dept.getDeptId() + "", Organizations.CLASS_TYPE);
Organizations organization = buildOrganization(dept);
if (synchroRelated == null) {
organization.setId(organization.generateId());
organizationsService.insert(organization);
_logger.debug("Organizations : " + organization);
synchroRelated = buildSynchroRelated(organization, dept.getDeptId() + "", dept.getName(), dept.getParentId() + "");
} else {
organization.setId(synchroRelated.getObjectId());
organizationsService.update(organization);
}
synchroRelatedService.updateSynchroRelated(this.synchronizer, synchroRelated, Organizations.CLASS_TYPE);
_logger.debug("Organizations : " + organization);
}
}
} catch (ApiException e) {
e.printStackTrace();
} catch (NoSuchElementException e) {
_logger.debug("Sync Department successful .");
}
}
use of com.dingtalk.api.response.OapiV2DepartmentListsubResponse in project MaxKey by dromara.
the class DingtalkOrganizationService method requestDepartmentList.
public OapiV2DepartmentListsubResponse requestDepartmentList(String access_token, Long deptId) throws ApiException {
DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsub");
OapiV2DepartmentListsubRequest req = new OapiV2DepartmentListsubRequest();
req.setDeptId(deptId);
req.setLanguage("zh_CN");
OapiV2DepartmentListsubResponse rspDepts = client.execute(req, access_token);
_logger.trace("response : " + rspDepts.getBody());
return rspDepts;
}
Aggregations