|
|
|
@ -1,16 +1,21 @@
|
|
|
|
|
package com.glxp.sale.admin.service.auth.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
|
|
import com.glxp.sale.admin.constant.ConstantStatus;
|
|
|
|
|
import com.glxp.sale.admin.dao.auth.AuthPermissionRuleDao;
|
|
|
|
|
import com.glxp.sale.admin.entity.auth.AuthPermissionRule;
|
|
|
|
|
import com.glxp.sale.admin.entity.auth.MetaEntity;
|
|
|
|
|
import com.glxp.sale.admin.entity.auth.RouterEntity;
|
|
|
|
|
import com.glxp.sale.admin.exception.JsonException;
|
|
|
|
|
import com.glxp.sale.admin.service.auth.AuthPermissionRuleService;
|
|
|
|
|
import com.glxp.sale.admin.util.Constant;
|
|
|
|
|
import com.glxp.sale.common.enums.ResultEnum;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
@ -48,6 +53,7 @@ public class AuthPermissionRuleServiceImpl implements AuthPermissionRuleService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询所有
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
@ -57,6 +63,7 @@ public class AuthPermissionRuleServiceImpl implements AuthPermissionRuleService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 插入
|
|
|
|
|
*
|
|
|
|
|
* @param authPermissionRule
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -79,6 +86,7 @@ public class AuthPermissionRuleServiceImpl implements AuthPermissionRuleService
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 更新
|
|
|
|
|
*
|
|
|
|
|
* @param authPermissionRule
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
@ -107,4 +115,214 @@ public class AuthPermissionRuleServiceImpl implements AuthPermissionRuleService
|
|
|
|
|
public boolean deleteById(Long id) {
|
|
|
|
|
return authPermissionRuleDao.deleteById(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<AuthPermissionRule> selectMenuTreeByUserId(List<AuthPermissionRule> menus) {
|
|
|
|
|
|
|
|
|
|
return getChildPerms(menus, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<RouterEntity> buildMenus(List<AuthPermissionRule> menus) {
|
|
|
|
|
|
|
|
|
|
List<RouterEntity> routers = new LinkedList<RouterEntity>();
|
|
|
|
|
for (AuthPermissionRule menu : menus) {
|
|
|
|
|
RouterEntity router = new RouterEntity();
|
|
|
|
|
router.setHidden("0".equals(menu.getVisible()));
|
|
|
|
|
router.setName(getRouteName(menu));
|
|
|
|
|
router.setPath(getRouterPath(menu));
|
|
|
|
|
router.setComponent(getComponent(menu));
|
|
|
|
|
router.setQuery(menu.getQueryParam());
|
|
|
|
|
router.setMeta(new MetaEntity(menu.getTitle(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache() + ""), menu.getPath()));
|
|
|
|
|
List<AuthPermissionRule> cMenus = menu.getChildren();
|
|
|
|
|
if (!cMenus.isEmpty() && Constant.TYPE_DIR.equals(menu.getMenuType())) {
|
|
|
|
|
router.setAlwaysShow(true);
|
|
|
|
|
router.setRedirect("noRedirect");
|
|
|
|
|
router.setChildren(buildMenus(cMenus));
|
|
|
|
|
} else if (isMenuFrame(menu)) {
|
|
|
|
|
router.setMeta(null);
|
|
|
|
|
List<RouterEntity> childrenList = new ArrayList<RouterEntity>();
|
|
|
|
|
RouterEntity children = new RouterEntity();
|
|
|
|
|
children.setPath(menu.getPath());
|
|
|
|
|
children.setComponent(menu.getName());
|
|
|
|
|
children.setName(StringUtils.capitalize(menu.getPath()));
|
|
|
|
|
children.setMeta(new MetaEntity(menu.getTitle(), menu.getIcon(), StringUtils.equals("1", menu.getIsCache() + ""), menu.getPath()));
|
|
|
|
|
children.setQuery(menu.getQueryParam());
|
|
|
|
|
childrenList.add(children);
|
|
|
|
|
router.setChildren(childrenList);
|
|
|
|
|
} else if (menu.getPid().intValue() == 0 && isInnerLink(menu)) {
|
|
|
|
|
router.setMeta(new MetaEntity(menu.getTitle(), menu.getIcon()));
|
|
|
|
|
router.setPath("/");
|
|
|
|
|
List<RouterEntity> childrenList = new ArrayList<RouterEntity>();
|
|
|
|
|
RouterEntity children = new RouterEntity();
|
|
|
|
|
String routerPath = innerLinkReplaceEach(menu.getPath());
|
|
|
|
|
children.setPath(routerPath);
|
|
|
|
|
children.setComponent(Constant.INNER_LINK);
|
|
|
|
|
children.setName(StringUtils.capitalize(routerPath));
|
|
|
|
|
children.setMeta(new MetaEntity(menu.getTitle(), menu.getIcon(), menu.getPath()));
|
|
|
|
|
childrenList.add(children);
|
|
|
|
|
router.setChildren(childrenList);
|
|
|
|
|
}
|
|
|
|
|
routers.add(router);
|
|
|
|
|
}
|
|
|
|
|
return routers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取路由名称
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 路由名称
|
|
|
|
|
*/
|
|
|
|
|
public String getRouteName(AuthPermissionRule menu) {
|
|
|
|
|
String routerName = StringUtils.capitalize(menu.getPath());
|
|
|
|
|
// 非外链并且是一级目录(类型为目录)
|
|
|
|
|
if (isMenuFrame(menu)) {
|
|
|
|
|
routerName = StringUtils.EMPTY;
|
|
|
|
|
}
|
|
|
|
|
return routerName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取路由地址
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 路由地址
|
|
|
|
|
*/
|
|
|
|
|
public String getRouterPath(AuthPermissionRule menu) {
|
|
|
|
|
String routerPath = menu.getPath();
|
|
|
|
|
// 内链打开外网方式
|
|
|
|
|
if (menu.getPid().intValue() != 0 && isInnerLink(menu)) {
|
|
|
|
|
routerPath = innerLinkReplaceEach(routerPath);
|
|
|
|
|
}
|
|
|
|
|
// 非外链并且是一级目录(类型为目录)
|
|
|
|
|
if (0 == menu.getPid().intValue() && Constant.TYPE_DIR.equals(menu.getMenuType())
|
|
|
|
|
&& Constant.NO_FRAME.equals(menu.getIsFrame())) {
|
|
|
|
|
routerPath = "/" + menu.getPath();
|
|
|
|
|
}
|
|
|
|
|
// 非外链并且是一级目录(类型为菜单)
|
|
|
|
|
else if (isMenuFrame(menu)) {
|
|
|
|
|
routerPath = "/";
|
|
|
|
|
}
|
|
|
|
|
return routerPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取组件信息
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 组件信息
|
|
|
|
|
*/
|
|
|
|
|
public String getComponent(AuthPermissionRule menu) {
|
|
|
|
|
String component = Constant.LAYOUT;
|
|
|
|
|
if (StringUtils.isNotEmpty(menu.getName()) && !isMenuFrame(menu)) {
|
|
|
|
|
component = menu.getName();
|
|
|
|
|
} else if (StringUtils.isEmpty(menu.getName()) && menu.getPid().intValue() != 0 && isInnerLink(menu)) {
|
|
|
|
|
component = Constant.INNER_LINK;
|
|
|
|
|
} else if (StringUtils.isEmpty(menu.getName()) && isParentView(menu)) {
|
|
|
|
|
component = Constant.PARENT_VIEW;
|
|
|
|
|
}
|
|
|
|
|
return component;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否为菜单内部跳转
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
public boolean isMenuFrame(AuthPermissionRule menu) {
|
|
|
|
|
return menu.getPid().intValue() == 0 && Constant.TYPE_MENU.equals(menu.getMenuType())
|
|
|
|
|
&& menu.getIsFrame().equals(Constant.NO_FRAME);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否为内链组件
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
public boolean isInnerLink(AuthPermissionRule menu) {
|
|
|
|
|
return menu.getIsFrame() != null && (menu.getIsFrame() + "").equals(Constant.NO_FRAME) && menu.getPath() != null && HttpUtil.isHttp(menu.getPath());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 是否为parent_view组件
|
|
|
|
|
*
|
|
|
|
|
* @param menu 菜单信息
|
|
|
|
|
* @return 结果
|
|
|
|
|
*/
|
|
|
|
|
public boolean isParentView(AuthPermissionRule menu) {
|
|
|
|
|
return menu.getPid().intValue() != 0 && Constant.TYPE_DIR.equals(menu.getMenuType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据父节点的ID获取所有子节点
|
|
|
|
|
*
|
|
|
|
|
* @param list 分类表
|
|
|
|
|
* @param parentId 传入的父节点ID
|
|
|
|
|
* @return String
|
|
|
|
|
*/
|
|
|
|
|
public List<AuthPermissionRule> getChildPerms(List<AuthPermissionRule> list, int parentId) {
|
|
|
|
|
List<AuthPermissionRule> returnList = new ArrayList<AuthPermissionRule>();
|
|
|
|
|
for (AuthPermissionRule t : list) {
|
|
|
|
|
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
|
|
|
|
|
if (t.getPid() == parentId) {
|
|
|
|
|
recursionFn(list, t);
|
|
|
|
|
returnList.add(t);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return returnList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 递归列表
|
|
|
|
|
*
|
|
|
|
|
* @param list
|
|
|
|
|
* @param t
|
|
|
|
|
*/
|
|
|
|
|
private void recursionFn(List<AuthPermissionRule> list, AuthPermissionRule t) {
|
|
|
|
|
// 得到子节点列表
|
|
|
|
|
List<AuthPermissionRule> childList = getChildList(list, t);
|
|
|
|
|
t.setChildren(childList);
|
|
|
|
|
for (AuthPermissionRule tChild : childList) {
|
|
|
|
|
if (hasChild(list, tChild)) {
|
|
|
|
|
recursionFn(list, tChild);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 得到子节点列表
|
|
|
|
|
*/
|
|
|
|
|
private List<AuthPermissionRule> getChildList(List<AuthPermissionRule> list, AuthPermissionRule t) {
|
|
|
|
|
List<AuthPermissionRule> tlist = new ArrayList<AuthPermissionRule>();
|
|
|
|
|
for (AuthPermissionRule n : list) {
|
|
|
|
|
if (n.getPid().longValue() == t.getId().longValue()) {
|
|
|
|
|
tlist.add(n);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return tlist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断是否有子节点
|
|
|
|
|
*/
|
|
|
|
|
private boolean hasChild(List<AuthPermissionRule> list, AuthPermissionRule t) {
|
|
|
|
|
return getChildList(list, t).size() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 内链域名特殊字符替换
|
|
|
|
|
*
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public String innerLinkReplaceEach(String path) {
|
|
|
|
|
return StringUtils.replaceEach(path, new String[]{Constant.HTTP, Constant.HTTPS, Constant.WWW, "."},
|
|
|
|
|
new String[]{"", ""});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|