mirror of https://gitee.com/stylefeng/roses
【7.2.5】【org】获取部门上级组织
parent
07b1f8e761
commit
566f53600f
|
@ -71,4 +71,15 @@ public interface OrganizationServiceApi {
|
|||
*/
|
||||
List<OrganizationTreeNode> getDeptOrgTree(Long orgId);
|
||||
|
||||
/**
|
||||
* 获取指定组织机构的上级组织机构是什么
|
||||
*
|
||||
* @param orgId 指定机构id
|
||||
* @param parentLevelNum 上级机构的层级数,从0开始
|
||||
* @return 上级机构的id
|
||||
* @author fengshuonan
|
||||
* @date 2022/9/18 15:02
|
||||
*/
|
||||
Long getParentLevelOrgId(Long orgId, Integer parentLevelNum);
|
||||
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ import cn.hutool.core.bean.copier.CopyOptions;
|
|||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.stylefeng.roses.kernel.auth.api.context.LoginContext;
|
||||
|
@ -412,6 +413,48 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
|
|||
return new DefaultTreeBuildFactory<OrganizationTreeNode>().doTreeBuild(treeNodeList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getParentLevelOrgId(Long orgId, Integer parentLevelNum) {
|
||||
|
||||
if (ObjectUtil.isEmpty(orgId) || ObjectUtil.isEmpty(parentLevelNum)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 如果上级层数为0,则直接返回参数的orgId,代表同级别组织机构
|
||||
if (parentLevelNum == 0) {
|
||||
return orgId;
|
||||
}
|
||||
|
||||
// 获取当前部门的所有父级id
|
||||
HrOrganization hrOrganization = this.getById(orgId);
|
||||
if (hrOrganization == null || StrUtil.isEmpty(hrOrganization.getOrgPids())) {
|
||||
return null;
|
||||
}
|
||||
String orgParentIdListStr = hrOrganization.getOrgPids();
|
||||
String[] orgParentIdList = orgParentIdListStr.split(",");
|
||||
String[] orgParentIdListReverse = ArrayUtil.reverse(orgParentIdList);
|
||||
|
||||
// 根据请求参数,需要从orgParentIdListReverse获取的下表
|
||||
int needGetArrayIndex = parentLevelNum - 1;
|
||||
|
||||
// orgParentIdListReverse最大能提供的下表,这里为什么是-2,因为所有组织机构,最顶级的父级id是[-1],[-1]是不存在
|
||||
int maxCanGetIndex = orgParentIdListReverse.length - 2;
|
||||
|
||||
// 如果没有最顶级的上级,则他本身就是最顶级上级
|
||||
if (maxCanGetIndex < 0) {
|
||||
return orgId;
|
||||
}
|
||||
|
||||
// 根据参数传参,进行获取上级的操作
|
||||
String orgIdString;
|
||||
if (needGetArrayIndex <= (maxCanGetIndex)) {
|
||||
orgIdString = orgParentIdListReverse[needGetArrayIndex];
|
||||
} else {
|
||||
orgIdString = orgParentIdListReverse[maxCanGetIndex];
|
||||
}
|
||||
return Long.valueOf(orgIdString);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建组织架构的通用条件查询wrapper
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue