资料库代码提交

This commit is contained in:
hzj
2024-09-18 18:43:13 +08:00
parent 78ba6903c6
commit bb5d1d3335
2 changed files with 5 additions and 0 deletions

View File

@@ -83,5 +83,8 @@ public class LibAlgorithm extends BaseEntity {
@TableField(exist = false)
private List<LibAlgorithm> children;
@TableField(exist = false)
private Integer level;
}

View File

@@ -93,12 +93,14 @@ public class LibAlgorithmServiceImpl extends ServiceImpl<LibAlgorithmMapper, Lib
List<LibAlgorithm> libAlgorithmList = this.lambdaQuery().eq(LibAlgorithm::getStatus,1).list();
List<LibAlgorithm> tree = libAlgorithmList.stream().filter(item -> item.getPid().equals("0")).peek(item -> {
item.setLevel(1);
item.setChildren(getChildren(item, libAlgorithmList));
}).collect(Collectors.toList());
return tree;
}
private List<LibAlgorithm> getChildren(LibAlgorithm libAlgorithm, List<LibAlgorithm> all) {
return all.stream().filter(item -> item.getPid().equals(libAlgorithm.getId())).peek(item -> {
item.setLevel(libAlgorithm.getLevel()+1);
item.setChildren(getChildren(item, all));
}).collect(Collectors.toList());
}