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;
}
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);
}
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;
}
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);
}
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);
}
}
}
}
}
Aggregations