菜单新增是否显示字段
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
<result column="category" property="category"/>
|
||||
<result column="action" property="action"/>
|
||||
<result column="is_open" property="isOpen"/>
|
||||
<result column="is_display" property="isDisplay"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
</resultMap>
|
||||
@@ -31,6 +32,7 @@
|
||||
<result column="category" property="category"/>
|
||||
<result column="action" property="action"/>
|
||||
<result column="is_open" property="isOpen"/>
|
||||
<result column="is_display" property="isDisplay"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="has_children" property="hasChildren"/>
|
||||
|
||||
@@ -72,6 +72,7 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
private final ITopMenuSettingService topMenuSettingService;
|
||||
private final static String PARENT_ID = "parentId";
|
||||
private final static Integer MENU_CATEGORY = 1;
|
||||
private final static Integer MENU_DISPLAY = 1;
|
||||
|
||||
@Override
|
||||
public List<MenuVO> lazyList(Long parentId, Map<String, Object> param) {
|
||||
@@ -132,10 +133,22 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
roleMenus.forEach(roleMenu -> recursion(allMenus, routes, roleMenu));
|
||||
routes.sort(Comparator.comparing(Menu::getSort));
|
||||
MenuWrapper menuWrapper = new MenuWrapper();
|
||||
List<Menu> collect = routes.stream().filter(x -> Func.equals(x.getCategory(), 1)).collect(Collectors.toList());
|
||||
Map<Long, Menu> routeMap = routes.stream().collect(Collectors.toMap(Menu::getId, x -> x, (left, right) -> left));
|
||||
List<Menu> collect = routes.stream()
|
||||
.filter(x -> Func.equals(x.getCategory(), 1))
|
||||
.filter(x -> isDisplayMenu(x, routeMap))
|
||||
.collect(Collectors.toList());
|
||||
return menuWrapper.listNodeVO(collect);
|
||||
}
|
||||
|
||||
private boolean isDisplayMenu(Menu menu, Map<Long, Menu> routeMap) {
|
||||
if (!Func.equals(Func.toInt(menu.getIsDisplay(), MENU_DISPLAY), MENU_DISPLAY)) {
|
||||
return false;
|
||||
}
|
||||
Menu parentMenu = routeMap.get(menu.getParentId());
|
||||
return parentMenu == null || isDisplayMenu(parentMenu, routeMap);
|
||||
}
|
||||
|
||||
private void recursion(List<Menu> allMenus, List<Menu> routes, Menu roleMenu) {
|
||||
Optional<Menu> menu = allMenus.stream().filter(x -> Func.equals(x.getId(), roleMenu.getParentId())).findFirst();
|
||||
if (menu.isPresent() && !routes.contains(menu.get())) {
|
||||
@@ -306,6 +319,9 @@ public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IM
|
||||
if (menu.getParentId() == null) {
|
||||
menu.setParentId(BladeConstant.TOP_PARENT_ID);
|
||||
}
|
||||
if (menu.getIsDisplay() == null) {
|
||||
menu.setIsDisplay(MENU_DISPLAY);
|
||||
}
|
||||
|
||||
// 验证父节点类型(新增或父节点变更时)
|
||||
if (isNewMenu || menu.getParentId() != null) {
|
||||
|
||||
@@ -63,9 +63,11 @@ public class MenuWrapper extends BaseEntityWrapper<Menu, MenuVO> {
|
||||
String category = DictCache.getValue(DictEnum.MENU_CATEGORY, Func.toInt(menuVO.getCategory()));
|
||||
String action = DictCache.getValue(DictEnum.BUTTON_FUNC, Func.toInt(menuVO.getAction()));
|
||||
String open = DictCache.getValue(DictEnum.YES_NO, Func.toInt(menuVO.getIsOpen()));
|
||||
String display = Func.equals(Func.toInt(menuVO.getIsDisplay(), 1), 1) ? "显示" : "不显示";
|
||||
menuVO.setCategoryName(category);
|
||||
menuVO.setActionName(action);
|
||||
menuVO.setIsOpenName(open);
|
||||
menuVO.setIsDisplayName(display);
|
||||
return menuVO;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user