articles = baseMapper.listAllArticleWithContent();
+ if (CollUtil.isEmpty(articles)) {
+ return new ArrayList<>();
+ }
+ return articles;
+ }
+
/**
* 查询列表
* 避免在查询主要信息时返回正文信息造成的性能影响, 该接口不返回文章正文 toc/markdown/html
@@ -138,6 +153,13 @@ public class ArticleService extends ServiceImpl {
@Transactional(rollbackFor = Exception.class)
public ArticleEntity insert(ArticleEntity req) {
baseMapper.insert(req);
+ ArticleIndexMsg articleIndexMsg = new ArticleIndexMsg(IndexMsgTypeEnum.ADD, req.getId(), req.getName());
+ try {
+ IndexMsgQueue.add(articleIndexMsg);
+ } catch (InterruptedException e) {
+ // 不抛出, 暂时先记录
+ log.error("索引更新失败" + e.getMessage());
+ }
return req;
}
@@ -149,6 +171,13 @@ public class ArticleService extends ServiceImpl {
public Long update(ArticleEntity req) {
XzException404.throwBy(req.getId() == null, "ID不得为空");
baseMapper.updById(req);
+ ArticleIndexMsg articleIndexMsg = new ArticleIndexMsg(IndexMsgTypeEnum.ADD, req.getId(), req.getName());
+ try {
+ IndexMsgQueue.add(articleIndexMsg);
+ } catch (InterruptedException e) {
+ // 不抛出, 暂时先记录
+ log.error("索引更新失败" + e.getMessage());
+ }
return req.getId();
}
@@ -169,6 +198,14 @@ public class ArticleService extends ServiceImpl {
baseMapper.updContentById(req);
referenceService.bind(req.getUserId(), req.getId(), req.getName(), req.getReferences());
logService.insert(req.getId(), 0, req.getMarkdown());
+ // 更新索引
+ ArticleIndexMsg articleIndexMsg = new ArticleIndexMsg(IndexMsgTypeEnum.ADD, req.getId(), req.getName(), req.getMarkdown());
+ try {
+ IndexMsgQueue.add(articleIndexMsg);
+ } catch (InterruptedException e) {
+ // 不抛出, 暂时先记录
+ log.error("索引更新失败" + e.getMessage());
+ }
return req.getWords();
}
@@ -197,6 +234,14 @@ public class ArticleService extends ServiceImpl {
referenceService.delete(id);
// 删除访问记录
viewService.delete(id);
+ // 删除索引
+ ArticleIndexMsg articleIndexMsg = new ArticleIndexMsg(IndexMsgTypeEnum.DELETE, id);
+ try {
+ IndexMsgQueue.add(articleIndexMsg);
+ } catch (InterruptedException e) {
+ // 不抛出, 暂时先记录
+ log.error("索引更新失败" + e.getMessage());
+ }
}
/**
diff --git a/blossom-backend/backend/src/main/java/com/blossom/backend/server/article/recycle/ArticleRecycleService.java b/blossom-backend/backend/src/main/java/com/blossom/backend/server/article/recycle/ArticleRecycleService.java
index 5886fd2..72fc5e5 100644
--- a/blossom-backend/backend/src/main/java/com/blossom/backend/server/article/recycle/ArticleRecycleService.java
+++ b/blossom-backend/backend/src/main/java/com/blossom/backend/server/article/recycle/ArticleRecycleService.java
@@ -6,6 +6,9 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blossom.backend.base.param.ParamEnum;
import com.blossom.backend.base.param.ParamService;
import com.blossom.backend.base.param.pojo.ParamEntity;
+import com.blossom.backend.base.search.message.ArticleIndexMsg;
+import com.blossom.backend.base.search.message.IndexMsgTypeEnum;
+import com.blossom.backend.base.search.queue.IndexMsgQueue;
import com.blossom.backend.server.article.recycle.pojo.ArticleRecycleEntity;
import com.blossom.backend.server.folder.FolderService;
import com.blossom.backend.server.folder.pojo.FolderEntity;
@@ -58,6 +61,13 @@ public class ArticleRecycleService extends ServiceImpl
+
+
+