提示:平铺数据转为层级树状数据结构
一、代码如下:
//查询数据源信息
List jyeooSectionPos = getJyeooSectionPos(bookId);
if (!CollectionUtils.isEmpty(jyeooSectionPos)) {
//2.组装成知识点树
List yunhenPointVos = new ArrayList<>();
if (CollectionUtils.isEmpty(jyeooSectionPos)) {
return ResultUtil.createResult(true, "查询成功!", yunhenPointVos);
}
if (!CollectionUtils.isEmpty(jyeooSectionPos)) {
for (JyeooSectionPo yunhenPointPo : jyeooSectionPos) {
JyeooSectionTreeOutVo yunhenPointVo = new JyeooSectionTreeOutVo();
BeanUtil.copyProperties(yunhenPointPo, yunhenPointVo);
yunhenPointVos.add(yunhenPointVo);
}
}
//获取第一层知识点
List firstLevelPoints = new ArrayList<>();
for (JyeooSectionTreeOutVo yunhenPointVo : yunhenPointVos) {
String pid = yunhenPointVo.getPid();
if (StringUtils.isEmpty(pid)) {
firstLevelPoints.add(yunhenPointVo);
List subPointTree = getPointTree(yunhenPointVos, yunhenPointVo.getId());
yunhenPointVo.setChildren(subPointTree);
}
//可以排序
}
return ResultUtil.createResult(true, "查询成功!", firstLevelPoints);
}
public List getPointTree(List yunhenPointVos, String id) {
if (yunhenPointVos == null || yunhenPointVos.size() == 0) {
return null;
}
List list = new ArrayList<>();
List listContinue = new ArrayList<>(yunhenPointVos);
for (JyeooSectionTreeOutVo yunhenPointVo : yunhenPointVos) {
if (id.equals(yunhenPointVo.getPid())) {
listContinue.remove(yunhenPointVo);
yunhenPointVo.setChildren(getPointTree(listContinue, yunhenPointVo.getId()));
list.add(yunhenPointVo);
}
}
if (list.size() == 0) {
return null;
}
return list;
}
2.JyeooSectionTreeOutVo实体
代码如下(示例):
package com.yunhenedu.homework.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Data
public class JyeooSectionTreeOutVo implements Cloneable, Serializable {
private String id;
private String jyeooId;
private String pjyeooId;
private String pid;
private String seq;
private String name;
private String describes;
private String editionDetailId;
private String editionDetailJyeooId;
private String subjectEn;
@ApiModelProperty("子知识点列表")
private List children;
}
该处使用的url网络请求的数据。
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。



