Compare commits

...

4 Commits

Author SHA1 Message Date
试着奔跑的菜鸟 878de4602b
Pre Merge pull request !373 from 试着奔跑的菜鸟/master 2025-03-10 03:45:51 +00:00
若依 a6bcebb62b
!397 修复actuator暴漏问题
Merge pull request !397 from 威士忌的纯度/N/A
2025-03-10 03:45:34 +00:00
威士忌的纯度 1cb262daa3
修复actuator暴漏问题
Signed-off-by: 威士忌的纯度 <whr888888@vip.qq.com>
2025-03-07 10:22:52 +00:00
试着奔跑的菜鸟 ad34bc5698
优化部门管理组装树型结构数据
1. 使用Set集合代替List判断元素是否存在
2. 修改recursionFn中通过map集合的内容判断是否有子元素的方法

Signed-off-by: 试着奔跑的菜鸟 <846933465@qq.com>
2024-05-15 00:24:15 +00:00
2 changed files with 19 additions and 19 deletions

View File

@ -29,7 +29,7 @@ http {
}
# 避免actuator暴露
if ($request_uri ~ "/actuator") {
if ($uri ~ "/actuator") {
return 403;
}

View File

@ -3,6 +3,7 @@ package com.ruoyi.system.service.impl;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@ -68,21 +69,20 @@ public class SysDeptServiceImpl implements ISysDeptService
* @return
*/
@Override
public List<SysDept> buildDeptTree(List<SysDept> depts)
{
public List<SysDept> buildDeptTree(List<SysDept> depts) {
List<SysDept> returnList = new ArrayList<SysDept>();
List<Long> tempList = depts.stream().map(SysDept::getDeptId).collect(Collectors.toList());
for (SysDept dept : depts)
{
// 按父级分组
Map<Long, List<SysDept>> groupByParentIdDepts = depts.stream().filter(dept -> dept.getParentId() != null)
.collect(Collectors.groupingBy(SysDept::getParentId));
for (SysDept dept : depts) {
// 如果是顶级节点, 遍历该父节点的所有子节点
if (!tempList.contains(dept.getParentId()))
{
recursionFn(depts, dept);
if (!tempList.contains(dept.getParentId())) {
recursionFn(groupByParentIdDepts, dept);
returnList.add(dept);
}
}
if (returnList.isEmpty())
{
if (returnList.isEmpty()) {
returnList = depts;
}
return returnList;
@ -296,17 +296,17 @@ public class SysDeptServiceImpl implements ISysDeptService
/**
*
*/
private void recursionFn(List<SysDept> list, SysDept t)
{
private void recursionFn(Map<Long, List<SysDept>> groupByParentIdDepts, SysDept t) {
// 得到子节点列表
List<SysDept> childList = getChildList(list, t);
t.setChildren(childList);
for (SysDept tChild : childList)
{
if (hasChild(list, tChild))
{
recursionFn(list, tChild);
List<SysDept> childList = groupByParentIdDepts.get(t.getDeptId());
if (childList != null) {
t.setChildren(childList);
// 为每个子节点递归找到子节点
for (SysDept tChild : childList) {
recursionFn(groupByParentIdDepts, tChild);
}
} else {
t.setChildren(new ArrayList<>(0));
}
}