List<StyleDto> styleDtos2 = TreeBuilder.buildByLoopV2(styleDtos);将List<StyleDto> styleDtos列表转换为数据列表
与数据库对应的对象Style
@Data
@Entity
@TableName("style")
public class Style extends AuditableIdModel {
@Schema(description = "款式名称")
private String styleName;
@Schema(description = "款式编码")
private String styleCode;
@Schema(description = "款式性别(0女、1男)")
private Boolean styleGender;
@Schema(description = "父级id(0代表当前是父级)")
private Long parentId;
@Schema(description = "号型系列")
private String sizeSeries;
@Schema(description = "款式单耗")
private String styleUnitConsumption;
@Schema(description = "产品类型")
private String productType;
@Schema(description = "产品性别(0女、1男)")
private Boolean productGender;
@Schema(description = "上下装(0上装、1下装)")
private Boolean separates;
@Schema(description = "使用版型")
private String pattern;
@Schema(description = "状态(0待审核、1已通过、2已驳回)")
private Integer state;
@Schema(description = "是否启用(0禁用、1启用)")
private Boolean disabled;
@Schema(description = "胸围放松量,单位cm")
private String bustEase;
@Schema(description = "腰围放松量,单位cm")
private String waistlineEase;
@Schema(description = "臀围放松量,单位cm")
private String hipEase;
@Schema(description = "外形特征")
private String appearanceCharacteristics;
@Schema(description = "外形图")
private String appearanceImg;
}
列表输出时的对象StyleDto,继承了TreeNode
@Data
public class StyleDto extends TreeNode {
@Schema(description = "id")
private Long id;
@Schema(description = "款式名称")
private String styleName;
@Schema(description = "款式编码")
private String styleCode;
@Schema(description = "款式性别(0女、1男)")
private Boolean styleGender;
@Schema(description = "父级id(0代表当前是父级)")
private Long parentId;
@Schema(description = "号型系列")
private String sizeSeries;
@Schema(description = "款式单耗")
private String styleUnitConsumption;
@Schema(description = "产品类型")
private String productType;
@Schema(description = "产品性别(0女、1男)")
private Boolean productGender;
@Schema(description = "上下装(0上装、1下装)")
private Boolean separates;
@Schema(description = "使用版型")
private String pattern;
@Schema(description = "状态(0待审核、1已通过、2已驳回)")
private Integer state;
@Schema(description = "是否启用(0禁用、1启用)")
private Boolean disabled;
@Schema(description = "胸围放松量,单位cm")
private String bustEase;
@Schema(description = "腰围放松量,单位cm")
private String waistlineEase;
@Schema(description = "臀围放松量,单位cm")
private String hipEase;
@Schema(description = "外形特征")
private String appearanceCharacteristics;
@Schema(description = "外形图")
private String appearanceImg;
@Schema(description = "创建人")
private Long createdById;
@Schema(description = "创建人名称")
private String createdByName;
@Schema(description = "创建时间")
private LocalDateTime createdTime;
@Schema(description = "更新人")
private Long updatedById;
@Schema(description = "更新人名称")
private String updatedByName;
@Schema(description = "更新时间")
private LocalDateTime updatedTime;
}
List<Style> styleList = styleMapper.selectStyleList(styleName, styleCode, productType); List<StyleDto> styleDtos = convertToDtoList(styleList); List<StyleDto> styleDtos2 = TreeBuilder.buildByLoopV2(styleDtos);
TreeBuilder.buildByLoopV2()
public final class TreeBuilder {
public static <T extends TreeNode> List<T> buildByLoop(List<T> treeNodes, @NotNull Serializable root) {
List<T> trees = new ArrayList();
Iterator var3 = treeNodes.iterator();
while(var3.hasNext()) {
T treeNode = (TreeNode)var3.next();
if (root.equals(treeNode.getParentId())) {
trees.add(treeNode);
}
Iterator var5 = treeNodes.iterator();
while(var5.hasNext()) {
T it = (TreeNode)var5.next();
if (it.getParentId().equals(treeNode.getId())) {
if (treeNode.getChildren() == null) {
treeNode.setChildren(new ArrayList());
}
treeNode.add(it);
}
}
}
return trees;
}
public static <T extends TreeNode> List<T> buildByLoopV2(List<T> BaseTrees) {
List<T> trees = new ArrayList();
List<Serializable> collect = (List)BaseTrees.stream().map(TreeNode::getId).collect(Collectors.toList());
Iterator var3 = BaseTrees.iterator();
while(var3.hasNext()) {
T BaseTree = (TreeNode)var3.next();
Serializable parentId = BaseTree.getParentId();
if (!collect.contains(parentId)) {
trees.add(BaseTree);
}
Iterator var6 = BaseTrees.iterator();
while(var6.hasNext()) {
T it = (TreeNode)var6.next();
if (it.getParentId().equals(BaseTree.getId())) {
if (BaseTree.getChildren() == null) {
BaseTree.setChildren(new ArrayList());
}
BaseTree.add(it);
}
}
}
return trees;
}
}