fix: 修复生成树的空指针bug

11111
winter 1 year ago
parent 676f6fc46b
commit 46b88742d7

@ -31,11 +31,11 @@ public class EvaluationTreeServiceImpl implements EvaluationTreeService {
}
/**
* , (,)
* , (,)
*/
private void buildChildren(EvaluationTreeNode parent, List<EvaluationTreeNode> nodes) {
List<EvaluationTreeNode> children = getChildren(parent, nodes);
if (children.size() > 0) return;
if (children.size() == 0) return;
parent.setChildren(children);
for (EvaluationTreeNode child : children) {
@ -50,7 +50,7 @@ public class EvaluationTreeServiceImpl implements EvaluationTreeService {
private List<EvaluationTreeNode> getChildren(EvaluationTreeNode parent, List<EvaluationTreeNode> nodes) {
List<EvaluationTreeNode> children = new ArrayList<>();
for (EvaluationTreeNode node : nodes) {
if (node.getPid().equals(parent.getId())) {
if (StringUtils.isNotBlank(node.getPid()) && node.getPid().equals(parent.getId())) {
children.add(node);
}
}

@ -49,16 +49,16 @@ class TeamModelExtensionApplicationTests {
// 2
EvaluationTreeNode node1 = new EvaluationTreeNode();
String subId = UUID.randomUUID().toString();
node.setId(subId);
node.setPid(rootId);
node.setName("child-1");
node.setScore(0);
node1.setId(subId);
node1.setPid(rootId);
node1.setName("child-1");
node1.setScore(0);
// 3
EvaluationTreeNode node2 = new EvaluationTreeNode();
node.setId(UUID.randomUUID().toString());
node.setPid(subId);
node.setName("child-2");
node.setScore(0);
node2.setId(UUID.randomUUID().toString());
node2.setPid(subId);
node2.setName("child-2");
node2.setScore(0);
nodes.add(node);
nodes.add(node1);
nodes.add(node2);

@ -1,7 +1,10 @@
package cn.teammodel;
import cn.teammodel.common.R;
import cn.teammodel.model.entity.EvaluationTree;
import cn.teammodel.model.entity.EvaluationTreeNode;
import cn.teammodel.model.entity.User;
import cn.teammodel.service.impl.EvaluationTreeServiceImpl;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiRobotSendRequest;
@ -10,7 +13,10 @@ import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* @author winter
@ -82,14 +88,38 @@ public class TestWithoutSpring {
}
@Test
public void testResult() {
User user = new User();
user.setId("ds");
user.setName("ds");
user.setPicture("s");
user.setStandard("s");
user.setScope("ad");
user.setWebsite("dsa");
user.setArea("");
System.out.println(R.success(user));
EvaluationTreeServiceImpl service = new EvaluationTreeServiceImpl();
EvaluationTree evaluationTree = new EvaluationTree();
evaluationTree.setCode("evaluation");
evaluationTree.setCampusId("default");
List<EvaluationTreeNode> nodes = new ArrayList<>();
// 1
String rootId = UUID.randomUUID().toString();
EvaluationTreeNode node = new EvaluationTreeNode();
node.setId(rootId);
node.setPid(null);
node.setName("root");
node.setScore(0);
// 2
EvaluationTreeNode node1 = new EvaluationTreeNode();
String subId = UUID.randomUUID().toString();
node1.setId(subId);
node1.setPid(rootId);
node1.setName("child-1");
node1.setScore(0);
// 3
EvaluationTreeNode node2 = new EvaluationTreeNode();
node2.setId(UUID.randomUUID().toString());
node2.setPid(subId);
node2.setName("child-2");
node2.setScore(0);
nodes.add(node);
nodes.add(node1);
nodes.add(node2);
evaluationTree.setNodes(nodes);
List<EvaluationTreeNode> tree = service.buildTree(nodes);
System.out.println(tree);
}
}

Loading…
Cancel
Save