mirror of https://gitee.com/stylefeng/roses
【7.2.2】【app】更新菜单返回的应用排序
parent
a9e09f6b12
commit
262a186b03
|
@ -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<String> getAppNameSorted();
|
||||
|
||||
}
|
||||
|
|
|
@ -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<SysAppMapper, SysApp> impleme
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getAppNameSorted() {
|
||||
LambdaQueryWrapper<SysApp> wrapper = this.createWrapper(new SysAppRequest());
|
||||
wrapper.select(SysApp::getAppName);
|
||||
List<SysApp> list = this.list(wrapper);
|
||||
return list.stream().map(SysApp::getAppName).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统应用
|
||||
*
|
||||
|
|
|
@ -58,39 +58,36 @@ public class AntdMenusFactory {
|
|||
* 组装antdv用的获取所有菜单列表详情
|
||||
*
|
||||
* @param appSortedMenus 按应用排序过的菜单集合
|
||||
* @param appNames 排序过的应用名称
|
||||
* @author fengshuonan
|
||||
* @date 2021/1/7 18:17
|
||||
*/
|
||||
public static List<AntdSysMenuDTO> createTotalMenus(Map<String, List<SysMenu>> appSortedMenus, String activeAppCode) {
|
||||
public static List<AntdSysMenuDTO> createTotalMenus(Map<String, List<SysMenu>> appSortedMenus, List<String> appNames) {
|
||||
|
||||
// 创建应用级别的菜单集合
|
||||
ArrayList<AntdSysMenuDTO> appSortedAntdMenus = new ArrayList<>();
|
||||
|
||||
// 如果用户菜单中包含了激活的应用,先放激活的应用的
|
||||
if (appSortedMenus.containsKey(activeAppCode)) {
|
||||
// 创建其他应用的菜单
|
||||
for (Map.Entry<String, List<SysMenu>> entry : appSortedMenus.entrySet()) {
|
||||
// 创建顶层应用菜单
|
||||
AntdSysMenuDTO firstSortApp = createRootAppMenu(activeAppCode);
|
||||
List<SysMenu> treeStructMenu = new DefaultTreeBuildFactory<SysMenu>(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(appSortedMenus.get(activeAppCode));
|
||||
AntdSysMenuDTO rootAppMenu = createRootAppMenu(entry.getKey());
|
||||
List<SysMenu> treeStructMenu = new DefaultTreeBuildFactory<SysMenu>(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(entry.getValue());
|
||||
List<AntdSysMenuDTO> antdSysMenuDTOS = doModelTransfer(treeStructMenu);
|
||||
|
||||
// 更新顶层应用级别的菜单
|
||||
firstSortApp.setChildren(antdSysMenuDTOS);
|
||||
appSortedAntdMenus.add(firstSortApp);
|
||||
rootAppMenu.setChildren(antdSysMenuDTOS);
|
||||
appSortedAntdMenus.add(rootAppMenu);
|
||||
}
|
||||
|
||||
// 创建其他应用的菜单
|
||||
for (Map.Entry<String, List<SysMenu>> entry : appSortedMenus.entrySet()) {
|
||||
if (!entry.getKey().equals(activeAppCode)) {
|
||||
// 创建顶层应用菜单
|
||||
AntdSysMenuDTO rootAppMenu = createRootAppMenu(entry.getKey());
|
||||
List<SysMenu> treeStructMenu = new DefaultTreeBuildFactory<SysMenu>(TreeConstants.DEFAULT_PARENT_ID.toString()).doTreeBuild(entry.getValue());
|
||||
List<AntdSysMenuDTO> 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;
|
||||
}
|
||||
|
|
|
@ -299,12 +299,12 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
|
|||
List<SysMenu> currentUserMenus = this.getCurrentUserMenus(null, false);
|
||||
|
||||
// 获取当前激活的应用
|
||||
String activeAppCode = appServiceApi.getActiveAppCode();
|
||||
List<String> appNameSorted = appServiceApi.getAppNameSorted();
|
||||
|
||||
// 将菜单按应用编码分类,激活的应用放在最前边
|
||||
Map<String, List<SysMenu>> sortedUserMenus = AntdMenusFactory.sortUserMenusByAppCode(currentUserMenus);
|
||||
|
||||
return AntdMenusFactory.createTotalMenus(sortedUserMenus, activeAppCode);
|
||||
return AntdMenusFactory.createTotalMenus(sortedUserMenus, appNameSorted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue