package com.supervision.police.dto; import cn.hutool.core.collection.CollUtil; import com.supervision.police.domain.SystemMenu; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import java.util.ArrayList; import java.util.List; import java.util.Objects; @Data public class MenuDTO { @Schema(description = "菜单id") private String id; @Schema(description = "标签(菜单名或按钮名)") private String label; @Schema(description = "标签码 前端权限使用") private String labelCode; @Schema(description = "标签类型 0: 菜单 1:标签 默认菜单") private Integer labelType; @Schema(description = "父级id") private String parentId; @Schema(description = "子菜单") private List children; public MenuDTO() { } public MenuDTO(String id) { this.id = id; } public MenuDTO(SystemMenu systemMenu) { if (Objects.isNull(systemMenu)){ return; } this.id = systemMenu.getId(); this.label = systemMenu.getLabel(); this.labelCode = systemMenu.getLabelCode(); this.labelType = systemMenu.getLabelType(); this.parentId = systemMenu.getParentId(); } public List floatMenu(){ List menuDTOS = new ArrayList<>(); menuDTOS.add(this); if (CollUtil.isNotEmpty(this.children)){ for (MenuDTO child : this.children) { menuDTOS.addAll(child.floatMenu()); } } return menuDTOS; } public List seekMenu(String menuId) { List menuDTOS = new ArrayList<>(); if (this.getId().equals(menuId)) { menuDTOS.add(this); return menuDTOS; } if (CollUtil.isNotEmpty(this.children)) { for (MenuDTO child : this.children) { List seekList = child.seekMenu(menuId); if (!seekList.isEmpty()) { menuDTOS.add(this); menuDTOS.addAll(seekList); return menuDTOS; } } } return menuDTOS; } }