✨ Introducing new features. close #3530 部门树、菜单树支持按名称检索 方便使用

This commit is contained in:
lbw committed 2022-01-04 17:08:22 +08:00
1 parent 8e12472ac4
commit 9a3985ff94
6 files changed
+44 -23

No files matched your search

@@ -64,11 +64,12 @@ public class SysDeptController {
/**
* 返回树形菜单集合
* @param deptName 部门名称
* @return 树形菜单
*/
@GetMapping(value = "/tree")
public R getTree() {
return R.ok(sysDeptService.selectTree());
public R getTree(String deptName) {
return R.ok(sysDeptService.selectTree(deptName));
}
/**
@@ -63,13 +63,13 @@ public class SysMenuController {
/**
* 返回树形菜单集合
* @param lazy 是否是懒加载
* @param parentId 父节点ID
* @param menuName 菜单名称
* @return 树形菜单
*/
@GetMapping(value = "/tree")
public R getTree(boolean lazy, Long parentId) {
return R.ok(sysMenuService.treeMenu(lazy, parentId));
public R getTree(Long parentId, String menuName) {
return R.ok(sysMenuService.treeMenu(parentId, menuName));
}
/**
@@ -38,8 +38,9 @@ public interface SysDeptService extends IService<SysDept> {
/**
* 查询部门树菜单
* @return 树
* @param deptName 部门名称
*/
List<Tree<Long>> selectTree();
List<Tree<Long>> selectTree(String deptName);
/**
* 添加信息部门
@@ -60,11 +60,11 @@ public interface SysMenuService extends IService<SysMenu> {
/**
* 构建树
* @param lazy 是否是懒加载
* @param parentId 父节点ID
* @param menuName 菜单名称
* @return
*/
List<Tree<Long>> treeMenu(boolean lazy, Long parentId);
List<Tree<Long>> treeMenu(Long parentId, String menuName);
/**
* 查询菜单
@@ -23,6 +23,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.entity.SysDept;
@@ -115,15 +116,18 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
/**
* 查询全部部门树
* @return 树
* @return 树 部门名称
* @param deptName
*/
@Override
public List<Tree<Long>> selectTree() {
public List<Tree<Long>> selectTree(String deptName) {
// 查询全部部门
List<SysDept> deptAllList = deptMapper.selectList(Wrappers.emptyWrapper());
List<SysDept> deptAllList = deptMapper
.selectList(Wrappers.<SysDept>lambdaQuery().like(SysDept::getName, deptName));
// 查询数据权限内部门
List<Long> deptOwnIdList = deptMapper.selectListByScope(Wrappers.emptyWrapper(), new DataScope()).stream()
.map(SysDept::getDeptId).collect(Collectors.toList());
List<Long> deptOwnIdList = deptMapper
.selectListByScope(Wrappers.<SysDept>lambdaQuery().like(SysDept::getName, deptName), new DataScope())
.stream().map(SysDept::getDeptId).collect(Collectors.toList());
// 权限内部门
List<TreeNode<Long>> collect = deptAllList.stream()
@@ -142,6 +146,16 @@ public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept> impl
return treeNode;
}).collect(Collectors.toList());
// 模糊查询 不组装树结构 直接返回 表格方便编辑
if (StrUtil.isNotBlank(deptName)) {
return collect.stream().map(node -> {
Tree<Long> tree = new Tree<>();
tree.putAll(node.getExtra());
BeanUtils.copyProperties(node, tree);
return tree;
}).collect(Collectors.toList());
}
return TreeUtil.build(collect, 0L);
}
@@ -23,6 +23,7 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.tree.Tree;
import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.lang.tree.TreeUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pigx.admin.api.entity.SysMenu;
@@ -35,6 +36,7 @@ import com.pig4cloud.pigx.common.core.constant.CommonConstants;
import com.pig4cloud.pigx.common.core.constant.enums.MenuTypeEnum;
import com.pig4cloud.pigx.common.core.util.R;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
@@ -94,25 +96,28 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
* 构建树查询 1. 不是懒加载情况,查询全部 2. 是懒加载,根据parentId 查询 2.1 父节点为空,则查询ID -1
* @param lazy 是否是懒加载
* @param parentId 父节点ID
* @param menuName 菜单名称
* @return
*/
@Override
public List<Tree<Long>> treeMenu(boolean lazy, Long parentId) {
if (!lazy) {
List<TreeNode<Long>> collect = baseMapper
.selectList(Wrappers.<SysMenu>lambdaQuery().orderByAsc(SysMenu::getSortOrder)).stream()
.map(getNodeFunction()).collect(Collectors.toList());
return TreeUtil.build(collect, CommonConstants.MENU_TREE_ROOT_ID);
}
public List<Tree<Long>> treeMenu(Long parentId, String menuName) {
Long parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
List<TreeNode<Long>> collect = baseMapper
.selectList(Wrappers.<SysMenu>lambdaQuery().eq(SysMenu::getParentId, parent)
.selectList(Wrappers.<SysMenu>lambdaQuery().like(SysMenu::getName, menuName)
.orderByAsc(SysMenu::getSortOrder))
.stream().map(getNodeFunction()).collect(Collectors.toList());
// 模糊查询 不组装树结构 直接返回 表格方便编辑
if (StrUtil.isNotBlank(menuName)) {
return collect.stream().map(node -> {
Tree<Long> tree = new Tree<>();
tree.putAll(node.getExtra());
BeanUtils.copyProperties(node, tree);
return tree;
}).collect(Collectors.toList());
}
return TreeUtil.build(collect, parent);
}