25 changed files with 426 additions and 194 deletions
@ -0,0 +1,34 @@ |
|||
package com.epmet.commons.tools.utils; |
|||
|
|||
import java.util.ArrayList; |
|||
import java.util.LinkedHashMap; |
|||
import java.util.List; |
|||
import java.util.Map; |
|||
|
|||
public class LouDongTreeNodeUtils { |
|||
|
|||
/** |
|||
* 构建树节点 |
|||
*/ |
|||
public static <T extends LoudongTreeNode> List<T> build(List<T> treeNodes) { |
|||
List<T> result = new ArrayList<>(); |
|||
|
|||
//list转map
|
|||
Map<Long, T> nodeMap = new LinkedHashMap<>(treeNodes.size()); |
|||
for(T treeNode : treeNodes){ |
|||
nodeMap.put(treeNode.getId(), treeNode); |
|||
} |
|||
|
|||
for(T node : nodeMap.values()) { |
|||
T parent = nodeMap.get(node.getPid()); |
|||
if(parent != null && !(node.getId().equals(parent.getId()))){ |
|||
parent.getChildren().add(node); |
|||
continue; |
|||
} |
|||
|
|||
result.add(node); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
@ -0,0 +1,48 @@ |
|||
package com.epmet.commons.tools.utils; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
|
|||
public class LoudongTreeNode<T> implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
/** |
|||
* 主键 |
|||
*/ |
|||
private Long id; |
|||
/** |
|||
* 上级ID |
|||
*/ |
|||
private String pid; |
|||
/** |
|||
* 子节点列表 |
|||
*/ |
|||
private List<T> children = new ArrayList<>(); |
|||
|
|||
|
|||
public Long getId() { |
|||
return id; |
|||
} |
|||
|
|||
public void setId(Long id) { |
|||
this.id = id; |
|||
} |
|||
|
|||
|
|||
public String getPid() { |
|||
return pid; |
|||
} |
|||
|
|||
public void setPid(String pid) { |
|||
this.pid = pid; |
|||
} |
|||
|
|||
public List<T> getChildren() { |
|||
return children; |
|||
} |
|||
|
|||
public void setChildren(List<T> children) { |
|||
this.children = children; |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
package com.epmet.opendata.dto.result; |
|||
|
|||
import com.epmet.commons.tools.utils.LoudongTreeNode; |
|||
import com.epmet.commons.tools.utils.TreeNode; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
@Data |
|||
public class LouDongCascadeResultDTO extends LoudongTreeNode implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -359443782589013555L; |
|||
|
|||
private String gridId; |
|||
|
|||
private String gridName; |
|||
|
|||
private String communityId; |
|||
|
|||
private String communityName; |
|||
|
|||
private String streetId; |
|||
|
|||
private String streetName; |
|||
|
|||
private String pid; |
|||
|
|||
} |
Loading…
Reference in new issue