XiaoRuby
2023-08-24 e0ef38a77c4bbe67d8a9eab46134ed00fb1e8293
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.yuanchu.limslaboratory.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuanchu.limslaboratory.mapper.MenuMapper;
import com.yuanchu.limslaboratory.pojo.Menu;
import com.yuanchu.limslaboratory.service.RoleManagerService;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Author 张宾
 * @Date 2023/8/23
 */
@Service
public class RoleManagerServiceImpl implements RoleManagerService {
 
    @Resource
    private MenuMapper menuMapper;
 
    @Override
    public Object getMenusTree() {
        List<Menu> menus = menuMapper.getMenuList();
        return menus.stream()
                .filter(t -> t.getParentId() == 0)
                .peek((menu) -> menu.setChildren(this.getEnumChildren(menu, menus)))
                .collect(Collectors.toList());
    }
 
 
    private List<Menu> getEnumChildren(Menu root, List<Menu> all) {
        return all.stream()
                .filter(t -> Objects.equals(t.getParentId(), root.getValue()))
                .peek(g -> {
                    //找子菜单
                    g.setChildren(getEnumChildren(g, all));
                })
                .collect(Collectors.toList());
    }
 
}