List<MenuTree> treeMenu(boolean la, Integer parentId);
@Override
public List<MenuTree> treeMenu(boolean la, Integer parentId) {
if (!lazy) {
return TreeUtil.buildTree(baseMapper.selectList(Wrappers.<SysMenu>lambdaQuery()
.orderByAsc(SysMenu::getSort)), CommonConstants.MENU_TREE_ROOT_ID);
}
Integer parent = parentId == null ? CommonConstants.MENU_TREE_ROOT_ID : parentId;
return TreeUtil.buildTree(baseMapper
.selectList(Wrappers.<SysMenu>lambdaQuery().eq(SysMenu::getParentId, parent)
.orderByAsc(SysMenu::getSort)), parent);
}
public List<MenuTree> buildTree(List<SysMenu> menus, int root) {
List<MenuTree> trees = new ArrayList<>();
MenuTree node;
for (SysMenu menu : menus) {
node = new MenuTree();
node.setId(menu.getMenuId());
node.setParentId(menu.getParentId());
node.setName(menu.getName());
node.setPath(menu.getPath());
node.setPermission(menu.getPermission());
node.setLabel(menu.getName());
node.setIcon(menu.getIcon());
node.setType(menu.getType());
node.setSort(menu.getSort());
node.setHasChildren(true);
node.setKeepAlive(menu.getKeepAlive());
trees.add(node);
}
return TreeUtil.build(trees, root);
}
public <T extends TreeNode> List<T> build(List<T> treeNodes, Object root) {
List<T> trees = new ArrayList<>();
for (T treeNode : treeNodes) {
if (root.equals(treeNode.getParentId())) {
trees.add(treeNode);
}
for (T it : treeNodes) {
if (it.getParentId() == treeNode.getId()) {
if (treeNode.getChildren() == null) {
treeNode.setChildren(new ArrayList<>());
}
treeNode.add(it);
}
}
if (treeNode.getChildren().size() == 0) {
List<TreeNode> sizeBland = treeNode.getChildren();
sizeBland = null;
}
}
return trees;
}
public <T extends TreeNode> List<T> buildByRecursive(List<T> treeNodes, Object root) {
List<T> trees = new ArrayList<T>();
for (T treeNode : treeNodes) {
if (root.equals(treeNode.getParentId())) {
trees.add(findChildren(treeNode, treeNodes));
}
}
return trees;
}
public <T extends TreeNode> T findChildren(T treeNode, List<T> treeNodes) {
for (T it : treeNodes) {
if (treeNode.getId() == it.getParentId()) {
if (treeNode.getChildren() == null) {
treeNode.setChildren(new ArrayList<>());
}
treeNode.add(findChildren(it, treeNodes));
if (treeNode.getChildren().size() == 0) {
List<TreeNode> children = treeNode.getChildren();
children = null;
}
}
}
return treeNode;
}
@Data
@ApiModel(value = "树形节点")
public class TreeNode {
@ApiModelProperty(value = "当前节点id")
protected int id;
@ApiModelProperty(value = "父节点id")
protected int parentId;
@ApiModelProperty(value = "子节点列表")
protected List<TreeNode> children = new ArrayList<TreeNode>();
@ApiModelProperty(value = "企业树中的车辆信息")
protected List<CarInfoVO> carInfoVOList;
@ApiModelProperty(value = "部门员工")
List<UserVO> staff;
public void add(TreeNode node) {
children.add(node);
}
}
@Data
@ApiModel(value = "菜单树")
@EqualsAndHashCode(callSuper = true)
public class MenuTree extends TreeNode implements Serializable {
@ApiModelProperty(value = "菜单图标")
private String icon;
@ApiModelProperty(value = "菜单名称")
private String name;
private boolean spread = false;
@ApiModelProperty(value = "前端路由标识路径")
private String path;
@ApiModelProperty(value = "路由缓冲")
private String keepAlive;
@ApiModelProperty(value = "权限编码")
private String permission;
@ApiModelProperty(value = "菜单类型,0:菜单 1:按钮")
private String type;
@ApiModelProperty(value = "菜单标签")
private String label;
@ApiModelProperty(value = "排序值")
private Integer sort;
private Boolean hasChildren;
public MenuTree() {
}
public MenuTree(int id, String name, int parentId) {
this.id = id;
this.parentId = parentId;
this.name = name;
this.label = name;
}
public MenuTree(int id, String name, MenuTree parent) {
this.id = id;
this.parentId = parent.getId();
this.name = name;
this.label = name;
}
public MenuTree(MenuVO menuVo) {
this.id = menuVo.getMenuId();
this.parentId = menuVo.getParentId();
this.icon = menuVo.getIcon();
this.name = menuVo.getName();
this.path = menuVo.getPath();
this.type = menuVo.getType();
this.permission = menuVo.getPermission();
this.label = menuVo.getName();
this.sort = menuVo.getSort();
this.keepAlive = menuVo.getKeepAlive();
}