Search in sources :

Example 1 with ListUserResponse

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();
    }
}
Also used : OapiV2UserListRequest(com.dingtalk.api.request.OapiV2UserListRequest) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) ListUserResponse(com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse) SynchroRelated(org.maxkey.entity.SynchroRelated) UserInfo(org.maxkey.entity.UserInfo) OapiV2UserListResponse(com.dingtalk.api.response.OapiV2UserListResponse) DefaultDingTalkClient(com.dingtalk.api.DefaultDingTalkClient) DingTalkClient(com.dingtalk.api.DingTalkClient)

Aggregations

DefaultDingTalkClient (com.dingtalk.api.DefaultDingTalkClient)1 DingTalkClient (com.dingtalk.api.DingTalkClient)1 OapiV2UserListRequest (com.dingtalk.api.request.OapiV2UserListRequest)1 OapiV2UserListResponse (com.dingtalk.api.response.OapiV2UserListResponse)1 ListUserResponse (com.dingtalk.api.response.OapiV2UserListResponse.ListUserResponse)1 SynchroRelated (org.maxkey.entity.SynchroRelated)1 UserInfo (org.maxkey.entity.UserInfo)1