update redis调整
This commit is contained in:
parent
42543ce7c7
commit
6a78f14eec
|
|
@ -0,0 +1,115 @@
|
|||
package com.tacit.admin.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tacit.common.entity.Base;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@TableName("sys_menu")
|
||||
public class Menu extends Base implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
// 菜单ID
|
||||
@TableId(type = IdType.AUTO)
|
||||
@TableField("menu_id")
|
||||
private Long menuId;
|
||||
// 菜单名称
|
||||
@TableField("menu_name")
|
||||
private String menuName;
|
||||
// 父菜单ID
|
||||
@TableField("parent_id")
|
||||
private Long parentId;
|
||||
// 菜单等级
|
||||
@TableField("level")
|
||||
private String level;
|
||||
// 显示顺序
|
||||
@TableField("order_num")
|
||||
private Integer orderNum;
|
||||
// 菜单图标
|
||||
@TableField("icon")
|
||||
private String icon;
|
||||
// 路由地址
|
||||
@TableField("path")
|
||||
private String path;
|
||||
// 路由参数
|
||||
@TableField("query")
|
||||
private String query;
|
||||
// 是否为外链(0是 1否)
|
||||
@TableField("is_frame")
|
||||
private Integer isFrame;
|
||||
// 是否缓存(0缓存 1不缓存)
|
||||
@TableField("is_cache")
|
||||
private Integer isCache;
|
||||
// 菜单类型(M目录 C菜单 F按钮)
|
||||
@TableField("menu_type")
|
||||
private String menuType;
|
||||
// 菜单状态(0显示 1隐藏)
|
||||
@TableField("visible")
|
||||
private String visible;
|
||||
// 菜单状态(0正常 1停用)
|
||||
@TableField("status")
|
||||
private String status;
|
||||
// 菜单备注
|
||||
@TableField("remark")
|
||||
private String remark;
|
||||
// 创建者
|
||||
@TableField("create_by")
|
||||
private String createBy;
|
||||
// 更新者
|
||||
@TableField("update_by")
|
||||
private String updateBy;
|
||||
|
||||
// 子菜单列表
|
||||
@TableField(exist = false)
|
||||
private List<Menu> children;
|
||||
|
||||
/**
|
||||
* 将菜单列表转换为树形结构
|
||||
* @param menuList 菜单列表
|
||||
* @return 树形结构的菜单列表
|
||||
*/
|
||||
public static List<Menu> buildTree(List<Menu> menuList) {
|
||||
if (menuList == null || menuList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 找到所有根节点(parentId为0或null)
|
||||
List<Menu> rootMenus = menuList.stream()
|
||||
.filter(menu -> menu.getParentId() == null || menu.getParentId() == 0)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 为每个根节点添加子节点
|
||||
rootMenus.forEach(rootMenu -> {
|
||||
addChildren(rootMenu, menuList);
|
||||
});
|
||||
|
||||
return rootMenus;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归添加子节点
|
||||
* @param parentMenu 父菜单
|
||||
* @param menuList 所有菜单列表
|
||||
*/
|
||||
private static void addChildren(Menu parentMenu, List<Menu> menuList) {
|
||||
// 找到所有父节点的直接子节点
|
||||
List<Menu> children = menuList.stream()
|
||||
.filter(menu -> parentMenu.getMenuId().equals(menu.getParentId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!children.isEmpty()) {
|
||||
// 设置子节点
|
||||
parentMenu.setChildren(children);
|
||||
// 递归添加子节点的子节点
|
||||
children.forEach(child -> {
|
||||
addChildren(child, menuList);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue