You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fu-hsi-service/src/main/java/com/supervision/police/dto/MenuDTO.java

83 lines
2.1 KiB
Java

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<MenuDTO> 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<MenuDTO> floatMenu(){
List<MenuDTO> menuDTOS = new ArrayList<>();
menuDTOS.add(this);
if (CollUtil.isNotEmpty(this.children)){
for (MenuDTO child : this.children) {
menuDTOS.addAll(child.floatMenu());
}
}
return menuDTOS;
}
public List<MenuDTO> seekMenu(String menuId) {
List<MenuDTO> menuDTOS = new ArrayList<>();
if (this.getId().equals(menuId)) {
menuDTOS.add(this);
return menuDTOS;
}
if (CollUtil.isNotEmpty(this.children)) {
for (MenuDTO child : this.children) {
List<MenuDTO> seekList = child.seekMenu(menuId);
if (!seekList.isEmpty()) {
menuDTOS.add(this);
menuDTOS.addAll(seekList);
return menuDTOS;
}
}
}
return menuDTOS;
}
}