当前位置:网站首页>递归查询单表-单表树结构-(自用)
递归查询单表-单表树结构-(自用)
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;
}
边栏推荐
- Pythagorean tuple od js
- TCP/IP four-layer model
- 分布式与集群是什么 ? 区别是什么?
- Classic linked list OJ strong training problem - fast and slow double pointer efficient solution
- 点云DBSCAN聚类(MATLAB,非内置函数)
- Installation of mysql5.7.37 under CentOS7 [perfect solution]
- 【C语言】进制转换一般方法
- LeetCode Daily Question 2022/7/25-2022/7/31
- The use of font compression artifact font-spider
- Basic learning about Redis related content
猜你喜欢
Crypto Firms Offer Offer To Theft Hackers: Keep A Little, Give The Rest
The application of AI in the whole process of medical imaging equipment
Installation, start and stop of redis7 under Linux
Live Preview | KDD2022 Doctoral Dissertation Award Champion and Runner-up Dialogue
Hanyuan Hi-Tech 8-channel HDMI integrated multi-service high-definition video optical transceiver 8-channel HDMI video + 8-channel two-way audio + 8-channel 485 data + 8-channel E1 + 32-channel teleph
10. Redis implements likes (Set) and obtains the total number of likes
【编译原理】词法分析程序设计原理与实现
f.grid_sample
软件积累 -- 截图软件ScreenToGif
Project (5) - Small target detection tph-yolov5
随机推荐
Local area network computer hardware information collection tool
15. Website Statistics
【shell基础】判断目录是否为空
Difference between CMOS and TTL?
什么是分布式锁?实现分布式锁的三种方式
7、私信列表
php 网站的多语言设置(IP地址区分国内国外)
学习DAVID数据库(1)
YOLOV5 study notes (2) - environment installation + operation + training
YOLOV5 study notes (3) - detailed explanation of network module
局域网电脑硬件信息收集工具
What is a distributed lock?Three ways of implementing distributed lock
11. Redis implements follow, unfollow, and follow and follower lists
Draw Your Cards
Project (5) - Small target detection tph-yolov5
SonarQube的BUG定义
print task sorting js od huawei
软件积累 -- 截图软件ScreenToGif
CloudCompare&PCL 计算两个点云之间的重叠度
SQL injection Less54 (limited number of SQL injection + union injection)