diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/AppServiceApi.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/AppServiceApi.java index 5ae86998b..9838ce677 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/AppServiceApi.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/api/AppServiceApi.java @@ -27,6 +27,7 @@ package cn.stylefeng.roses.kernel.system.api; import cn.stylefeng.roses.kernel.rule.pojo.dict.SimpleDict; import cn.stylefeng.roses.kernel.system.api.pojo.app.SysAppResult; +import java.util.List; import java.util.Set; /** @@ -74,4 +75,12 @@ public interface AppServiceApi { */ SysAppResult getAppInfoByAppCode(String appCode); + /** + * 按顺序获取app的编码 + * + * @author fengshuonan + * @date 2022/4/6 22:34 + */ + List getAppNameSorted(); + } diff --git a/kernel-s-system/system-business-app/src/main/java/cn/stylefeng/roses/kernel/system/modular/app/service/impl/SysAppServiceImpl.java b/kernel-s-system/system-business-app/src/main/java/cn/stylefeng/roses/kernel/system/modular/app/service/impl/SysAppServiceImpl.java index ba8de98cc..0c7dadd3a 100644 --- a/kernel-s-system/system-business-app/src/main/java/cn/stylefeng/roses/kernel/system/modular/app/service/impl/SysAppServiceImpl.java +++ b/kernel-s-system/system-business-app/src/main/java/cn/stylefeng/roses/kernel/system/modular/app/service/impl/SysAppServiceImpl.java @@ -53,6 +53,7 @@ import javax.annotation.Resource; import java.util.HashSet; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; /** * 系统应用service接口实现类 @@ -269,6 +270,14 @@ public class SysAppServiceImpl extends ServiceImpl impleme } } + @Override + public List getAppNameSorted() { + LambdaQueryWrapper wrapper = this.createWrapper(new SysAppRequest()); + wrapper.select(SysApp::getAppName); + List list = this.list(wrapper); + return list.stream().map(SysApp::getAppName).collect(Collectors.toList()); + } + /** * 获取系统应用 * diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/factory/AntdMenusFactory.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/factory/AntdMenusFactory.java index 693afe2cb..0e912d410 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/factory/AntdMenusFactory.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/factory/AntdMenusFactory.java @@ -58,39 +58,36 @@ public class AntdMenusFactory { * 组装antdv用的获取所有菜单列表详情 * * @param appSortedMenus 按应用排序过的菜单集合 + * @param appNames 排序过的应用名称 * @author fengshuonan * @date 2021/1/7 18:17 */ - public static List createTotalMenus(Map> appSortedMenus, String activeAppCode) { + public static List createTotalMenus(Map> appSortedMenus, List appNames) { // 创建应用级别的菜单集合 ArrayList appSortedAntdMenus = new ArrayList<>(); - // 如果用户菜单中包含了激活的应用,先放激活的应用的 - if (appSortedMenus.containsKey(activeAppCode)) { + // 创建其他应用的菜单 + for (Map.Entry> entry : appSortedMenus.entrySet()) { // 创建顶层应用菜单 - AntdSysMenuDTO firstSortApp = createRootAppMenu(activeAppCode); - List treeStructMenu = new DefaultTreeBuildFactory(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(appSortedMenus.get(activeAppCode)); + AntdSysMenuDTO rootAppMenu = createRootAppMenu(entry.getKey()); + List treeStructMenu = new DefaultTreeBuildFactory(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(entry.getValue()); List antdSysMenuDTOS = doModelTransfer(treeStructMenu); // 更新顶层应用级别的菜单 - firstSortApp.setChildren(antdSysMenuDTOS); - appSortedAntdMenus.add(firstSortApp); + rootAppMenu.setChildren(antdSysMenuDTOS); + appSortedAntdMenus.add(rootAppMenu); } - // 创建其他应用的菜单 - for (Map.Entry> entry : appSortedMenus.entrySet()) { - if (!entry.getKey().equals(activeAppCode)) { - // 创建顶层应用菜单 - AntdSysMenuDTO rootAppMenu = createRootAppMenu(entry.getKey()); - List treeStructMenu = new DefaultTreeBuildFactory(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(entry.getValue()); - List antdSysMenuDTOS = doModelTransfer(treeStructMenu); - - // 更新顶层应用级别的菜单 - rootAppMenu.setChildren(antdSysMenuDTOS); - appSortedAntdMenus.add(rootAppMenu); - } + // 更新排序 + if (ObjectUtil.isEmpty(appNames)) { + return appSortedAntdMenus; } + appSortedAntdMenus.sort((antdSysMenuDTO, antdSysMenuDTO2) -> { + int one = appNames.indexOf(antdSysMenuDTO.getTitle()); + int two = appNames.indexOf(antdSysMenuDTO2.getTitle()); + return Integer.compare(one, two); + }); return appSortedAntdMenus; } diff --git a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/service/impl/SysMenuServiceImpl.java b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/service/impl/SysMenuServiceImpl.java index 2797f90a7..e4a4f0797 100644 --- a/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/service/impl/SysMenuServiceImpl.java +++ b/kernel-s-system/system-business-menu/src/main/java/cn/stylefeng/roses/kernel/system/modular/menu/service/impl/SysMenuServiceImpl.java @@ -299,12 +299,12 @@ public class SysMenuServiceImpl extends ServiceImpl impl List currentUserMenus = this.getCurrentUserMenus(null, false); // 获取当前激活的应用 - String activeAppCode = appServiceApi.getActiveAppCode(); + List appNameSorted = appServiceApi.getAppNameSorted(); // 将菜单按应用编码分类,激活的应用放在最前边 Map> sortedUserMenus = AntdMenusFactory.sortUserMenusByAppCode(currentUserMenus); - return AntdMenusFactory.createTotalMenus(sortedUserMenus, activeAppCode); + return AntdMenusFactory.createTotalMenus(sortedUserMenus, appNameSorted); } @Override