-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10473 from dataease/pr@dev-v2@feat_tree_dpi
feat(仪表板): 新增下拉树接口
- Loading branch information
Showing
5 changed files
with
221 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
core/core-backend/src/main/java/io/dataease/dataset/utils/DatasetUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package io.dataease.dataset.utils; | ||
|
||
import io.dataease.api.dataset.dto.BaseTreeNodeDTO; | ||
import io.dataease.utils.TreeUtils; | ||
import org.apache.commons.collections4.CollectionUtils; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.springframework.util.Assert; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* @Author Junjun | ||
*/ | ||
public class DatasetUtils { | ||
public final static String SEPARATOR = "-de-"; | ||
|
||
public static List<BaseTreeNodeDTO> mergeDuplicateTree(List<BaseTreeNodeDTO> tree, String... rootPid) { | ||
Assert.notNull(rootPid, "Root Pid cannot be null"); | ||
if (CollectionUtils.isEmpty(tree)) { | ||
return null; | ||
} | ||
List<BaseTreeNodeDTO> result = new ArrayList<>(); | ||
// 构建id-节点map映射 | ||
Map<String, BaseTreeNodeDTO> treePidMap = tree.stream().collect(Collectors.toMap(node -> node.getNodeType(), t -> t)); | ||
tree.stream().filter(item -> ObjectUtils.isNotEmpty(item.getId())).forEach(node -> { | ||
|
||
String nodeType = node.getNodeType(); | ||
String[] links = nodeType.split(SEPARATOR); | ||
int length = links.length; | ||
int level = Integer.parseInt(links[length - 1]); | ||
// 判断根节点 | ||
if (Arrays.asList(rootPid).contains(node.getPid()) && 0 == level) { | ||
result.add(node); | ||
} else { | ||
//找到父元素 | ||
String[] pLinks = new String[level]; | ||
System.arraycopy(links, 0, pLinks, 0, level); | ||
String parentType = Arrays.stream(pLinks).collect(Collectors.joining(SEPARATOR)) + TreeUtils.SEPARATOR + (level - 1); | ||
BaseTreeNodeDTO parentNode = treePidMap.get(parentType); | ||
if (parentNode == null) { | ||
// 可能出现 rootPid 更高的节点 这个操作相当于截断 | ||
return; | ||
} | ||
if (parentNode.getChildren() == null) { | ||
parentNode.setChildren(new ArrayList()); | ||
} | ||
parentNode.getChildren().add(node); | ||
} | ||
}); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
sdk/api/api-base/src/main/java/io/dataease/api/dataset/dto/BaseTreeNodeDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package io.dataease.api.dataset.dto; | ||
|
||
|
||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
@Data | ||
public class BaseTreeNodeDTO { | ||
|
||
private String id; | ||
|
||
private String pid; | ||
|
||
private String text; | ||
|
||
private String nodeType; | ||
|
||
private List<BaseTreeNodeDTO> children; | ||
|
||
public BaseTreeNodeDTO(String id, String pid, String text, String nodeType) { | ||
this.id = id; | ||
this.pid = pid; | ||
this.text = text; | ||
this.nodeType = nodeType; | ||
} | ||
|
||
} |