gao.qiang hace 1 año
padre
commit
0f27127b55

+ 18 - 1
base-system/src/main/java/com/ozs/system/service/impl/SysMenuServiceImpl.java

@@ -9,6 +9,10 @@ import java.util.List;
 import java.util.Set;
 import java.util.stream.Collectors;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ozs.system.domain.SysRoleMenu;
+import com.ozs.system.domain.SysUserRole;
+import com.ozs.system.mapper.SysUserRoleMapper;
 import icu.mhb.mybatisplus.plugln.base.service.impl.JoinServiceImpl;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -44,6 +48,8 @@ public class SysMenuServiceImpl extends JoinServiceImpl<SysMenuMapper, SysMenu>
 
     @Autowired
     private SysRoleMenuMapper roleMenuMapper;
+    @Autowired
+    private SysUserRoleMapper sysUserRoleMapper;
 
     /**
      * 根据用户查询系统菜单列表
@@ -120,7 +126,18 @@ public class SysMenuServiceImpl extends JoinServiceImpl<SysMenuMapper, SysMenu>
     @Override
     public List<SysMenu> selectMenuTreeByUserId(Long userId) {
         List<SysMenu> menus = null;
-        if (SecurityUtils.isAdmin(userId)) {
+        boolean stop=false;
+        LambdaQueryWrapper<SysUserRole> wrapper=new LambdaQueryWrapper<>();
+        wrapper.eq(SysUserRole::getUserId,userId);
+        List<SysUserRole> sysUserRoles = sysUserRoleMapper.selectList(wrapper);
+        for (SysUserRole sysUserRole : sysUserRoles) {
+            String roleKey = roleMapper.getRoleKey(sysUserRole.getRoleId());
+            if ("admin".equals(roleKey)){
+                stop=true;
+                break;
+            }
+        }
+        if (SecurityUtils.isAdmin(userId)||stop) {
             menus = menuMapper.selectMenuTreeAll();
         } else {
             menus = menuMapper.selectMenuTreeByUserId(userId);