部门顶级节点逻辑优化

master
RuoYi 5 years ago
parent d677cd11d1
commit 436f8eb737
  1. 2
      ruoyi/src/main/java/com/ruoyi/framework/security/service/TokenService.java
  2. 15
      ruoyi/src/main/java/com/ruoyi/project/system/service/impl/SysDeptServiceImpl.java

@ -124,8 +124,6 @@ public class TokenService
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
if (expireTime - currentTime <= MILLIS_MINUTE_TEN) if (expireTime - currentTime <= MILLIS_MINUTE_TEN)
{ {
String token = loginUser.getToken();
loginUser.setToken(token);
refreshToken(loginUser); refreshToken(loginUser);
} }
} }

@ -49,18 +49,19 @@ public class SysDeptServiceImpl implements ISysDeptService
public List<SysDept> buildDeptTree(List<SysDept> depts) public List<SysDept> buildDeptTree(List<SysDept> depts)
{ {
List<SysDept> returnList = new ArrayList<SysDept>(); List<SysDept> returnList = new ArrayList<SysDept>();
if (StringUtils.isNotEmpty(depts) && StringUtils.isNotNull(depts.stream().findFirst())) List<Long> tempList = new ArrayList<Long>();
for (SysDept dept : depts)
{ {
depts.stream().findFirst().get().setParentId(null); tempList.add(dept.getDeptId());
} }
for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();) for (Iterator<SysDept> iterator = depts.iterator(); iterator.hasNext();)
{ {
SysDept t = (SysDept) iterator.next(); SysDept dept = (SysDept) iterator.next();
// 根据传入的某个父节点ID,遍历该父节点的所有子节点 // 如果是顶级节点, 遍历该父节点的所有子节点
if (StringUtils.isNull(t.getParentId()) || t.getParentId() == 0) if (!tempList.contains(dept.getParentId()))
{ {
recursionFn(depts, t); recursionFn(depts, dept);
returnList.add(t); returnList.add(dept);
} }
} }
if (returnList.isEmpty()) if (returnList.isEmpty())

Loading…
Cancel
Save