@Override
public List getCateGoryTree() {
List categoryEntities = baseDao.selectList(null);
List<CategoryEntity> collect = categoryEntities.stream().filter(entity ->
entity.getParentCid() == 0 // 获取父类
).map(menu->{ // 映射子类
menu.setChild(getChildMenu(menu,categoryEntities)); // 调用递归方法子类
return menu;
}).sorted((m1,m2)->{
return ( m1.getSort()==null?0:m1.getSort())-(m2.getSort()==null?0:m2.getSort());
}).collect(Collectors.toList());
return collect;
}
//递归子类
private List<CategoryEntity> getChildMenu(CategoryEntity root,List<CategoryEntity> all){
List<CategoryEntity> collect = all.stream().filter(entity -> {
return entity.getParentCid() == root.getCatId();
}).map(entity->{
entity.setChild(getChildMenu(entity,all)); // 递归获取层级子类
return entity;
}).sorted((m1,m2)->{
return (m1.getSort()==null?0:m1.getSort())-(m2.getSort()==null?0:m2.getSort());
}).collect(Collectors.toList());
return collect;
}