Search in sources :

Example 6 with Department

use of com.jeecg.dingtalk.api.department.vo.Department in project kms by mahonelau.

the class ThirdAppDingtalkServiceImpl method syncThirdAppDepartmentToLocal.

@Override
public SyncInfoVo syncThirdAppDepartmentToLocal(String ids) {
    SyncInfoVo syncInfo = new SyncInfoVo();
    String accessToken = this.getAccessToken();
    if (accessToken == null) {
        syncInfo.addFailInfo("accessToken获取失败!");
        return syncInfo;
    }
    // 获取【钉钉】所有的部门
    List<Department> departments = JdtDepartmentAPI.listAll(accessToken);
    String username = JwtUtil.getUserNameByToken(SpringContextUtils.getHttpServletRequest());
    List<JdtDepartmentTreeVo> departmentTreeList = JdtDepartmentTreeVo.listToTree(departments);
    // 递归同步部门
    this.syncDepartmentToLocalRecursion(departmentTreeList, null, username, syncInfo, accessToken);
    return syncInfo;
}
Also used : SyncInfoVo(org.jeecg.modules.system.vo.thirdapp.SyncInfoVo) Department(com.jeecg.dingtalk.api.department.vo.Department) JdtDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo)

Example 7 with Department

use of com.jeecg.dingtalk.api.department.vo.Department in project kms by mahonelau.

the class ThirdAppDingtalkServiceImpl method sysDepartToDtDepartment.

/**
 * 【同步部门】将SysDepartTreeModel转为【钉钉】的Department对象(创建新部门)
 */
private Department sysDepartToDtDepartment(SysDepartTreeModel departTree, Integer parentId) {
    Department department = new Department();
    department.setSource_identifier(departTree.getId());
    return this.sysDepartToDtDepartment(departTree, department, parentId);
}
Also used : Department(com.jeecg.dingtalk.api.department.vo.Department)

Example 8 with Department

use of com.jeecg.dingtalk.api.department.vo.Department in project kykms by mahonelau.

the class ThirdAppDingtalkServiceImpl method sysUserToDtUser.

/**
 * 【同步用户】将SysUser转为【钉钉】的User对象(更新旧用户)
 */
private User sysUserToDtUser(SysUser sysUser, User user, List<Department> allDepartment) {
    user.setName(sysUser.getRealname());
    user.setMobile(sysUser.getPhone());
    user.setTelephone(sysUser.getTelephone());
    user.setJob_number(sysUser.getWorkNo());
    // 职务翻译
    if (oConvertUtils.isNotEmpty(sysUser.getPost())) {
        SysPosition position = sysPositionService.getByCode(sysUser.getPost());
        if (position != null) {
            user.setTitle(position.getName());
        }
    }
    user.setEmail(sysUser.getEmail());
    // 查询并同步用户部门关系
    List<SysDepart> departList = this.getUserDepart(sysUser);
    if (departList != null) {
        List<Integer> departmentIdList = new ArrayList<>();
        for (SysDepart sysDepart : departList) {
            // 企业微信的部门id
            Department department = this.getDepartmentByDepartId(sysDepart.getId(), allDepartment);
            if (department != null) {
                departmentIdList.add(department.getDept_id());
            }
        }
        user.setDept_id_list(departmentIdList.toArray(new Integer[] {}));
        user.setDept_order_list(null);
    }
    if (oConvertUtils.isEmpty(user.getDept_id_list())) {
        // 没有找到匹配部门,同步到根部门下
        user.setDept_id_list(1);
        user.setDept_order_list(null);
    }
    // sysUser.getStatus()
    return user;
}
Also used : Department(com.jeecg.dingtalk.api.department.vo.Department) ArrayList(java.util.ArrayList)

Example 9 with Department

use of com.jeecg.dingtalk.api.department.vo.Department in project kykms by mahonelau.

the class ThirdAppDingtalkServiceImpl method sysDepartToDtDepartment.

/**
 * 【同步部门】将SysDepartTreeModel转为【钉钉】的Department对象(创建新部门)
 */
private Department sysDepartToDtDepartment(SysDepartTreeModel departTree, Integer parentId) {
    Department department = new Department();
    department.setSource_identifier(departTree.getId());
    return this.sysDepartToDtDepartment(departTree, department, parentId);
}
Also used : Department(com.jeecg.dingtalk.api.department.vo.Department)

Example 10 with Department

use of com.jeecg.dingtalk.api.department.vo.Department in project kykms by mahonelau.

the class ThirdAppDingtalkServiceImpl method syncDepartmentToLocalRecursion.

public void syncDepartmentToLocalRecursion(List<JdtDepartmentTreeVo> departmentTreeList, String sysParentId, String username, SyncInfoVo syncInfo, String accessToken) {
    if (departmentTreeList != null && departmentTreeList.size() != 0) {
        for (JdtDepartmentTreeVo departmentTree : departmentTreeList) {
            LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
            // 根据 source_identifier 字段查询
            queryWrapper.eq(SysDepart::getId, departmentTree.getSource_identifier());
            SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
            if (sysDepart != null) {
                // 执行更新操作
                SysDepart updateSysDepart = this.dtDepartmentToSysDepart(departmentTree, sysDepart);
                if (sysParentId != null) {
                    updateSysDepart.setParentId(sysParentId);
                }
                try {
                    sysDepartService.updateDepartDataById(updateSysDepart, username);
                    String str = String.format("部门 %s 更新成功!", updateSysDepart.getDepartName());
                    syncInfo.addSuccessInfo(str);
                } catch (Exception e) {
                    this.syncDepartCollectErrInfo(e, departmentTree, syncInfo);
                }
                if (departmentTree.hasChildren()) {
                    // 紧接着同步子级
                    this.syncDepartmentToLocalRecursion(departmentTree.getChildren(), updateSysDepart.getId(), username, syncInfo, accessToken);
                }
            } else {
                // 执行新增操作
                SysDepart newSysDepart = this.dtDepartmentToSysDepart(departmentTree, null);
                if (sysParentId != null) {
                    newSysDepart.setParentId(sysParentId);
                }
                try {
                    sysDepartService.saveDepartData(newSysDepart, username);
                    // 更新钉钉 source_identifier
                    Department updateDtDepart = new Department();
                    updateDtDepart.setDept_id(departmentTree.getDept_id());
                    updateDtDepart.setSource_identifier(newSysDepart.getId());
                    Response response = JdtDepartmentAPI.update(updateDtDepart, accessToken);
                    if (!response.isSuccess()) {
                        throw new RuntimeException(response.getErrmsg());
                    }
                    String str = String.format("部门 %s 创建成功!", newSysDepart.getDepartName());
                    syncInfo.addSuccessInfo(str);
                } catch (Exception e) {
                    this.syncDepartCollectErrInfo(e, departmentTree, syncInfo);
                }
                // 紧接着同步子级
                if (departmentTree.hasChildren()) {
                    this.syncDepartmentToLocalRecursion(departmentTree.getChildren(), newSysDepart.getId(), username, syncInfo, accessToken);
                }
            }
        }
    }
}
Also used : Response(com.jeecg.dingtalk.api.core.response.Response) Department(com.jeecg.dingtalk.api.department.vo.Department) JdtDepartmentTreeVo(org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

Department (com.jeecg.dingtalk.api.department.vo.Department)21 SyncInfoVo (org.jeecg.modules.system.vo.thirdapp.SyncInfoVo)10 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)9 Response (com.jeecg.dingtalk.api.core.response.Response)9 User (com.jeecg.dingtalk.api.user.vo.User)9 JdtDepartmentTreeVo (org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo)9 JSONObject (com.alibaba.fastjson.JSONObject)6 ArrayList (java.util.ArrayList)6 SysDepartTreeModel (org.jeecg.modules.system.model.SysDepartTreeModel)6 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)6 JdtBaseAPI (com.jeecg.dingtalk.api.base.JdtBaseAPI)3 AccessToken (com.jeecg.dingtalk.api.core.vo.AccessToken)3 PageResult (com.jeecg.dingtalk.api.core.vo.PageResult)3 JdtDepartmentAPI (com.jeecg.dingtalk.api.department.JdtDepartmentAPI)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 ContactUser (com.jeecg.dingtalk.api.oauth2.vo.ContactUser)3 JdtUserAPI (com.jeecg.dingtalk.api.user.JdtUserAPI)3