判断是否存在子集
private static boolean ifChilds(List<?> list) {
boolean flag = false;
if (list != null && list.size() != 0) {
flag = true;
}
return flag;
}
List 转换成 Tree
public List<BibookInvestmentPlanEntity> buildByRecursive(List<BibookInvestmentPlanEntity> treeEntity) {
List<BibookInvestmentPlanEntity> trees = new ArrayList<BibookInvestmentPlanEntity>();
for (BibookInvestmentPlanEntity en : treeEntity) {
if ("0".equals(en.getPid())) {
trees.add(findChildren(en, treeEntity));
}
}
return trees;
}
public BibookInvestmentPlanEntity findChildren(BibookInvestmentPlanEntity entity, List<BibookInvestmentPlanEntity> treeEntity) {
for (BibookInvestmentPlanEntity it : treeEntity) {
if (entity.getInvestmentPlanId().equals(it.getPid())) {
if (entity.getChildren() == null) {
entity.setChildren(new ArrayList<BibookInvestmentPlanEntity>());
}
entity.getChildren().add(findChildren(it, treeEntity));
}
}
return entity;
}
Tree 转换成 List
private List<BibookInvestmentPlanEntity> getTreeChangeList(List<BibookInvestmentPlanEntity> lists){
List<BibookInvestmentPlanEntity> list = new ArrayList<>();
lists.forEach(o->{
this.treeToList(o,list);
});
return list;
}
public void treeToList(BibookInvestmentPlanEntity node,List<BibookInvestmentPlanEntity> list){
if(list==null){
list=new ArrayList<BibookInvestmentPlanEntity>();
}
BibookInvestmentPlanEntity nodeValue= new BibookInvestmentPlanEntity(
node.getId(),node.getInvestmentPlanId(),node.getCourseNumber(),node.getCourseLevel(),node.getCourseName(),
node.getPid(),node.getNormTotal(),node.getNormUnilateral(),node.getAdjustTotal(),node.getAdjustUnilateral(),
node.getManual(),node.getInvestType(),node.getInvestTypeName(),node.getCreatTime(),node.getSubmitSave(),
node.getCoding(),node.getDataSource(),node.getVersionId(),node.getColum1(),node.getColum2(),
new ArrayList<BibookInvestmentPlanEntity>()
);
list.add(nodeValue);
if(ifChilds(node.getChildren())){
for (int i = 0; i < node.getChildren().size(); i++) {
BibookInvestmentPlanEntity node_= node.getChildren().get(i);
treeToList(node_,list);
}
}
}