refactor(department): 优化部门层级绑定逻辑并添加部门属性
- 修改bindParent方法参数名以提高代码可读性 - 在bindParent方法中添加重复检查避免循环引用 - 创建treeDepartments副本确保数据完整性 - 调整TBaseDepartment类中导入语句顺序 - 添加hasChild和hasManager两个新字段用于标识部门状态
This commit is contained in:
parent
5bf26c76d5
commit
81d10ba5d1
|
|
@ -3,12 +3,13 @@ package com.nflg.mobilebroken.repository.entity;
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 部门表
|
* 部门表
|
||||||
|
|
@ -85,4 +86,14 @@ public class TBaseDepartment implements Serializable {
|
||||||
* 更新时间
|
* 更新时间
|
||||||
*/
|
*/
|
||||||
private LocalDateTime dataModifyTime;
|
private LocalDateTime dataModifyTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否有下级
|
||||||
|
*/
|
||||||
|
private boolean hasChild;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否已设置管理者
|
||||||
|
*/
|
||||||
|
private boolean hasManager;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -465,7 +465,8 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||||
Set<TBaseDepartment> searchDepartments = departments.stream()
|
Set<TBaseDepartment> searchDepartments = departments.stream()
|
||||||
.filter(d -> searchUsers.stream().map(AdminUser::getDepartmentId).anyMatch(dt -> Objects.equals(d.getId(), dt)))
|
.filter(d -> searchUsers.stream().map(AdminUser::getDepartmentId).anyMatch(dt -> Objects.equals(d.getId(), dt)))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
searchDepartments.forEach(d -> bindParent(d, searchDepartments, departments));
|
Set<TBaseDepartment> treeDepartments = new HashSet<>(searchDepartments);
|
||||||
|
searchDepartments.forEach(d -> bindParent(d, treeDepartments, departments));
|
||||||
List<TBaseDepartment> rootDepartments = searchDepartments.stream()
|
List<TBaseDepartment> rootDepartments = searchDepartments.stream()
|
||||||
.filter(d -> d.getDeptParentId() == 0)
|
.filter(d -> d.getDeptParentId() == 0)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
@ -506,13 +507,14 @@ public class AdminUserServiceImpl extends ServiceImpl<AdminUserMapper, AdminUser
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindParent(TBaseDepartment department, Set<TBaseDepartment> vos, List<TBaseDepartment> departments) {
|
private void bindParent(TBaseDepartment department, Set<TBaseDepartment> treeDepartments, List<TBaseDepartment> departments) {
|
||||||
Set<TBaseDepartment> parents = departments.stream()
|
Set<TBaseDepartment> parents = departments.stream()
|
||||||
.filter(d -> Objects.equals(d.getId(), department.getDeptParentId()))
|
.filter(d -> Objects.equals(d.getId(), department.getDeptParentId()))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
parents.removeIf(p -> treeDepartments.stream().anyMatch(v -> Objects.equals(p.getId(), v.getId())));
|
||||||
if (CollectionUtil.isNotEmpty(parents)) {
|
if (CollectionUtil.isNotEmpty(parents)) {
|
||||||
vos.addAll(parents);
|
treeDepartments.addAll(parents);
|
||||||
parents.forEach(p -> bindParent(p, vos, departments));
|
parents.forEach(p -> bindParent(p, treeDepartments, departments));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue