use of org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo in project jeecg-boot by jeecgboot.
the class ThirdAppWechatEnterpriseServiceImpl method deleteDepartRecursion.
// 递归删除部门以及子部门,由于企业微信不允许删除带有成员和子部门的部门,所以需要递归删除下子部门,然后把部门成员移动端根部门下
private void deleteDepartRecursion(List<JwDepartmentTreeVo> children, String accessToken, boolean ifLocal) {
for (JwDepartmentTreeVo departmentTree : children) {
String depId = departmentTree.getId();
// 过滤根部门
if (!"1".equals(depId)) {
// 判断本地是否有该部门
if (ifLocal) {
LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(SysDepart::getQywxIdentifier, depId);
SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
// 本地有该部门,不删除
if (sysDepart != null) {
if (departmentTree.hasChildren()) {
this.deleteDepartRecursion(departmentTree.getChildren(), accessToken, true);
}
continue;
}
}
// 判断是否有成员,有就移动到根部门
List<User> departUserList = JwUserAPI.getUsersByDepartid(depId, "1", null, accessToken);
if (departUserList != null && departUserList.size() > 0) {
for (User user : departUserList) {
User updateUser = new User();
updateUser.setUserid(user.getUserid());
updateUser.setDepartment(new Integer[] { 1 });
JwUserAPI.updateUser(updateUser, accessToken);
}
}
// 有子部门优先删除子部门
if (departmentTree.hasChildren()) {
this.deleteDepartRecursion(departmentTree.getChildren(), accessToken, false);
}
// 执行删除操作
JwDepartmentAPI.deleteDepart(depId, accessToken);
}
}
}
use of org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo in project jeecg-boot by jeecgboot.
the class ThirdAppWechatEnterpriseServiceImpl 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 = JwDepartmentAPI.getAllDepartment(accessToken);
if (departments == null) {
syncInfo.addFailInfo("企业微信部门信息获取失败!");
return syncInfo;
}
String username = JwtUtil.getUserNameByToken(SpringContextUtils.getHttpServletRequest());
// 将list转为tree
List<JwDepartmentTreeVo> departmentTreeList = JwDepartmentTreeVo.listToTree(departments);
// 递归同步部门
this.syncDepartmentToLocalRecursion(departmentTreeList, null, username, syncInfo);
return syncInfo;
}
use of org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo in project kykms by mahonelau.
the class ThirdAppWechatEnterpriseServiceImpl method syncLocalDepartmentToThirdApp.
@Override
public boolean syncLocalDepartmentToThirdApp(String ids) {
String accessToken = this.getAccessToken();
if (accessToken == null) {
return false;
}
// 获取企业微信所有的部门
List<Department> departments = JwDepartmentAPI.getAllDepartment(accessToken);
if (departments == null) {
return false;
}
// 删除企业微信有但本地没有的部门(以本地部门数据为主)(以为企业微信不能创建同名部门,所以只能先删除)
List<JwDepartmentTreeVo> departmentTreeList = JwDepartmentTreeVo.listToTree(departments);
this.deleteDepartRecursion(departmentTreeList, accessToken, true);
// 获取本地所有部门树结构
List<SysDepartTreeModel> sysDepartsTree = sysDepartService.queryTreeList();
// -- 企业微信不能创建新的顶级部门,所以新的顶级部门的parentId就为1
Department parent = new Department();
parent.setId("1");
// 递归同步部门
departments = JwDepartmentAPI.getAllDepartment(accessToken);
this.syncDepartmentRecursion(sysDepartsTree, departments, parent, accessToken);
return true;
}
use of org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo in project kms by mahonelau.
the class ThirdAppWechatEnterpriseServiceImpl method syncDepartmentToLocalRecursion.
/**
* 递归同步部门到本地
*/
private void syncDepartmentToLocalRecursion(List<JwDepartmentTreeVo> departmentTreeList, String sysParentId, String username, SyncInfoVo syncInfo) {
if (departmentTreeList != null && departmentTreeList.size() != 0) {
for (JwDepartmentTreeVo departmentTree : departmentTreeList) {
String depId = departmentTree.getId();
LambdaQueryWrapper<SysDepart> queryWrapper = new LambdaQueryWrapper<>();
// 根据 qywxIdentifier 字段查询
queryWrapper.eq(SysDepart::getQywxIdentifier, depId);
SysDepart sysDepart = sysDepartService.getOne(queryWrapper);
if (sysDepart != null) {
// 执行更新操作
SysDepart updateSysDepart = this.qwDepartmentToSysDepart(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);
}
} else {
// 执行新增操作
SysDepart newSysDepart = this.qwDepartmentToSysDepart(departmentTree, null);
if (sysParentId != null) {
newSysDepart.setParentId(sysParentId);
}
try {
sysDepartService.saveDepartData(newSysDepart, username);
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);
}
}
}
}
}
use of org.jeecg.modules.system.vo.thirdapp.JwDepartmentTreeVo in project kms by mahonelau.
the class ThirdAppWechatEnterpriseServiceImpl 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 = JwDepartmentAPI.getAllDepartment(accessToken);
if (departments == null) {
syncInfo.addFailInfo("企业微信部门信息获取失败!");
return syncInfo;
}
String username = JwtUtil.getUserNameByToken(SpringContextUtils.getHttpServletRequest());
// 将list转为tree
List<JwDepartmentTreeVo> departmentTreeList = JwDepartmentTreeVo.listToTree(departments);
// 递归同步部门
this.syncDepartmentToLocalRecursion(departmentTreeList, null, username, syncInfo);
return syncInfo;
}
Aggregations