当前位置:网站首页>递归查询单表-单表树结构-(自用)
递归查询单表-单表树结构-(自用)
2022-07-31 03:00:00 【杰拉德·皮克·谢】
单表递归应用场景,树结构无限下沉(如下图)

表结构 parent_id(父亲id)

实体类
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@TableName(value = "t_dept")
public class OrgDept implements Serializable {
/** * 组织架构 */
@TableId(value = "org_id", type = IdType.INPUT)
private Long orgId;
/** * 组织code */
@TableField(value = "org_code")
private String orgCode;
/** * 组织名称 */
@TableField(value = "org_name")
private String orgName;
/** * 父节点 */
@TableField(value = "parent_id")
private Long parentId;
/** * 组织描述 */
@TableField(value = "org_address")
private String orgAddress;
/** * 创建时间 */
@TableField(value = "create_time")
private Date createTime;
/** * 创建人 */
@TableField(value = "create_by")
private String createBy;
/** * 电话号码 */
@TableField(value = "phone_number")
private String phoneNumber;
/** * 排序 */
@TableField(value = "order_number")
private Integer orderNumber;
@TableField(exist = false)
private String parentName;
@TableField(exist = false)
List<OrgDept> children;
/** * 部门id集合 */
@TableField(exist = false)
List<Integer> depaIds;
private static final long serialVersionUID = 1L;
}
impl 递归开始
listRoleOrgDept
@Override
@Transactional(rollbackFor = Exception.class)
public List<OrgDept> listRoleOrgDept(Long deptId) {
//
List<Long> depaIds = new ArrayList<>();
// x_1 部门全部列表
List<OrgDept> orgDepts = new LambdaQueryChainWrapper<>(orgDeptMapper)
.list();
//定义返回对象子父嵌套
List<OrgDept> parentMenu;
// 点击页面时会捕捉当前节点拿到节点id 如果没有默认全部
if (deptId == null) {
// 获取全部列表
parentMenu = orgDepts.stream().filter(e -> e.getParentId().equals(0L)).collect(Collectors.toList());
//
for (OrgDept sysMenu : parentMenu) {
depaIds.add(sysMenu.getOrgId());
setChild(sysMenu, orgDepts, depaIds);
}
} else {
parentMenu = pIdLive(deptId, orgDepts, depaIds);
}
return parentMenu;
}
边栏推荐
- Draw Your Cards
- AI software development process in medical imaging field
- SQL注入 Less47(报错注入) 和Less49(时间盲注)
- SQL injection Less47 (error injection) and Less49 (time blind injection)
- 【C语言】进制转换一般方法
- golang GUI for nuxui — HelloWorld
- 11. Redis implements follow, unfollow, and follow and follower lists
- 12 磁盘相关命令
- 【HCIP】ISIS
- 5. SAP ABAP OData 服务如何支持 $filter (过滤)操作
猜你喜欢

11. Redis implements follow, unfollow, and follow and follower lists

YOLOV5 study notes (3) - detailed explanation of network module

Difference between CMOS and TTL?

Maximum area of solar panel od js

Intel's software and hardware optimization empowers Neusoft to accelerate the arrival of the era of smart medical care

The simulation application of common mode inductance is here, full of dry goods for everyone

CorelDRAW2022 streamlined Asia Pacific new features in detail

【C语言】求两个整数m和n的最大公因数和最小公倍数之和一般方法,经典解法

【C语言】三子棋(经典解法+一览图)

JS 函数 this上下文 运行时点语法 圆括号 数组 IIFE 定时器 延时器 self.备份上下文 call apply
随机推荐
C#远程调试
YOLOV5 study notes (3) - detailed explanation of network module
字体压缩神器font-spider的使用
10. Redis implements likes (Set) and obtains the total number of likes
Android's webview cache related knowledge collection
MPPT solar charge controller data collection - through the gateway acquisition capacity battery SOC battery voltage, wi-fi
SonarQube的BUG定义
LeetCode 1161 The largest element in the layer and the LeetCode road of [BFS binary tree] HERODING
Office automation case: how to automatically generate period data?
什么是分布式锁?实现分布式锁的三种方式
IIR滤波器和FIR滤波器
点云DBSCAN聚类(MATLAB,非内置函数)
共模电感的仿真应用来了,满满的干货送给大家
Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
4. Sensitive word filtering (prefix tree)
【Android】Room —— SQLite的替代品
STM32问题合集
10、Redis实现点赞(Set)和获取总点赞数
The Sad History of Image Processing Technology
TCP/IP four-layer model