forked from rongchao/epmet-cloud-rizhao
				
			
				 9 changed files with 1066 additions and 833 deletions
			
			
		@ -0,0 +1,45 @@ | 
				
			|||
package com.epmet.commons.tools.utils; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
import java.util.ArrayList; | 
				
			|||
import java.util.List; | 
				
			|||
 | 
				
			|||
public class NodeTree<T> implements Serializable { | 
				
			|||
    private static final long serialVersionUID = 8020505121785861117L; | 
				
			|||
    /** | 
				
			|||
     * 主键 | 
				
			|||
     */ | 
				
			|||
    private String id; | 
				
			|||
    /** | 
				
			|||
     * 上级ID | 
				
			|||
     */ | 
				
			|||
    private String pid; | 
				
			|||
    /** | 
				
			|||
     * 子节点列表 | 
				
			|||
     */ | 
				
			|||
    private List<T> children = new ArrayList<>(); | 
				
			|||
 | 
				
			|||
    public String getId() { | 
				
			|||
        return id; | 
				
			|||
    } | 
				
			|||
 | 
				
			|||
    public void setId(String 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,31 @@ | 
				
			|||
package com.epmet.commons.tools.utils; | 
				
			|||
 | 
				
			|||
import java.util.ArrayList; | 
				
			|||
import java.util.LinkedHashMap; | 
				
			|||
import java.util.List; | 
				
			|||
import java.util.Map; | 
				
			|||
 | 
				
			|||
public class NodeTreeUtils { | 
				
			|||
 | 
				
			|||
    public static <T extends NodeTree> List<T> build(List<T> treeNodes) { | 
				
			|||
        List<T> result = new ArrayList<>(); | 
				
			|||
 | 
				
			|||
        //list转map
 | 
				
			|||
        Map<String, 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,39 @@ | 
				
			|||
package com.epmet.dto.result; | 
				
			|||
 | 
				
			|||
 | 
				
			|||
import com.epmet.commons.tools.utils.NodeTree; | 
				
			|||
import lombok.AllArgsConstructor; | 
				
			|||
import lombok.Data; | 
				
			|||
import lombok.NoArgsConstructor; | 
				
			|||
 | 
				
			|||
import java.io.Serializable; | 
				
			|||
import java.util.Date; | 
				
			|||
 | 
				
			|||
@Data | 
				
			|||
@NoArgsConstructor | 
				
			|||
@AllArgsConstructor | 
				
			|||
public class AgencyAddressBookTreeResultDTO extends NodeTree implements Serializable { | 
				
			|||
 | 
				
			|||
    private static final long serialVersionUID = -1993037593855768962L; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 父id | 
				
			|||
     */ | 
				
			|||
    private String pid; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 名字 | 
				
			|||
     */ | 
				
			|||
    private String name; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 级别 | 
				
			|||
     */ | 
				
			|||
    private String level; | 
				
			|||
 | 
				
			|||
    /** | 
				
			|||
     * 创建时间 | 
				
			|||
     */ | 
				
			|||
    private Date createTime; | 
				
			|||
 | 
				
			|||
} | 
				
			|||
					Loading…
					
					
				
		Reference in new issue