【7.2.5】【org】更新获取上级部门的方法

pull/37/head
fengshuonan 2022-10-01 13:51:51 +08:00
parent e84f8a2ca7
commit aff8e14eae
2 changed files with 73 additions and 38 deletions

View File

@ -73,13 +73,28 @@ public interface OrganizationServiceApi {
/**
*
* <p>
*
*
* @param orgId id
* @param parentLevelNum 0
* @param parentLevelNum 00
* @return id
* @author fengshuonan
* @date 2022/9/18 15:02
*/
Long getParentLevelOrgId(Long orgId, Integer parentLevelNum);
/**
*
* <p>
*
*
* @param orgId id
* @param highestLevelNum 00
* @return id
* @author fengshuonan
* @date 2022/10/1 11:37
*/
Long getHighestLevelOrgId(Long orgId, Integer highestLevelNum);
}

View File

@ -415,44 +415,12 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
@Override
public Long getParentLevelOrgId(Long orgId, Integer parentLevelNum) {
return calcParentOrgId(orgId, parentLevelNum, true);
}
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);
@Override
public Long getHighestLevelOrgId(Long orgId, Integer highestLevelNum) {
return calcParentOrgId(orgId, highestLevelNum, false);
}
/**
@ -589,4 +557,56 @@ public class HrOrganizationServiceImpl extends ServiceImpl<HrOrganizationMapper,
return this.list(queryWrapper);
}
/**
* id
*
* @param orgId id
* @param parentLevelNum 00
* @param reverse true-false-
* @author fengshuonan
* @date 2022/10/1 11:45
*/
private Long calcParentOrgId(Long orgId, Integer parentLevelNum, boolean reverse) {
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(",");
if (reverse) {
orgParentIdList = ArrayUtil.reverse(orgParentIdList);
}
// 根据请求参数需要从orgParentIdList获取的下标
int needGetArrayIndex = parentLevelNum - 1;
// orgParentIdList最大能提供的下表这里为什么是-2因为所有组织机构最顶级的父级id是[-1][-1]是不存在
int maxCanGetIndex = orgParentIdList.length - 2;
// 如果没有最顶级的上级,则他本身就是最顶级上级
if (maxCanGetIndex < 0) {
return orgId;
}
// 根据参数传参,进行获取上级的操作
String orgIdString;
if (needGetArrayIndex <= (maxCanGetIndex)) {
orgIdString = orgParentIdList[needGetArrayIndex];
} else {
orgIdString = orgParentIdList[maxCanGetIndex];
}
return Long.valueOf(orgIdString);
}
}