Search in sources :

Example 1 with OapiV2DepartmentListsubResponse

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 .");
    }
}
Also used : OapiV2DepartmentListsubResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse) Organizations(org.maxkey.entity.Organizations) SynchroRelated(org.maxkey.entity.SynchroRelated) OapiV2DepartmentGetResponse(com.dingtalk.api.response.OapiV2DepartmentGetResponse) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) DeptBaseResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse) NoSuchElementException(java.util.NoSuchElementException) ApiException(com.taobao.api.ApiException)

Example 2 with OapiV2DepartmentListsubResponse

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;
}
Also used : OapiV2DepartmentListsubResponse(com.dingtalk.api.response.OapiV2DepartmentListsubResponse) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient) OapiV2DepartmentListsubRequest(com.dingtalk.api.request.OapiV2DepartmentListsubRequest)

Aggregations

OapiV2DepartmentListsubResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse)2 DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)1 DingTalkClient (com.dingtalk.api.DingTalkClient)1 OapiV2DepartmentListsubRequest (com.dingtalk.api.request.OapiV2DepartmentListsubRequest)1 OapiV2DepartmentGetResponse (com.dingtalk.api.response.OapiV2DepartmentGetResponse)1 DeptBaseResponse (com.dingtalk.api.response.OapiV2DepartmentListsubResponse.DeptBaseResponse)1 ApiException (com.taobao.api.ApiException)1 NoSuchElementException (java.util.NoSuchElementException)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1 Organizations (org.maxkey.entity.Organizations)1 SynchroRelated (org.maxkey.entity.SynchroRelated)1