|
@@ -60,48 +60,21 @@ public class FaqServiceImpl extends ServiceImpl<FaqMapper, Faq> implements FaqSe
|
|
|
public RestResponse delete(Long id) {
|
|
|
List<Long> ids = new ArrayList<>();
|
|
|
List<Faq> faqs = this.list();
|
|
|
- faqs.forEach(faq -> {
|
|
|
- if (id.equals(faq.getParentId())) {
|
|
|
- ids.add(faq.getParentId());
|
|
|
- ids.addAll(this.d(faq.getParentId()), faqs);
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- if (deleteAll(id)) {
|
|
|
+ ids = this.ids(id, faqs, ids);
|
|
|
+ if (this.removeByIds(ids)) {
|
|
|
return RestResponse.ok(null, "1", "删除成功");
|
|
|
}
|
|
|
return RestResponse.ok(null, "0", "删除失败");
|
|
|
}
|
|
|
|
|
|
- private ArrayList<Integer> d(Long id, List<Faq> faqs) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //递归删除id及它下面所有分类,问答
|
|
|
- private boolean deleteAll(Long id) {
|
|
|
-
|
|
|
-
|
|
|
- //获取父id下的所有子分类或问答
|
|
|
- List<Faq> faqs = this.list(new QueryWrapper<Faq>().eq("parent_id", id));
|
|
|
- //删除父id下的所有子分类或问答
|
|
|
- this.remove(new QueryWrapper<Faq>().eq("parent_id", id));
|
|
|
- //删除自己
|
|
|
- this.remove(new QueryWrapper<Faq>().eq("id", id));
|
|
|
- //如果父id下还有子分类或问答
|
|
|
- if (faqs.size() != 0) {
|
|
|
- //遍历删除自己及删除自己下的所有子分类或问答
|
|
|
- faqs.forEach(faq -> {
|
|
|
- this.remove(new QueryWrapper<Faq>().eq("parent_id", id));
|
|
|
- this.remove(new QueryWrapper<Faq>().eq("id", id));
|
|
|
- //递归删除
|
|
|
- deleteAll(faq.getParentId());
|
|
|
- });
|
|
|
- //删除完毕返回true
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- //如果没有子分类或问答就直接返回了
|
|
|
- return true;
|
|
|
+ private List<Long> ids(Long id, List<Faq> faqs, List<Long> ids) {
|
|
|
+ for (Faq faq : faqs) {
|
|
|
+ if (id.equals(faq.getParentId())) {
|
|
|
+ ids.add(faq.getParentId());
|
|
|
+ ids.addAll(this.ids(faq.getParentId(), faqs, ids));
|
|
|
+ }
|
|
|
}
|
|
|
+ return ids;
|
|
|
}
|
|
|
|
|
|
//type 1上移 0下移
|