菜单对象
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.zcckj.common.model.dto.BaseDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotBlank;
import java.util.List;
/**
* @author fsren
* @date 2019-09-10
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel
public class DistributorMenuDTO extends BaseDTO {
/**
* 菜单名称
*/
@NotBlank(groups = {Save.class}, message = "菜单名称不可为空")
@ApiModelProperty(value = "菜单名称")
private String name;
/**
* 菜单URL
*/
@ApiModelProperty(value = "菜单URL")
private String url;
/**
* 授权(多个用逗号分隔,如:user:list,user:create)
*/
@ApiModelProperty(value = "授权(多个用逗号分隔,如:user:list,user:create)")
private String authorities;
/**
* 类型(0:目录 1:菜单 2:按钮)
*/
@Min(groups = {Save.class}, value = 0, message = "0:目录 1:菜单 2:按钮")
@Max(groups = {Save.class}, value = 2, message = "0:目录 1:菜单 2:按钮")
@ApiModelProperty(value = "类型(0:目录 1:菜单 2:按钮)")
private Integer type;
/**
* 描述
*/
@ApiModelProperty(value = "描述")
private String description;
/**
* 父级ID
*/
@Min(groups = {Save.class}, value = 0, message = "父级ID应为正整数")
@ApiModelProperty(value = "父级ID")
private Long parentId;
/**
* 排序
*/
@ApiModelProperty(value = "排序")
@Min(groups = {Save.class}, value = 0, message = "排序值应大于0")
private Integer sort;
/**
* 账号是否删除
*/
@JsonIgnore
@ApiModelProperty(value = "是否删除")
private Boolean isDelete;
/**
* @author l'amour solitaire
* @description 是否有权限(查询)
* @date 2019/10/16 下午5:04
*/
@ApiModelProperty(value = "是否有权限")
private Boolean haveJurisdiction;
/**
* 子项
*/
@ApiModelProperty(value = "子项")
private List<DistributorMenuDTO> children;
public interface Search {
}
}
递归
/**
* @author l'amour solitaire
* @description 递归菜单
* @date 2020/3/24 下午3:12
*/
private static List<DistributorMenuDTO> makeTree(List<DistributorMenuDTO> distributorMenuList, Long pId) {
List<DistributorMenuDTO> children = distributorMenuList.stream().filter(x -> x.getParentId().equals(pId)).collect(Collectors.toList());
List<DistributorMenuDTO> successor = distributorMenuList.stream().filter(x -> !x.getParentId().equals(pId)).collect(Collectors.toList());
children.forEach(x -> x.setChildren(makeTree(successor, x.getId())));
return children;
}