liusheng
2025-03-26 fa132afa3a6942a48002c8e36e9ee47de13ee005
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysMenuServiceImpl.java
@@ -12,6 +12,7 @@
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
@@ -47,6 +48,10 @@
    @Autowired
    private SysRoleMenuMapper roleMenuMapper;
    @Value("${isAdmin}")
    private List<Long> isAdmin;
    /**
     * 根据用户查询系统菜单列表
     *
@@ -71,7 +76,7 @@
        if (SysUser.isAdmin(userId)) {
            menuList = menuMapper.selectMenuList(menu);
        } else {
            menu.getParams().put("userId" , userId);
            menu.getParams().put("userId", userId);
            menuList = menuMapper.selectMenuListByUserId(menu);
        }
        return menuList;
@@ -122,7 +127,8 @@
    @Override
    public List<SysMenu> selectMenuTreeByUserId(Long userId) {
        List<SysMenu> menus = null;
        if (SecurityUtils.isAdmin(userId)) {
//        if (SecurityUtils.isAdmin(userId)) {
        if (userId != null && isAdmin.contains(userId)) {
            menus = menuMapper.selectMenuTreeAll();
        } else {
            menus = menuMapper.selectMenuTreeByUserId(userId);
@@ -150,7 +156,7 @@
     */
    @Override
    public List<RouterVo> buildMenus(List<SysMenu> menus) {
        log.error("buildMenus的入参为:{}",menus);
        log.error("buildMenus的入参为:{}", menus);
        List<RouterVo> routers = new LinkedList<RouterVo>();
        for (SysMenu menu : menus) {
            RouterVo router = new RouterVo();
@@ -159,7 +165,7 @@
            router.setPath(getRouterPath(menu));
            router.setComponent(getComponent(menu));
            router.setQuery(menu.getQuery());
            router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1" , menu.getIsCache()), menu.getPath()));
            router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
            List<SysMenu> cMenus = menu.getChildren();
            if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
                router.setAlwaysShow(true);
@@ -172,7 +178,7 @@
                children.setPath(menu.getPath());
                children.setComponent(menu.getComponent());
                children.setName(StringUtils.capitalize(menu.getPath()));
                children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1" , menu.getIsCache()), menu.getPath()));
                children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
                children.setQuery(menu.getQuery());
                childrenList.add(children);
                router.setChildren(childrenList);
@@ -191,7 +197,7 @@
            }
            routers.add(router);
        }
        log.error("----------routers的入参为:{}",routers);
        log.error("----------routers的入参为:{}", routers);
        for (RouterVo routerVo : routers) {
            List<String> childName = new ArrayList<>();
            List<RouterVo> childrens = routerVo.getChildren();
@@ -478,6 +484,6 @@
     * @return 替换后的内链域名
     */
    public String innerLinkReplaceEach(String path) {
        return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."}, new String[]{"" , "" , "" , "/"});
        return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."}, new String[]{"", "", "", "/"});
    }
}