|
@@ -1,12 +1,18 @@
|
|
|
package cc.iotkit.system.service.impl;
|
|
|
|
|
|
+import cc.iotkit.common.constant.Constants;
|
|
|
+import cc.iotkit.common.constant.UserConstants;
|
|
|
import cc.iotkit.common.satoken.utils.LoginHelper;
|
|
|
import cc.iotkit.common.utils.MapstructUtils;
|
|
|
import cc.iotkit.common.utils.StreamUtils;
|
|
|
+import cc.iotkit.common.utils.StringUtils;
|
|
|
import cc.iotkit.common.utils.TreeBuildUtils;
|
|
|
import cc.iotkit.data.system.ISysMenuData;
|
|
|
+import cc.iotkit.data.system.ISysRoleData;
|
|
|
import cc.iotkit.model.system.SysMenu;
|
|
|
+import cc.iotkit.model.system.SysRole;
|
|
|
import cc.iotkit.system.dto.bo.SysMenuBo;
|
|
|
+import cc.iotkit.system.dto.vo.MetaVo;
|
|
|
import cc.iotkit.system.dto.vo.RouterVo;
|
|
|
import cc.iotkit.system.dto.vo.SysMenuVo;
|
|
|
import cc.iotkit.system.service.ISysMenuService;
|
|
@@ -15,10 +21,7 @@ import cn.hutool.core.lang.tree.Tree;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashSet;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 菜单 业务层处理
|
|
@@ -30,6 +33,7 @@ import java.util.Set;
|
|
|
public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
|
|
|
private final ISysMenuData sysMenuData;
|
|
|
+ private final ISysRoleData sysRoleData;
|
|
|
|
|
|
/**
|
|
|
* 根据用户查询系统菜单列表
|
|
@@ -65,7 +69,14 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Set<String> selectMenuPermsByUserId(Long userId) {
|
|
|
- return new HashSet<>();
|
|
|
+ List<String> perms = sysMenuData.selectMenuPermsByUserId(userId);
|
|
|
+ Set<String> permsSet = new HashSet<>();
|
|
|
+ for (String perm : perms) {
|
|
|
+ if (StringUtils.isNotEmpty(perm)) {
|
|
|
+ permsSet.addAll(StringUtils.splitList(perm.trim()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return permsSet;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -76,7 +87,14 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public Set<String> selectMenuPermsByRoleId(Long roleId) {
|
|
|
- return new HashSet<>();
|
|
|
+ List<String> perms = sysMenuData.selectMenuPermsByRoleId(roleId);
|
|
|
+ Set<String> permsSet = new HashSet<>();
|
|
|
+ for (String perm : perms) {
|
|
|
+ if (StringUtils.isNotEmpty(perm)) {
|
|
|
+ permsSet.addAll(StringUtils.splitList(perm.trim()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return permsSet;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -87,7 +105,13 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<SysMenu> selectMenuTreeByUserId(Long userId) {
|
|
|
- return new ArrayList<>();
|
|
|
+ List<SysMenu> menus = null;
|
|
|
+ if (LoginHelper.isSuperAdmin(userId)) {
|
|
|
+ menus = sysMenuData.selectMenuTreeAll();
|
|
|
+ } else {
|
|
|
+ menus = sysMenuData.selectMenuTreeByUserId(userId);
|
|
|
+ }
|
|
|
+ return getChildPerms(menus, 0);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -98,7 +122,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<Long> selectMenuListByRoleId(Long roleId) {
|
|
|
- return new ArrayList<>();
|
|
|
+ SysRole role = sysRoleData.findById(roleId);
|
|
|
+ return sysRoleData.selectMenuListByRoleId(roleId, role.getMenuCheckStrictly());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -120,7 +145,115 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public List<RouterVo> buildMenus(List<SysMenu> menus) {
|
|
|
- return new ArrayList<>();
|
|
|
+ List<RouterVo> routers = new LinkedList<>();
|
|
|
+ for (SysMenu menu : menus) {
|
|
|
+ RouterVo router = new RouterVo();
|
|
|
+ router.setHidden("1".equals(menu.getVisible()));
|
|
|
+ router.setName(getRouteName(menu));
|
|
|
+ router.setPath(getRouterPath(menu));
|
|
|
+ router.setComponent(getComponent(menu));
|
|
|
+ router.setQuery(menu.getQueryParam());
|
|
|
+ router.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
|
|
+ List<SysMenu> cMenus = menu.getChildren();
|
|
|
+ if (CollUtil.isNotEmpty(cMenus) && UserConstants.TYPE_DIR.equals(menu.getMenuType())) {
|
|
|
+ router.setAlwaysShow(true);
|
|
|
+ router.setRedirect("noRedirect");
|
|
|
+ router.setChildren(buildMenus(cMenus));
|
|
|
+ } else if (isMenuFrame(menu)) {
|
|
|
+ router.setMeta(null);
|
|
|
+ List<RouterVo> childrenList = new ArrayList<>();
|
|
|
+ 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(), StringUtils.equals("1", menu.getIsCache()), menu.getPath()));
|
|
|
+ children.setQuery(menu.getQueryParam());
|
|
|
+ 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 children = new RouterVo();
|
|
|
+ String routerPath = innerLinkReplaceEach(menu.getPath());
|
|
|
+ children.setPath(routerPath);
|
|
|
+ children.setComponent(UserConstants.INNER_LINK);
|
|
|
+ children.setName(StringUtils.capitalize(routerPath));
|
|
|
+ children.setMeta(new MetaVo(menu.getMenuName(), menu.getIcon(), menu.getPath()));
|
|
|
+ childrenList.add(children);
|
|
|
+ router.setChildren(childrenList);
|
|
|
+ }
|
|
|
+ routers.add(router);
|
|
|
+ }
|
|
|
+ return routers;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取路由名称
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 路由名称
|
|
|
+ */
|
|
|
+ public String getRouteName(SysMenu menu) {
|
|
|
+ String routerName = StringUtils.capitalize(menu.getPath());
|
|
|
+ // 非外链并且是一级目录(类型为目录)
|
|
|
+ if (isMenuFrame(menu)) {
|
|
|
+ routerName = StringUtils.EMPTY;
|
|
|
+ }
|
|
|
+ return routerName;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否为菜单内部跳转
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public boolean isMenuFrame(SysMenu menu) {
|
|
|
+ return menu.getParentId().intValue() == 0 && UserConstants.TYPE_MENU.equals(menu.getMenuType())
|
|
|
+ && menu.getIsFrame().equals(UserConstants.NO_FRAME);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取路由地址
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 路由地址
|
|
|
+ */
|
|
|
+ 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())) {
|
|
|
+ routerPath = "/" + menu.getPath();
|
|
|
+ }
|
|
|
+ // 非外链并且是一级目录(类型为菜单)
|
|
|
+ else if (isMenuFrame(menu)) {
|
|
|
+ routerPath = "/";
|
|
|
+ }
|
|
|
+ return routerPath;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取组件信息
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 组件信息
|
|
|
+ */
|
|
|
+ public String getComponent(SysMenu menu) {
|
|
|
+ String component = UserConstants.LAYOUT;
|
|
|
+ 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -160,7 +293,27 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean hasChildByMenuId(Long menuId) {
|
|
|
- return false;
|
|
|
+ return sysMenuData.hasChildByMenuId(menuId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否为内链组件
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public boolean isInnerLink(SysMenu menu) {
|
|
|
+ return menu.getIsFrame().equals(UserConstants.NO_FRAME) && StringUtils.ishttp(menu.getPath());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 是否为parent_view组件
|
|
|
+ *
|
|
|
+ * @param menu 菜单信息
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ public boolean isParentView(SysMenu menu) {
|
|
|
+ return menu.getParentId().intValue() != 0 && UserConstants.TYPE_DIR.equals(menu.getMenuType());
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -214,8 +367,8 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
- public boolean checkMenuNameUnique(SysMenuBo menu) {
|
|
|
- return false;
|
|
|
+ public boolean checkMenuNameUnique(SysMenuBo bo) {
|
|
|
+ return sysMenuData.checkMenuNameUnique(bo.to(SysMenu.class));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -252,4 +405,12 @@ public class SysMenuServiceImpl implements ISysMenuService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 内链域名特殊字符替换
|
|
|
+ */
|
|
|
+ public String innerLinkReplaceEach(String path) {
|
|
|
+ return StringUtils.replaceEach(path, new String[]{Constants.HTTP, Constants.HTTPS, Constants.WWW, "."},
|
|
|
+ new String[]{"", "", "", "/"});
|
|
|
+ }
|
|
|
+
|
|
|
}
|