| |
| @Override |
| public List<CategoryEntity> listWithTree() |
| { |
| |
| List<CategoryEntity> entities = baseMapper.selectList(null); |
| |
| |
| List<CategoryEntity> levelMenus = entities.stream() |
| |
| .filter(c -> c.getParentCid() == 0) |
| .map(m -> |
| { |
| |
| m.setChildren(getChildrens(m, entities)); |
| return m; |
| }).sorted((m, m2) -> |
| { |
| |
| return ((m.getSort() == null ? 0 : m.getSort()) - (m2.getSort() == null ? 0 : m2.getSort())); |
| |
| }).collect(Collectors.toList()); |
| |
| return levelMenus; |
| } |
| |
| |
| private List<CategoryEntity> getChildrens(CategoryEntity root, List<CategoryEntity> all) |
| { |
| List<CategoryEntity> children = all.stream().filter(c -> |
| { |
| |
| return c.getParentCid() == root.getCatId(); |
| }).map(m -> { |
| |
| m.setChildren(getChildrens(m, all)); |
| return m; |
| }).sorted((m, m2) -> { |
| |
| return ((m.getSort() == null ? 0 : m.getSort()) - (m2.getSort() == null ? 0 : m2.getSort())); |
| |
| }).collect(Collectors.toList()); |
| return children; |
| } |