Selaa lähdekoodia

获取菜单信息

zhoutg 6 vuotta sitten
vanhempi
commit
2253bc968c

+ 24 - 2
user-service/src/main/java/com/diagbot/facade/UserFacade.java

@@ -253,12 +253,34 @@ public class UserFacade extends UserServiceImpl {
         loginDTO.setOrganization(org);
         //添加菜单信息
         List<MenuWrapper> menuList = menuFacade.getByRole(user.getId());
-        getMenuStruct(menuList);
-        loginDTO.setMenuWrappers(menuList);
+        Map<Long, List<MenuWrapper>> menuMap = EntityUtil.makeEntityListMap(menuList, "parentId");
+        List<MenuWrapper> menuRes = menuMap.get(-1L);
+        for(MenuWrapper bean : menuRes) {
+            getSonMenu(bean, menuMap);
+        }
+        loginDTO.setMenuWrappers(menuRes);
         return RespDTO.onSuc(loginDTO);
     }
 
 
+    /**
+     * 递归获取菜单结构
+     * @param menu 当前菜单
+     * @param menuMap 菜单集
+     * @return 菜单结构
+     */
+    public List<MenuWrapper> getSonMenu(MenuWrapper menu, Map<Long, List<MenuWrapper>> menuMap) {
+        List<MenuWrapper> res = new ArrayList<>();
+        List<MenuWrapper> list = menuMap.get(menu.getId());
+        if(ListUtil.isNotEmpty(list)) {
+            menu.setSubMenuList(list);
+            for(MenuWrapper bean : list) {
+                getSonMenu(bean, menuMap);
+            }
+        }
+        return res;
+    }
+
     /**
      * 递归获取菜单结构
      *

+ 1 - 1
user-service/src/main/resources/mapper/MenuMapper.xml

@@ -21,7 +21,7 @@
         select a.* from sys_menu a, sys_role_menu b, sys_user_role c
         where a.id = b.menu_id and b.role_id and b.role_id = c.role_id and c.user_id = #{userId}
         and a.is_deleted = 'N' and b.is_deleted = 'N' and c.is_deleted = 'N'
-        ORDER BY a.order_no
+        ORDER BY a.parent_id , a.order_no
     </select>
 
     <select id="getSubMenuById" resultMap="BaseResultMap">