提示:平铺数据转为层级树状数据结构
一、代码如下:
//查询数据源信息
List<JyeooSectionPo> jyeooSectionPos = getJyeooSectionPos(bookId);
if (!CollectionUtils.isEmpty(jyeooSectionPos)) {
//2.组装成知识点树
List<JyeooSectionTreeOutVo> 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<JyeooSectionTreeOutVo> firstLevelPoints = new ArrayList<>();
for (JyeooSectionTreeOutVo yunhenPointVo : yunhenPointVos) {
String pid = yunhenPointVo.getPid();
if (StringUtils.isEmpty(pid)) {
firstLevelPoints.add(yunhenPointVo);
List<JyeooSectionTreeOutVo> subPointTree = getPointTree(yunhenPointVos, yunhenPointVo.getId());
yunhenPointVo.setChildren(subPointTree);
}
//可以排序
}
return ResultUtil.createResult(true, "查询成功!", firstLevelPoints);
}
/**
* @Description: 将平级的维度列表,构造成树形结构的维度信息
* @Param: [yunhenPointVos, id]
* @Return: List
* @Author: gx
* @CreateDate
* @UpdateDate
*/
public List<JyeooSectionTreeOutVo> getPointTree(List<JyeooSectionTreeOutVo> yunhenPointVos, String id) {
if (yunhenPointVos == null || yunhenPointVos.size() == 0) {
return null;
}
List<JyeooSectionTreeOutVo> list = new ArrayList<>();
List<JyeooSectionTreeOutVo> 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;
/**
* 菁优id
*/
private String jyeooId;
/**
* 父菁优id
*/
private String pjyeooId;
/**
* 父id
*/
private String pid;
/**
* 排序号
*/
private String seq;
/**
* 章节名
*/
private String name;
/**
* 描述
*/
private String describes;
/**
* 版本详情主键
*/
private String editionDetailId;
/**
* 版本详情菁优id
*/
private String editionDetailJyeooId;
/**
* 学科英文名
*/
private String subjectEn;
@ApiModelProperty("子知识点列表")
private List<JyeooSectionTreeOutVo> children;
}
该处使用的url网络请求的数据。
总结
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)