Search in sources :

Example 1 with JdtDepartmentTreeVo

use of org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo in project jeecg-boot by jeecgboot.

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);
                    // 2 = 组织机构
                    newSysDepart.setOrgCategory("2");
                } else {
                    // 1 = 公司
                    newSysDepart.setOrgCategory("1");
                }
                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)

Example 2 with JdtDepartmentTreeVo

use of org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo 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 3 with JdtDepartmentTreeVo

use of org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo 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)

Example 4 with JdtDepartmentTreeVo

use of org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo in project kms 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)

Example 5 with JdtDepartmentTreeVo

use of org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo in project jeecg-boot by jeecgboot.

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)

Aggregations

Department (com.jeecg.dingtalk.api.department.vo.Department)6 JdtDepartmentTreeVo (org.jeecg.modules.system.vo.thirdapp.JdtDepartmentTreeVo)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)3 Response (com.jeecg.dingtalk.api.core.response.Response)3 SyncInfoVo (org.jeecg.modules.system.vo.thirdapp.SyncInfoVo)3 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3