From 47768d890fbfc1a5f3e93ca26137847361415e9e Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期二, 28 十月 2025 10:54:16 +0800
Subject: [PATCH] Merge branch 'master' into pim_meet
---
src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java | 149 +++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 124 insertions(+), 25 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
index fb1c830..fad86e5 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysMenuServiceImpl.java
@@ -10,15 +10,18 @@
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
+import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.domain.TreeSelect;
import com.ruoyi.project.system.domain.SysMenu;
+import com.ruoyi.project.system.domain.SysRole;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.domain.vo.MetaVo;
import com.ruoyi.project.system.domain.vo.RouterVo;
import com.ruoyi.project.system.mapper.SysMenuMapper;
+import com.ruoyi.project.system.mapper.SysRoleMapper;
import com.ruoyi.project.system.mapper.SysRoleMenuMapper;
import com.ruoyi.project.system.service.ISysMenuService;
@@ -34,6 +37,9 @@
@Autowired
private SysMenuMapper menuMapper;
+
+ @Autowired
+ private SysRoleMapper roleMapper;
@Autowired
private SysRoleMenuMapper roleMenuMapper;
@@ -95,6 +101,27 @@
}
/**
+ * 鏍规嵁瑙掕壊ID鏌ヨ鏉冮檺
+ *
+ * @param roleId 瑙掕壊ID
+ * @return 鏉冮檺鍒楄〃
+ */
+ @Override
+ public Set<String> selectMenuPermsByRoleId(Long roleId)
+ {
+ List<String> perms = menuMapper.selectMenuPermsByRoleId(roleId);
+ Set<String> permsSet = new HashSet<>();
+ for (String perm : perms)
+ {
+ if (StringUtils.isNotEmpty(perm))
+ {
+ permsSet.addAll(Arrays.asList(perm.trim().split(",")));
+ }
+ }
+ return permsSet;
+ }
+
+ /**
* 鏍规嵁鐢ㄦ埛ID鏌ヨ鑿滃崟
*
* @param userId 鐢ㄦ埛鍚嶇О
@@ -122,9 +149,10 @@
* @return 閫変腑鑿滃崟鍒楄〃
*/
@Override
- public List<Integer> selectMenuListByRoleId(Long roleId)
+ public List<Long> selectMenuListByRoleId(Long roleId)
{
- return menuMapper.selectMenuListByRoleId(roleId);
+ SysRole role = roleMapper.selectRoleById(roleId);
+ return menuMapper.selectMenuListByRoleId(roleId, role.isMenuCheckStrictly());
}
/**
@@ -144,22 +172,39 @@
router.setName(getRouteName(menu));
router.setPath(getRouterPath(menu));
router.setComponent(getComponent(menu));
- router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
+ router.setQuery(menu.getQuery());
+ router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
List<SysMenu> cMenus = menu.getChildren();
- if (!cMenus.isEmpty() && cMenus.size() > 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
+ if (StringUtils.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType()))
{
router.setAlwaysShow(true);
router.setRedirect("noRedirect");
router.setChildren(buildMenus(cMenus));
}
- else if (isMeunFrame(menu))
+ else if (isMenuFrame(menu))
{
+ router.setMeta(null);
List<RouterVo> childrenList = new ArrayList<RouterVo>();
RouterVo children = new RouterVo();
children.setPath(menu.getPath());
children.setComponent(menu.getComponent());
- children.setName(StringUtils.capitalize(menu.getPath()));
- children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
+ children.setName(getRouteName(menu.getRouteName(), menu.getPath()));
+ children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
+ children.setQuery(menu.getQuery());
+ childrenList.add(children);
+ router.setChildren(childrenList);
+ }
+ else if (menu.getParentId().intValue() == 0 && isInnerLink(menu))
+ {
+ router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon()));
+ router.setPath("/");
+ List<RouterVo> childrenList = new ArrayList<RouterVo>();
+ RouterVo children = new RouterVo();
+ String routerPath = innerLinkReplaceEach(menu.getPath());
+ children.setPath(routerPath);
+ children.setComponent(UserConstants.INNER_LINK);
+ children.setName(getRouteName(menu.getRouteName(), routerPath));
+ children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
childrenList.add(children);
router.setChildren(childrenList);
}
@@ -178,11 +223,7 @@
public List<SysMenu> buildMenuTree(List<SysMenu> menus)
{
List<SysMenu> returnList = new ArrayList<SysMenu>();
- List<Long> tempList = new ArrayList<Long>();
- for (SysMenu dept : menus)
- {
- tempList.add(dept.getMenuId());
- }
+ List<Long> tempList = menus.stream().map(SysMenu::getMenuId).collect(Collectors.toList());
for (Iterator<SysMenu> iterator = menus.iterator(); iterator.hasNext();)
{
SysMenu menu = (SysMenu) iterator.next();
@@ -235,7 +276,7 @@
public boolean hasChildByMenuId(Long menuId)
{
int result = menuMapper.hasChildByMenuId(menuId);
- return result > 0 ? true : false;
+ return result > 0;
}
/**
@@ -248,7 +289,7 @@
public boolean checkMenuExistRole(Long menuId)
{
int result = roleMenuMapper.checkMenuExistRole(menuId);
- return result > 0 ? true : false;
+ return result > 0;
}
/**
@@ -294,7 +335,7 @@
* @return 缁撴灉
*/
@Override
- public String checkMenuNameUnique(SysMenu menu)
+ public boolean checkMenuNameUnique(SysMenu menu)
{
Long menuId = StringUtils.isNull(menu.getMenuId()) ? -1L : menu.getMenuId();
SysMenu info = menuMapper.checkMenuNameUnique(menu.getMenuName(), menu.getParentId());
@@ -313,13 +354,25 @@
*/
public String getRouteName(SysMenu menu)
{
- String routerName = StringUtils.capitalize(menu.getPath());
// 闈炲閾惧苟涓旀槸涓�绾х洰褰曪紙绫诲瀷涓虹洰褰曪級
- if (isMeunFrame(menu))
+ if (isMenuFrame(menu))
{
- routerName = StringUtils.EMPTY;
+ return StringUtils.EMPTY;
}
- return routerName;
+ return getRouteName(menu.getRouteName(), menu.getPath());
+ }
+
+ /**
+ * 鑾峰彇璺敱鍚嶇О锛屽娌℃湁閰嶇疆璺敱鍚嶇О鍒欏彇璺敱鍦板潃
+ *
+ * @param name 璺敱鍚嶇О
+ * @param path 璺敱鍦板潃
+ * @return 璺敱鍚嶇О锛堥┘宄版牸寮忥級
+ */
+ public String getRouteName(String name, String path)
+ {
+ String routerName = StringUtils.isNotEmpty(name) ? name : path;
+ return StringUtils.capitalize(routerName);
}
/**
@@ -331,6 +384,11 @@
public String getRouterPath(SysMenu menu)
{
String routerPath = menu.getPath();
+ // 鍐呴摼鎵撳紑澶栫綉鏂瑰紡
+ if (menu.getParentId().intValue() != 0 && isInnerLink(menu))
+ {
+ routerPath = innerLinkReplaceEach(routerPath);
+ }
// 闈炲閾惧苟涓旀槸涓�绾х洰褰曪紙绫诲瀷涓虹洰褰曪級
if (0 == menu.getParentId().intValue() && UserConstants.TYPE_DIR.equals(menu.getMenuType())
&& UserConstants.NO_FRAME.equals(menu.getIsFrame()))
@@ -338,7 +396,7 @@
routerPath = "/" + menu.getPath();
}
// 闈炲閾惧苟涓旀槸涓�绾х洰褰曪紙绫诲瀷涓鸿彍鍗曪級
- else if (isMeunFrame(menu))
+ else if (isMenuFrame(menu))
{
routerPath = "/";
}
@@ -354,9 +412,17 @@
public String getComponent(SysMenu menu)
{
String component = UserConstants.LAYOUT;
- if (StringUtils.isNotEmpty(menu.getComponent()) && !isMeunFrame(menu))
+ if (StringUtils.isNotEmpty(menu.getComponent()) && !isMenuFrame(menu))
{
component = menu.getComponent();
+ }
+ else if (StringUtils.isEmpty(menu.getComponent()) && menu.getParentId().intValue() != 0 && isInnerLink(menu))
+ {
+ component = UserConstants.INNER_LINK;
+ }
+ else if (StringUtils.isEmpty(menu.getComponent()) && isParentView(menu))
+ {
+ component = UserConstants.PARENT_VIEW;
}
return component;
}
@@ -367,10 +433,32 @@
* @param menu 鑿滃崟淇℃伅
* @return 缁撴灉
*/
- public boolean isMeunFrame(SysMenu menu)
+ public boolean isMenuFrame(SysMenu menu)
{
return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
&& menu.getIsFrame().equals(UserConstants.NO_FRAME);
+ }
+
+ /**
+ * 鏄惁涓簆arent_view缁勪欢
+ *
+ * @param menu 鑿滃崟淇℃伅
+ * @return 缁撴灉
+ */
+ public boolean isParentView(SysMenu menu)
+ {
+ return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
+ }
+
+ /**
+ * 鏄惁涓哄唴閾剧粍浠�
+ *
+ * @param menu 鑿滃崟淇℃伅
+ * @return 缁撴灉
+ */
+ public boolean isInnerLink(SysMenu menu)
+ {
+ return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath());
}
/**
@@ -399,8 +487,8 @@
/**
* 閫掑綊鍒楄〃
*
- * @param list
- * @param t
+ * @param list 鍒嗙被琛�
+ * @param t 瀛愯妭鐐�
*/
private void recursionFn(List<SysMenu> list, SysMenu t)
{
@@ -439,6 +527,17 @@
*/
private boolean hasChild(List<SysMenu> list, SysMenu t)
{
- return getChildList(list, t).size() > 0 ? true : false;
+ return getChildList(list, t).size() > 0;
+ }
+
+ /**
+ * 鍐呴摼鍩熷悕鐗规畩瀛楃鏇挎崲
+ *
+ * @return 鏇挎崲鍚庣殑鍐呴摼鍩熷悕
+ */
+ public String innerLinkReplaceEach(String path)
+ {
+ return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":" },
+ new String[] { "", "", "", "/", "/" });
}
}
--
Gitblit v1.9.3