From 648b145189e6568613bac535365ad6a40a43a405 Mon Sep 17 00:00:00 2001
From: houzhongjian <houzhongyi@126.com>
Date: 星期四, 05 十二月 2024 17:04:47 +0800
Subject: [PATCH] 1、脚手架查询应用菜单接口修改 2、应用菜单二级菜单是目录时,path前面拼”/“解决前端加载不出路由的bug

---
 iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/auth/AuthController.java |   56 +++++++++++++++++++++++++++++++++++++++++++-------------
 iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/dal/mysql/dict/DictTypeMapper.java        |    2 +-
 2 files changed, 44 insertions(+), 14 deletions(-)

diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/auth/AuthController.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/auth/AuthController.java
index 7c3a9ef..d64c0ca 100644
--- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/auth/AuthController.java
+++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/controller/admin/auth/AuthController.java
@@ -142,6 +142,33 @@
         return success(AuthConvert.INSTANCE.convert(user, roles, menuList));
     }
 
+    @GetMapping("/get-app-permission-info")
+    @Operation(summary = "脚手架获取登录用户的权限信息")
+    public CommonResult<AuthPermissionInfoRespVO> getAppPermissionInfo() {
+        // 1.1 获得用户信息
+        AdminUserDO user = userService.getUser(getLoginUserId());
+        if (user == null) {
+            return success(null);
+        }
+
+        // 1.2 获得角色列表
+        Set<Long> roleIds = permissionService.getUserRoleIdListByUserId(getLoginUserId());
+        if (CollUtil.isEmpty(roleIds)) {
+            return success(AuthConvert.INSTANCE.convert(user, Collections.emptyList(), Collections.emptyList()));
+        }
+        List<RoleDO> roles = roleService.getRoleList(roleIds);
+        roles.removeIf(role -> !CommonStatusEnum.ENABLE.getStatus().equals(role.getStatus())); // 移除禁用的角色
+
+        // 1.3 获得菜单列表
+        Set<Long> menuIds = permissionService.getRoleMenuListByRoleId(convertSet(roles, RoleDO::getId));
+        List<MenuDO> menuList = menuService.getMenuList(menuIds);
+        menuList = menuService.filterDisableMenus(menuList);
+        menuList = menuService.filterMenus(menuList, "app");
+
+        // 2. 拼接结果返回
+        return success(AuthConvert.INSTANCE.convert(user, roles, menuList));
+    }
+
     @GetMapping("/get-app-permission")
     @Operation(summary = "获取登录用户的app权限信息")
     public CommonResult<List<AppRespVO>> getAppPermission() {
@@ -214,20 +241,23 @@
         List<MenuDO> tempChildren = new LinkedList<>();
         //为每一个二级菜单增加一个隐藏父级目录
         children.stream().forEach(menu -> {
-            if (menu.getType().equals(MenuTypeEnum.MENU.getType()) && menu.getParentId().equals(menuDO.getId())) {
-                MenuDO parentMenu = BeanUtils.toBean(menu, MenuDO.class);
-                parentMenu.setId(System.currentTimeMillis() + (int) (Math.random() * (99999 - 10000 + 1)) + 10000);
-                parentMenu.setType(MenuTypeEnum.DIR.getType());
-                parentMenu.setVisible(true);
-                parentMenu.setAlwaysShow(false);
-                parentMenu.setParentId(menuDO.getId());
-                parentMenu.setPath("/");
-                menu.setParentId(parentMenu.getId());
-                tempChildren.add(parentMenu);
-                tempChildren.add(menu);
-            } else {
-                tempChildren.add(menu);
+            if (menu.getParentId().equals(menuDO.getId())) {
+                if(menu.getType().equals(MenuTypeEnum.MENU.getType())) {
+                    MenuDO parentMenu = BeanUtils.toBean(menu, MenuDO.class);
+                    parentMenu.setId(System.currentTimeMillis() + (int) (Math.random() * (99999 - 10000 + 1)) + 10000);
+                    parentMenu.setType(MenuTypeEnum.DIR.getType());
+                    parentMenu.setVisible(true);
+                    parentMenu.setAlwaysShow(false);
+                    parentMenu.setParentId(menuDO.getId());
+                    parentMenu.setPath("/");
+                    menu.setParentId(parentMenu.getId());
+                    tempChildren.add(parentMenu);
+                } else if(menu.getType().equals(MenuTypeEnum.DIR.getType())) {
+                    // 为应用菜单二级目录前增加“/”
+                    menu.setPath("/" + menu.getPath());
+                }
             }
+            tempChildren.add(menu);
         });
         menuVOS = AuthConvert.INSTANCE.buildMenuTree(tempChildren, menuDO.getId(), menuDO.getPath(), info.getType());
         // 2. 拼接结果返回
diff --git a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/dal/mysql/dict/DictTypeMapper.java b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/dal/mysql/dict/DictTypeMapper.java
index 6218603..8f51710 100644
--- a/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/dal/mysql/dict/DictTypeMapper.java
+++ b/iailab-module-system/iailab-module-system-biz/src/main/java/com/iailab/module/system/dal/mysql/dict/DictTypeMapper.java
@@ -28,7 +28,7 @@
     }
 
     default DictTypeDO selectByName(String name) {
-        return selectOne(DictTypeDO::getName, name);
+        return selectOne(new LambdaQueryWrapperX<DictTypeDO>().eq(DictTypeDO::getName, name).eq(DictTypeDO::getDeleted, 0));
     }
 
     @Update("UPDATE system_dict_type SET deleted = 1, deleted_time = #{deletedTime} WHERE id = #{id}")

--
Gitblit v1.9.3