// 树形结构递归模糊查询
public SelfTree getTree(String pid, String keywords) {
Tree tree = getTree(pid);
return convert(tree, keywords, new String[]{"N"});
}
private static SelfTree convert(Tree tree, String keywords, String[] flag) {
if (tree == null) {
return null;
}
SelfTree tempTree = new SelfTree();
BeanUtils.copyProperties(tree, tempTree);
tempTree.setChildNodes(new ArrayList<>());
flag[0] = StringUtils.isNotEmpty(tempTree.getName()) && tempTree.getName().contains(keywords) ? flag[0]+"Y" : flag[0]+"N";
List<Tree> childNodes = tree.getChildNodes();
if (CollectionUtils.isNotEmpty(childNodes)) {
for (int i = 0; i < childNodes.size(); i++) {
String[] _var = new String[]{flag[0]+i};
SelfTree convert = convert(childNodes.get(i), keywords, _var);
if (_var[0].contains("Y") || !convert.getChildNodes().isEmpty()) {
tempTree.getChildNodes().add(convert);
}
}
}
return tempTree;
}