完善删除功能,目前删除标签的同时会删除所有子标签
This commit is contained in:
+33
-1
@@ -143,7 +143,8 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
||||
|
||||
@Override
|
||||
public boolean deleteById(String id) {
|
||||
int i = treeLabelDao.deleteById(id);
|
||||
List<String> nodeAndChildrenIds = findNodeAndChildrenIds(getTreeLabelRoot(), id).stream().distinct().collect(Collectors.toList());
|
||||
int i = treeLabelDao.deleteBatchIds(nodeAndChildrenIds);
|
||||
return i != 0;
|
||||
}
|
||||
|
||||
@@ -176,6 +177,37 @@ public class ITreeLabelServiceImpl extends ServiceImpl<TreeLabelDao, TreeLabelEn
|
||||
newRoot.setChildren(childLabel.isEmpty() ? null : childLabel);
|
||||
return root.getLabel().contains(name) || !childLabel.isEmpty() ? newRoot : null;
|
||||
}
|
||||
|
||||
public static List<String> findNodeAndChildrenIds(TreeLabelVo root, String nodeId) {
|
||||
List<String> result = new ArrayList<>();
|
||||
if (root == null) {
|
||||
return result;
|
||||
}
|
||||
if (root.getId().equals(nodeId)) {
|
||||
result.add(root.getId());
|
||||
collectChildrenIds(root, result);
|
||||
} else {
|
||||
for (TreeLabelVo child : root.getChildren()) {
|
||||
List<String> childResult = findNodeAndChildrenIds(child, nodeId);
|
||||
if (!childResult.isEmpty()) {
|
||||
result.addAll(childResult);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void collectChildrenIds(TreeLabelVo node, List<String> result) {
|
||||
result.add(node.getId());
|
||||
for (TreeLabelVo child : node.getChildren()) {
|
||||
collectChildrenIds(child, result);
|
||||
}
|
||||
}
|
||||
|
||||
private TreeLabelVo getTreeLabelRoot() {
|
||||
return getTreeLabellist(null).get(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user