WangHan
2025-04-03 a1b85ef72062ca80db35546e4216dd564f3e0f57
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package com.iplatform.base.controller;
 
import com.iplatform.base.SystemController;
import com.iplatform.base.callback.SecurityCallback;
import com.iplatform.base.service.RoleServiceImpl;
import com.iplatform.base.util.MenuUtils;
import com.iplatform.base.util.menu.SystemMenu;
import com.iplatform.model.po.S_role;
import com.iplatform.model.po.S_user_core;
import com.walker.infrastructure.utils.StringUtils;
import com.walker.web.ResponseValue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
@RestController
public class TestMenuController extends SystemController {
 
    @Autowired
    private RoleServiceImpl roleService;
 
    @RequestMapping("/test/menu/show")
    public ResponseValue showUserMenuList(long userId){
        SecurityCallback securityCallback = this.getPlatformCallback(SecurityCallback.class);
        List<SystemMenu> menuList = null;
 
        S_user_core user = this.getUserCacheProvider().getUser(userId);
 
        List<S_role> roleList = roleService.queryUserRoleList(userId);
        List<String> roleIdList = new ArrayList<>();
        if(!StringUtils.isEmptyList(roleList)){
            for(S_role role : roleList){
                roleIdList.add(role.getRole_id().toString());
            }
        }
        menuList = securityCallback.loadUserMenu(user, roleIdList);
        if (menuList != null) {
            // 过滤掉按钮权限,前端只需要菜单,按钮权限在permisstion中控制
            SystemMenu menu = null;
            for (Iterator<SystemMenu> it = menuList.iterator(); it.hasNext(); ) {
                menu = it.next();
                // 1.去掉按钮菜单,同时,停用的菜单也要去掉。2023-05-14
                // 2.不能展示的也要去掉,is_show = 0
                if (menu.getMenu_type().equals(MenuUtils.MENU_TYPE_BUTTON)
                        || menu.getStatus().equals(MenuUtils.MENU_STATUS_DISABLED)
                        || menu.getVisible().equals(MenuUtils.MENU_INVISIBLE)) {
                    it.remove();
                }
            }
        }
        return ResponseValue.success(menuList);
    }
}