Skip to content

Commit

Permalink
fix-DictCategoryController-修正tree接口获取到的子孙数据没有value的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
aruis committed Oct 23, 2024
1 parent d11898e commit 0fce735
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ void testDictCategoryAdd() {
.extract()
.asString();

given()
List<Map> responsex = given()
.header("userID", config.superUserId())
.get("%s/dict/tree/%s".formatted(base, "root1"))
.then()
Expand All @@ -194,10 +194,9 @@ void testDictCategoryAdd() {
.as(new TypeRef<>() {
});

// assertEquals(response.size(), 3);
// node = response.get(0);
// assertEquals(node.getChildren().size(), 1);
// assertNotNull(node.getValue());
assertEquals(responsex.size(), 3);
Map nodex = ((List<Map>) responsex.get(0).get("children")).get(0);
assertNotNull(nodex.get("value"));

List<DictTreeNode> response2 = given()
.header("userID", config.superUserId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ default Integer update(@PathParam("id") String id, Map body) {
return result;
}

private boolean isIdInTree(List<TreeNode> tree, String id) {
private boolean isIdInTree(List<? extends TreeNode> tree, String id) {
for (TreeNode node : tree) {
if (node.getId().equals(id)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TreeNode {
@Schema(description = "数据内容")
private Map<String, Object> data;
@Schema(description = "子节点")
private List<TreeNode> children;
private List<? extends TreeNode> children;

public TreeNode() {
}
Expand All @@ -31,7 +31,7 @@ public Map<String, Object> getData() {
return data;
}

public List<TreeNode> getChildren() {
public List<? extends TreeNode> getChildren() {
return children;
}

Expand All @@ -51,7 +51,7 @@ public TreeNode setData(Map<String, Object> data) {
}

public TreeNode setChildren(List<? extends TreeNode> children) {
this.children = (List<TreeNode>) children;
this.children = children;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private List<DictTreeNode> nodeToDictNode(List<? extends TreeNode> list) {
return list.stream().map(it -> {
DictTreeNode node = DictTreeNode.from(it)
.setValue(it.getData().get("v_value").toString());
List<TreeNode> children = node.getChildren();
List<? extends TreeNode> children = node.getChildren();
if (children != null && !children.isEmpty()) {
node.setChildren(nodeToDictNode(children));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private List<TreeNode> filterMenuByAuth(List<TreeNode> list) {
return filterMenuByAuth(list, authorizedResources);
}

private List<TreeNode> filterMenuByAuth(List<TreeNode> list, Map<String, Set<String>> resources) {
private List<TreeNode> filterMenuByAuth(List<? extends TreeNode> list, Map<String, Set<String>> resources) {
List<TreeNode> result = new ArrayList<>();
for (TreeNode node : list) {
Map data = node.getData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import net.ximatai.muyun.model.TreeNode;
import org.eclipse.microprofile.openapi.annotations.media.Schema;

import java.util.List;

public class DictTreeNode extends TreeNode {
@Schema(description = "字典值")
private String value;
Expand All @@ -23,4 +25,9 @@ public DictTreeNode setValue(String value) {
this.value = value;
return this;
}

@Override
public List<DictTreeNode> getChildren() {
return (List<DictTreeNode>) super.getChildren();
}
}

0 comments on commit 0fce735

Please sign in to comment.