|
@@ -3,10 +3,15 @@ package com.boman.system.service.impl;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import com.boman.common.core.utils.obj.ObjectUtils;
|
|
|
import com.boman.common.core.web.domain.AjaxResult;
|
|
|
+import com.boman.common.redis.RedisKey;
|
|
|
+import com.boman.common.redis.service.RedisService;
|
|
|
+import com.boman.domain.GenTable;
|
|
|
+import com.boman.domain.RoleEnum;
|
|
|
+import com.boman.domain.constant.GlobalBtn;
|
|
|
import com.boman.system.api.domain.SysMenu;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.boman.common.core.constant.UserConstants;
|
|
@@ -22,6 +27,11 @@ import com.boman.system.mapper.SysRoleMapper;
|
|
|
import com.boman.system.mapper.SysRoleMenuMapper;
|
|
|
import com.boman.system.service.ISysMenuService;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+
|
|
|
+import static com.boman.common.core.utils.obj.ObjectUtils.*;
|
|
|
+import static com.boman.domain.constant.FormDataConstant.COLON;
|
|
|
+
|
|
|
/**
|
|
|
* 菜单 业务层处理
|
|
|
*
|
|
@@ -39,6 +49,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
|
|
@Autowired
|
|
|
private SysRoleMenuMapper roleMenuMapper;
|
|
|
+ @Resource
|
|
|
+ private RedisService redisService;
|
|
|
|
|
|
/**
|
|
|
* 根据用户查询系统菜单列表
|
|
@@ -111,37 +123,38 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据用户ID查询菜单树信息
|
|
|
+ * 功能描述: 根据菜单id,找到此菜单以及子菜单下所有的叶子节点
|
|
|
*
|
|
|
* @param menuId menuId
|
|
|
- * @return 菜单列表
|
|
|
+ * @return java.util.List<com.boman.system.api.domain.SysMenu>
|
|
|
*/
|
|
|
@Override
|
|
|
public List<SysMenu> allLeafNodeById(Long menuId) {
|
|
|
- List<SysMenu> tempList = Lists.newArrayListWithCapacity(16);
|
|
|
SysMenu menu = selectMenuById(menuId);
|
|
|
List<SysMenu> menus = menuMapper.selectMenuList(new SysMenu());
|
|
|
- List<SysMenu> sysMenus = recursionList(menus, menu, tempList);
|
|
|
- return ObjectUtils.filter(sysMenus, menu1 -> SysMenu.BUTTON.equals(menu1.getMenuType()));
|
|
|
+ List<SysMenu> tempList = Lists.newArrayListWithCapacity(16);
|
|
|
+ recursionList(menus, menu, tempList);
|
|
|
+ // 把父亲去掉
|
|
|
+ if (tempList.size() > 1) {
|
|
|
+ tempList.remove(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ return tempList;
|
|
|
}
|
|
|
|
|
|
- private List<SysMenu> recursionList(List<SysMenu> menus, SysMenu menu, List<SysMenu> tempList) {
|
|
|
- int child = 0;
|
|
|
+ private void recursionList(List<SysMenu> menus, SysMenu menu, List<SysMenu> tempList) {
|
|
|
// 得到子节点列表
|
|
|
List<SysMenu> childList = getChildList(menus, menu);
|
|
|
+ if (isEmpty(childList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ tempList.add(menu);
|
|
|
for (SysMenu tChild : childList) {
|
|
|
if (hasChild(menus, tChild)) {
|
|
|
recursionList(menus, tChild, tempList);
|
|
|
- } else {
|
|
|
- child++;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (child == childList.size() && childList.size() != 0) {
|
|
|
- tempList.addAll(childList);
|
|
|
- }
|
|
|
-
|
|
|
- return tempList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -207,7 +220,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
@Override
|
|
|
public List<SysMenu> buildMenuTree(List<SysMenu> menus) {
|
|
|
List<SysMenu> returnList = new ArrayList<>();
|
|
|
- List<Long> allMenuId = ObjectUtils.map(menus, SysMenu::getId);
|
|
|
+ List<Long> allMenuId = map(menus, SysMenu::getId);
|
|
|
for (SysMenu menu : menus) {
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
if (!allMenuId.contains(menu.getParentId())) {
|
|
@@ -228,7 +241,7 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
@Override
|
|
|
public List<SysMenu> buildMenuTreeNotAddLeafNode(List<SysMenu> menus) {
|
|
|
List<SysMenu> returnList = new ArrayList<>();
|
|
|
- List<Long> allMenuId = ObjectUtils.map(menus, SysMenu::getId);
|
|
|
+ List<Long> allMenuId = map(menus, SysMenu::getId);
|
|
|
for (SysMenu menu : menus) {
|
|
|
// 如果是顶级节点, 遍历该父节点的所有子节点
|
|
|
if (!allMenuId.contains(menu.getParentId())) {
|
|
@@ -517,4 +530,92 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
private boolean hasChild(List<SysMenu> list, SysMenu t) {
|
|
|
return getChildList(list, t).size() > 0;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> listMenus(Long menuId) {
|
|
|
+ SysMenu menu = selectMenuById(menuId);
|
|
|
+ List<SysMenu> menus = menuMapper.selectMenuList(new SysMenu());
|
|
|
+ List<SysMenu> tempList = Lists.newArrayListWithCapacity(16);
|
|
|
+ recursionList(menus, menu, tempList);
|
|
|
+ // 把父亲去掉
|
|
|
+ if (tempList.size() > 1) {
|
|
|
+ tempList.remove(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, Object> result = Maps.newHashMapWithExpectedSize(2);
|
|
|
+ result.put("heads", RoleEnum.all());
|
|
|
+ if (isEmpty(tempList)) {
|
|
|
+ result.put("sysMenus", tempList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (SysMenu sysMenu : tempList) {
|
|
|
+ List<Object> containsHead = Lists.newArrayList("0", "0", "0", "0", "0", "0", "0", "0");
|
|
|
+ List<SysMenu> childList = getChildList(menus, sysMenu);
|
|
|
+ for (SysMenu childMenu : childList) {
|
|
|
+ String btn = getBtnFromPerms(childMenu.getPerms());
|
|
|
+ String tableName = getTableNameFromPerms(childMenu.getPerms());
|
|
|
+ GenTable genTable = redisService.getCacheObject(RedisKey.TABLE_INFO + tableName);
|
|
|
+ String menuRole = genTable.getMenuRole();
|
|
|
+ if (menuRole.contains(btn)) {
|
|
|
+ switchBtn(containsHead, btn, true);
|
|
|
+ } else {
|
|
|
+ switchBtn(containsHead, btn, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ sysMenu.setContainsHead(containsHead);
|
|
|
+ }
|
|
|
+ result.put("sysMenus", tempList);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void switchBtn(List<Object> containsHead, String btn, Object value) {
|
|
|
+ switch (btn) {
|
|
|
+ case GlobalBtn.A:
|
|
|
+ containsHead.set(0, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.M:
|
|
|
+ containsHead.set(1, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.D:
|
|
|
+ containsHead.set(2, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.Q:
|
|
|
+ containsHead.set(3, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.S:
|
|
|
+ containsHead.set(4, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.U:
|
|
|
+ containsHead.set(5, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.I:
|
|
|
+ containsHead.set(6, value);
|
|
|
+ break;
|
|
|
+ case GlobalBtn.E:
|
|
|
+ containsHead.set(7, value);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getBtnFromPerms(String perms) {
|
|
|
+ // sys_user:A
|
|
|
+ requireNonNull(perms, "权限标识为空");
|
|
|
+ String[] split = perms.split(COLON);
|
|
|
+ assert split.length == 2;
|
|
|
+ // A
|
|
|
+ return split[1];
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getTableNameFromPerms(String perms) {
|
|
|
+ // sys_user:A
|
|
|
+ requireNonNull(perms, "权限标识为空");
|
|
|
+ String[] split = perms.split(COLON);
|
|
|
+ assert split.length == 2;
|
|
|
+ // sys_user
|
|
|
+ return split[0];
|
|
|
+ }
|
|
|
}
|