Commit 476f0fde authored by 赵啸非's avatar 赵啸非

更新菜单树列表

parent c0fdc077
package com.mortals.xhx.module.menu.service; package com.mortals.xhx.module.menu.service;
import com.mortals.framework.exception.AppException; import com.mortals.framework.exception.AppException;
import com.mortals.framework.service.ICRUDService; import com.mortals.framework.service.ICRUDService;
import com.mortals.framework.service.IUser; import com.mortals.framework.service.IUser;
...@@ -8,32 +9,21 @@ import java.util.List; ...@@ -8,32 +9,21 @@ import java.util.List;
import java.util.Set; import java.util.Set;
/** /**
* MenuService * MenuService
* * <p>
* 菜单信息业务 service接口 * 菜单信息业务 service接口
* *
* @author zxfei * @author zxfei
* @date 2022-05-25 * @date 2022-05-25
*/ */
public interface MenuService extends ICRUDService<MenuEntity,Long>{ public interface MenuService extends ICRUDService<MenuEntity, Long> {
/**
* 获取所有可用菜单
*
* @return
* @throws AppException
*/
List<MenuEntity> findAllEnable() throws AppException;
/** /**
* 查询有权限的菜单 * 获取所有可用菜单,树结构
* *
* @param user 当前用户
* @param urls 有权限的访问地址集合
* @return * @return
* @throws AppException * @throws AppException
*/ */
List<MenuEntity> findTreeMenu(IUser user, Set<String> urls) throws AppException; List<MenuEntity> findAllEnable() throws AppException;
/** /**
* 查询用户所有权限的菜单 * 查询用户所有权限的菜单
...@@ -44,19 +34,9 @@ public interface MenuService extends ICRUDService<MenuEntity,Long>{ ...@@ -44,19 +34,9 @@ public interface MenuService extends ICRUDService<MenuEntity,Long>{
*/ */
List<MenuEntity> findTreeMenuByUser(IUser user) throws AppException; List<MenuEntity> findTreeMenuByUser(IUser user) throws AppException;
/**
* 查看所有菜单
*
* @return
* @throws AppException
*/
List<MenuEntity> findTreeMenu() throws AppException;
/** /**
* 更新排列顺序 * 更新排列顺序
*
* @param id * @param id
* @param type * @param type
*/ */
......
...@@ -27,92 +27,32 @@ import java.util.*; ...@@ -27,92 +27,32 @@ import java.util.*;
public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity, Long> implements MenuService { public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity, Long> implements MenuService {
@Override @Override
public List<MenuEntity> findAllEnable() throws AppException { public List<MenuEntity> findAllEnable() throws AppException {
MenuQuery params = new MenuQuery(); MenuQuery query = new MenuQuery();
params.setStatus(YesNo.YES.getValue()); query.setStatus(YesNo.YES.getValue());
params.setMenuType(0);//主菜单
List<OrderCol> orderColList = new ArrayList<OrderCol>(); List<OrderCol> orderColList = new ArrayList<OrderCol>();
orderColList.add(new OrderCol("parentId")); orderColList.add(new OrderCol("parentId"));
orderColList.add(new OrderCol("orderId")); orderColList.add(new OrderCol("orderId"));
params.setOrderColList(orderColList); query.setOrderColList(orderColList);
return dao.getList(params);
List<MenuEntity> menuEntityList = this.find(query);
List<MenuEntity> menuTreeList = getChildPerms(menuEntityList, -1);
return menuTreeList;
} }
@Override @Override
public List<MenuEntity> findTreeMenu(IUser user, Set<String> urls) throws AppException { public List<MenuEntity> findTreeMenuByUser(IUser user) throws AppException {
//保存已有菜单
Set<Long> authIds = new HashSet<>();
Map<Long, MenuEntity> menuMap = new HashMap<>();
//获取所有启用的菜单
List<MenuEntity> userModuleList = this.findAllEnable();
for (MenuEntity sysModule : userModuleList) {
if (sysModule == null) {
continue;
}
menuMap.put(sysModule.getId(), sysModule);
if (!user.isAdmin() && urls.contains(StringUtils.trim(sysModule.getUrl()))) {
authIds.add(sysModule.getId());
}
}
if (!user.isAdmin()) { if (!user.isAdmin()) {
Long[] ids = authIds.toArray(new Long[authIds.size()]); List<MenuEntity> menuList = dao.selectMenuTreeByUserId(user.getId());
for (Long id : ids) { //转换为树结构
MenuEntity menu = menuMap.get(id); List<MenuEntity> menuTreeList = getChildPerms(menuList, -1);
//找父节点 return menuTreeList;
while (menu != null) { } else {
authIds.add(menu.getId()); return findAllEnable();
menu = menuMap.get(menu.getParentId());
}
}
}
List<MenuEntity> outlookBar = new ArrayList<>();
List<MenuEntity> norightList = new ArrayList<>();
for (MenuEntity sysModule : userModuleList) {
if (!user.isAdmin() && !authIds.contains(sysModule.getId())) {
norightList.add(sysModule);
continue;
}
if (sysModule.getParentId() == null || sysModule.getParentId().longValue() == 0) {
outlookBar.add(sysModule);
continue;
}
MenuEntity sysModuleParent = menuMap.get(sysModule.getParentId());
if (sysModuleParent != null) {
sysModuleParent.getChildList().add(sysModule);
}
} }
return outlookBar;
} }
@Override
public List<MenuEntity> findTreeMenuByUser(IUser user) throws AppException {
List<MenuEntity> menuList = dao.selectMenuTreeByUserId(user.getId());
//转换为树结构
List<MenuEntity> menuTreeList = getChildPerms(menuList, -1);
return menuTreeList;
}
public List<MenuEntity> findTreeMenu() throws AppException {
Map<Long, MenuEntity> menuMap = new HashMap<>();
List<MenuEntity> userModuleList = this.findAllEnable();
for (MenuEntity sysModule : userModuleList) {
if (sysModule == null) {
continue;
}
menuMap.put(sysModule.getId(), sysModule);
}
List<MenuEntity> outlookBar = new ArrayList<>();
for (MenuEntity sysModule : userModuleList) {
if (sysModule.getParentId() == null || sysModule.getParentId().longValue() == 0) {
outlookBar.add(sysModule);
continue;
}
MenuEntity sysModuleParent = menuMap.get(sysModule.getParentId());
if (sysModuleParent != null) {
sysModuleParent.getChildList().add(sysModule);
}
}
return outlookBar;
}
@Override @Override
public void upOrDown(Long id, Integer type) { public void upOrDown(Long id, Integer type) {
...@@ -191,7 +131,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -191,7 +131,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
public List<MenuEntity> getChildPerms(List<MenuEntity> list, int parentId) { public List<MenuEntity> getChildPerms(List<MenuEntity> list, int parentId) {
List<MenuEntity> returnList = new ArrayList<MenuEntity>(); List<MenuEntity> returnList = new ArrayList<MenuEntity>();
for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) { for (Iterator<MenuEntity> iterator = list.iterator(); iterator.hasNext(); ) {
MenuEntity t =iterator.next(); MenuEntity t = iterator.next();
// 一、根据传入的某个父节点ID,遍历该父节点的所有子节点 // 一、根据传入的某个父节点ID,遍历该父节点的所有子节点
if (t.getParentId() == parentId) { if (t.getParentId() == parentId) {
recursionFn(list, t); recursionFn(list, t);
...@@ -225,7 +165,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity ...@@ -225,7 +165,7 @@ public class MenuServiceImpl extends AbstractCRUDServiceImpl<MenuDao, MenuEntity
List<MenuEntity> tlist = new ArrayList<>(); List<MenuEntity> tlist = new ArrayList<>();
Iterator<MenuEntity> it = list.iterator(); Iterator<MenuEntity> it = list.iterator();
while (it.hasNext()) { while (it.hasNext()) {
MenuEntity n =it.next(); MenuEntity n = it.next();
if (n.getParentId().longValue() == t.getId().longValue()) { if (n.getParentId().longValue() == t.getId().longValue()) {
tlist.add(n); tlist.add(n);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment