Search in sources :

Example 1 with AccessToken

use of com.jeecg.dingtalk.api.core.vo.AccessToken in project jeecg-boot by jeecgboot.

the class ThirdAppDingtalkServiceImpl method syncThirdAppUserToLocal.

@Override
public SyncInfoVo syncThirdAppUserToLocal() {
    SyncInfoVo syncInfo = new SyncInfoVo();
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        syncInfo.addFailInfo("accessToken获取失败!");
        return syncInfo;
    }
    // 获取本地用户
    List<SysUser> sysUsersList = sysUserService.list();
    // 查询钉钉所有的部门,用于同步用户和部门的关系
    List<Department> allDepartment = JdtDepartmentAPI.listAll(accessToken);
    // 根据钉钉部门查询所有钉钉用户,用于反向同步到本地
    List<User> ddUserList = this.getDtAllUserByDepartment(allDepartment, accessToken);
    for (User dtUserInfo : ddUserList) {
        SysThirdAccount sysThirdAccount = sysThirdAccountService.getOneByThirdUserId(dtUserInfo.getUserid(), THIRD_TYPE);
        List<SysUser> collect = sysUsersList.stream().filter(user -> (dtUserInfo.getMobile().equals(user.getPhone()) || dtUserInfo.getUserid().equals(user.getUsername()))).collect(Collectors.toList());
        if (collect != null && collect.size() > 0) {
            SysUser sysUserTemp = collect.get(0);
            // 循环到此说明用户匹配成功,进行更新操作
            SysUser updateSysUser = this.dtUserToSysUser(dtUserInfo, sysUserTemp);
            try {
                sysUserService.updateById(updateSysUser);
                String str = String.format("用户 %s(%s) 更新成功!", updateSysUser.getRealname(), updateSysUser.getUsername());
                syncInfo.addSuccessInfo(str);
            } catch (Exception e) {
                this.syncUserCollectErrInfo(e, dtUserInfo, syncInfo);
            }
            // 第三方账号关系表
            this.thirdAccountSaveOrUpdate(sysThirdAccount, updateSysUser.getId(), dtUserInfo.getUserid());
        } else {
            // 如果没有匹配到用户,则走创建逻辑
            SysUser newSysUser = this.dtUserToSysUser(dtUserInfo);
            try {
                sysUserService.save(newSysUser);
                String str = String.format("用户 %s(%s) 创建成功!", newSysUser.getRealname(), newSysUser.getUsername());
                syncInfo.addSuccessInfo(str);
            } catch (Exception e) {
                this.syncUserCollectErrInfo(e, dtUserInfo, syncInfo);
            }
            // 第三方账号关系表
            this.thirdAccountSaveOrUpdate(null, newSysUser.getId(), dtUserInfo.getUserid());
        }
    }
    return syncInfo;
}
Also used : SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) ThirdLoginModel(org.jeecg.modules.system.model.ThirdLoginModel) ActionCardMessage(com.jeecg.dingtalk.api.message.vo.ActionCardMessage) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Department(com.jeecg.dingtalk.api.department.vo.Department) JdtDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo) org.jeecg.modules.system.entity(org.jeecg.modules.system.entity) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ContactUser(com.jeecg.dingtalk.api.oauth2.vo.ContactUser) ArrayList(java.util.ArrayList) ThirdAppConfig(org.jeecg.config.thirdapp.ThirdAppConfig) AccessToken(com.jeecg.dingtalk.api.core.vo.AccessToken) JdtMessageAPI(com.jeecg.dingtalk.api.message.JdtMessageAPI) Message(com.jeecg.dingtalk.api.message.vo.Message) Service(org.springframework.stereotype.Service) User(com.jeecg.dingtalk.api.user.vo.User) org.jeecg.common.util.oConvertUtils(org.jeecg.common.util.oConvertUtils) GetUserListBody(com.jeecg.dingtalk.api.user.body.GetUserListBody) JdtBaseAPI(com.jeecg.dingtalk.api.base.JdtBaseAPI) org.jeecg.modules.system.service(org.jeecg.modules.system.service) JdtDepartmentAPI(com.jeecg.dingtalk.api.department.JdtDepartmentAPI) ThirdAppTypeItemVo(org.jeecg.config.thirdapp.ThirdAppTypeItemVo) JdtUserAPI(com.jeecg.dingtalk.api.user.JdtUserAPI) JwtUtil(org.jeecg.common.system.util.JwtUtil) PasswordUtil(org.jeecg.common.util.PasswordUtil) SysAnnouncementSendMapper(org.jeecg.modules.system.mapper.SysAnnouncementSendMapper) Collectors(java.util.stream.Collectors) RestUtil(org.jeecg.common.util.RestUtil) JdtOauth2API(com.jeecg.dingtalk.api.oauth2.JdtOauth2API) Slf4j(lombok.extern.slf4j.Slf4j) SpringContextUtils(org.jeecg.common.util.SpringContextUtils) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) List(java.util.List) JSON(com.alibaba.fastjson.JSON) Response(com.jeecg.dingtalk.api.core.response.Response) JSONObject(com.alibaba.fastjson.JSONObject) SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) TextMessage(com.jeecg.dingtalk.api.message.vo.TextMessage) CommonConstant(org.jeecg.common.constant.CommonConstant) MessageDTO(org.jeecg.common.api.dto.message.MessageDTO) PageResult(com.jeecg.dingtalk.api.core.vo.PageResult) SysDepartTreeModel(org.jeecg.modules.system.model.SysDepartTreeModel) BeanUtils(org.springframework.beans.BeanUtils) Department(com.jeecg.dingtalk.api.department.vo.Department) ContactUser(com.jeecg.dingtalk.api.oauth2.vo.ContactUser) User(com.jeecg.dingtalk.api.user.vo.User) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 2 with AccessToken

use of com.jeecg.dingtalk.api.core.vo.AccessToken in project kykms by mahonelau.

the class ThirdAppDingtalkServiceImpl method getAccessToken.

@Override
public String getAccessToken() {
    String appKey = thirdAppConfig.getDingtalk().getClientId();
    String appSecret = thirdAppConfig.getDingtalk().getClientSecret();
    AccessToken accessToken = JdtBaseAPI.getAccessToken(appKey, appSecret);
    if (accessToken != null) {
        return accessToken.getAccessToken();
    }
    log.warn("获取AccessToken失败");
    return null;
}
Also used : AccessToken(com.jeecg.dingtalk.api.core.vo.AccessToken)

Example 3 with AccessToken

use of com.jeecg.dingtalk.api.core.vo.AccessToken in project kms by mahonelau.

the class ThirdAppDingtalkServiceImpl method syncThirdAppUserToLocal.

@Override
public SyncInfoVo syncThirdAppUserToLocal() {
    SyncInfoVo syncInfo = new SyncInfoVo();
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        syncInfo.addFailInfo("accessToken获取失败!");
        return syncInfo;
    }
    // 获取本地用户
    List<SysUser> sysUsersList = sysUserService.list();
    // 查询钉钉所有的部门,用于同步用户和部门的关系
    List<Department> allDepartment = JdtDepartmentAPI.listAll(accessToken);
    // 根据钉钉部门查询所有钉钉用户,用于反向同步到本地
    List<User> ddUserList = this.getDtAllUserByDepartment(allDepartment, accessToken);
    for (User dtUserInfo : ddUserList) {
        SysThirdAccount sysThirdAccount = sysThirdAccountService.getOneByThirdUserId(dtUserInfo.getUserid(), ThirdAppConfig.DINGTALK.toLowerCase());
        List<SysUser> collect = sysUsersList.stream().filter(user -> (dtUserInfo.getMobile().equals(user.getPhone()) || dtUserInfo.getUserid().equals(user.getUsername()))).collect(Collectors.toList());
        if (collect != null && collect.size() > 0) {
            SysUser sysUserTemp = collect.get(0);
            // 循环到此说明用户匹配成功,进行更新操作
            SysUser updateSysUser = this.dtUserToSysUser(dtUserInfo, sysUserTemp);
            try {
                sysUserService.updateById(updateSysUser);
                String str = String.format("用户 %s(%s) 更新成功!", updateSysUser.getRealname(), updateSysUser.getUsername());
                syncInfo.addSuccessInfo(str);
            } catch (Exception e) {
                this.syncUserCollectErrInfo(e, dtUserInfo, syncInfo);
            }
            // 第三方账号关系表
            this.thirdAccountSaveOrUpdate(sysThirdAccount, updateSysUser.getId(), dtUserInfo.getUserid());
        } else {
            // 如果没有匹配到用户,则走创建逻辑
            SysUser newSysUser = this.dtUserToSysUser(dtUserInfo);
            try {
                sysUserService.save(newSysUser);
                String str = String.format("用户 %s(%s) 创建成功!", newSysUser.getRealname(), newSysUser.getUsername());
                syncInfo.addSuccessInfo(str);
            } catch (Exception e) {
                this.syncUserCollectErrInfo(e, dtUserInfo, syncInfo);
            }
            // 第三方账号关系表
            this.thirdAccountSaveOrUpdate(null, newSysUser.getId(), dtUserInfo.getUserid());
        }
    }
    return syncInfo;
}
Also used : SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) ActionCardMessage(com.jeecg.dingtalk.api.message.vo.ActionCardMessage) StringUtils(org.apache.commons.lang.StringUtils) Arrays(java.util.Arrays) Department(com.jeecg.dingtalk.api.department.vo.Department) JdtDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo) org.jeecg.modules.system.entity(org.jeecg.modules.system.entity) Autowired(org.springframework.beans.factory.annotation.Autowired) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) ArrayList(java.util.ArrayList) ThirdAppConfig(org.jeecg.config.thirdapp.ThirdAppConfig) AccessToken(com.jeecg.dingtalk.api.core.vo.AccessToken) JdtMessageAPI(com.jeecg.dingtalk.api.message.JdtMessageAPI) Message(com.jeecg.dingtalk.api.message.vo.Message) Service(org.springframework.stereotype.Service) User(com.jeecg.dingtalk.api.user.vo.User) org.jeecg.common.util.oConvertUtils(org.jeecg.common.util.oConvertUtils) GetUserListBody(com.jeecg.dingtalk.api.user.body.GetUserListBody) JdtBaseAPI(com.jeecg.dingtalk.api.base.JdtBaseAPI) org.jeecg.modules.system.service(org.jeecg.modules.system.service) JdtDepartmentAPI(com.jeecg.dingtalk.api.department.JdtDepartmentAPI) JdtUserAPI(com.jeecg.dingtalk.api.user.JdtUserAPI) JwtUtil(org.jeecg.common.system.util.JwtUtil) PasswordUtil(org.jeecg.common.util.PasswordUtil) SysAnnouncementSendMapper(org.jeecg.modules.system.mapper.SysAnnouncementSendMapper) Collectors(java.util.stream.Collectors) RestUtil(org.jeecg.common.util.RestUtil) Slf4j(lombok.extern.slf4j.Slf4j) SpringContextUtils(org.jeecg.common.util.SpringContextUtils) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) List(java.util.List) Response(com.jeecg.dingtalk.api.core.response.Response) JSONObject(com.alibaba.fastjson.JSONObject) SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) TextMessage(com.jeecg.dingtalk.api.message.vo.TextMessage) CommonConstant(org.jeecg.common.constant.CommonConstant) MessageDTO(org.jeecg.common.api.dto.message.MessageDTO) PageResult(com.jeecg.dingtalk.api.core.vo.PageResult) SysDepartTreeModel(org.jeecg.modules.system.model.SysDepartTreeModel) BeanUtils(org.springframework.beans.BeanUtils) Department(com.jeecg.dingtalk.api.department.vo.Department) User(com.jeecg.dingtalk.api.user.vo.User) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 4 with AccessToken

use of com.jeecg.dingtalk.api.core.vo.AccessToken in project kms by mahonelau.

the class ThirdAppDingtalkServiceImpl method getAccessToken.

@Override
public String getAccessToken() {
    String appKey = thirdAppConfig.getDingtalk().getClientId();
    String appSecret = thirdAppConfig.getDingtalk().getClientSecret();
    AccessToken accessToken = JdtBaseAPI.getAccessToken(appKey, appSecret);
    if (accessToken != null) {
        return accessToken.getAccessToken();
    }
    log.warn("获取AccessToken失败");
    return null;
}
Also used : AccessToken(com.jeecg.dingtalk.api.core.vo.AccessToken)

Example 5 with AccessToken

use of com.jeecg.dingtalk.api.core.vo.AccessToken in project jeecg-boot by jeecgboot.

the class ThirdAppDingtalkServiceImpl method getAccessToken.

@Override
public String getAccessToken() {
    String appKey = thirdAppConfig.getDingtalk().getClientId();
    String appSecret = thirdAppConfig.getDingtalk().getClientSecret();
    AccessToken accessToken = JdtBaseAPI.getAccessToken(appKey, appSecret);
    if (accessToken != null) {
        return accessToken.getAccessToken();
    }
    log.warn("获取AccessToken失败");
    return null;
}
Also used : AccessToken(com.jeecg.dingtalk.api.core.vo.AccessToken)

Aggregations

AccessToken (com.jeecg.dingtalk.api.core.vo.AccessToken)6 JSONObject (com.alibaba.fastjson.JSONObject)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 JdtBaseAPI (com.jeecg.dingtalk.api.base.JdtBaseAPI)3 Response (com.jeecg.dingtalk.api.core.response.Response)3 PageResult (com.jeecg.dingtalk.api.core.vo.PageResult)3 JdtDepartmentAPI (com.jeecg.dingtalk.api.department.JdtDepartmentAPI)3 Department (com.jeecg.dingtalk.api.department.vo.Department)3 JdtMessageAPI (com.jeecg.dingtalk.api.message.JdtMessageAPI)3 ActionCardMessage (com.jeecg.dingtalk.api.message.vo.ActionCardMessage)3 Message (com.jeecg.dingtalk.api.message.vo.Message)3 TextMessage (com.jeecg.dingtalk.api.message.vo.TextMessage)3 JdtUserAPI (com.jeecg.dingtalk.api.user.JdtUserAPI)3 GetUserListBody (com.jeecg.dingtalk.api.user.body.GetUserListBody)3 User (com.jeecg.dingtalk.api.user.vo.User)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Slf4j (lombok.extern.slf4j.Slf4j)3