Skip to content

Commit 6713d52

Browse files
author
yqz
committed
feat:更新文章存储逻辑
1 parent cb4f2f4 commit 6713d52

11 files changed

Lines changed: 366 additions & 38 deletions

File tree

OpenBlog-business/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
<version>8.5.17</version>
9292
</dependency>
9393

94+
<dependency>
95+
<groupId>com.vladsch.flexmark</groupId>
96+
<artifactId>flexmark-all</artifactId>
97+
<version>0.64.8</version>
98+
</dependency>
99+
94100
<dependency>
95101
<groupId>org.yaml</groupId>
96102
<artifactId>snakeyaml</artifactId>

OpenBlog-business/src/main/java/com/yqz/openblog/article/dto/ArticleDetailResponse.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class ArticleDetailResponse {
99
private String title;
1010
private String summary;
1111
private String contentMarkdown;
12+
private String contentHtml;
1213
private String coverMediaKey;
1314
private Long authorId;
1415
private String authorNickname;
@@ -56,6 +57,14 @@ public void setContentMarkdown(String contentMarkdown) {
5657
this.contentMarkdown = contentMarkdown;
5758
}
5859

60+
public String getContentHtml() {
61+
return contentHtml;
62+
}
63+
64+
public void setContentHtml(String contentHtml) {
65+
this.contentHtml = contentHtml;
66+
}
67+
5968
public String getCoverMediaKey() {
6069
return coverMediaKey;
6170
}

OpenBlog-business/src/main/java/com/yqz/openblog/article/dto/ArticlePublishedContentCachePayload.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ArticlePublishedContentCachePayload {
1313
private String title;
1414
private String summary;
1515
private String contentMarkdown;
16+
private String contentHtml;
1617
private String coverMediaKey;
1718
private Long authorId;
1819
private String authorNickname;
@@ -30,6 +31,7 @@ public static ArticlePublishedContentCachePayload fromDetail(ArticleDetailRespon
3031
p.setTitle(d.getTitle());
3132
p.setSummary(d.getSummary());
3233
p.setContentMarkdown(d.getContentMarkdown());
34+
p.setContentHtml(d.getContentHtml());
3335
p.setCoverMediaKey(d.getCoverMediaKey());
3436
p.setAuthorId(d.getAuthorId());
3537
p.setAuthorNickname(d.getAuthorNickname());
@@ -75,6 +77,14 @@ public void setContentMarkdown(String contentMarkdown) {
7577
this.contentMarkdown = contentMarkdown;
7678
}
7779

80+
public String getContentHtml() {
81+
return contentHtml;
82+
}
83+
84+
public void setContentHtml(String contentHtml) {
85+
this.contentHtml = contentHtml;
86+
}
87+
7888
public String getCoverMediaKey() {
7989
return coverMediaKey;
8090
}

OpenBlog-business/src/main/java/com/yqz/openblog/article/entity/Article.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ public class Article {
2828
@Column(length = 255)
2929
private String summary;
3030

31-
@Column(nullable = false, columnDefinition = "TEXT")
32-
private String contentMarkdown;
33-
3431
@Column(length = 64)
3532
private String coverMediaKey;
3633

@@ -123,14 +120,6 @@ public void setSummary(String summary) {
123120
this.summary = summary;
124121
}
125122

126-
public String getContentMarkdown() {
127-
return contentMarkdown;
128-
}
129-
130-
public void setContentMarkdown(String contentMarkdown) {
131-
this.contentMarkdown = contentMarkdown;
132-
}
133-
134123
public String getCoverMediaKey() {
135124
return coverMediaKey;
136125
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package com.yqz.openblog.article.entity;
2+
3+
import com.baomidou.mybatisplus.annotation.IdType;
4+
import com.baomidou.mybatisplus.annotation.TableId;
5+
import com.baomidou.mybatisplus.annotation.TableName;
6+
import jakarta.persistence.*;
7+
8+
import java.time.Instant;
9+
10+
@Entity
11+
@TableName("article_bodies")
12+
@Table(name = "article_bodies", indexes = {
13+
@Index(name = "idx_article_bodies_word_count", columnList = "word_count")
14+
})
15+
public class ArticleBody {
16+
17+
@TableId(value = "article_id", type = IdType.INPUT)
18+
@Id
19+
private Long articleId;
20+
21+
@Column(nullable = false, columnDefinition = "MEDIUMTEXT")
22+
private String contentMarkdown;
23+
24+
@Column(columnDefinition = "MEDIUMTEXT")
25+
private String contentHtml;
26+
27+
@Column
28+
private Integer wordCount;
29+
30+
@Column(nullable = false)
31+
private Instant createdAt;
32+
33+
@Column(nullable = false)
34+
private Instant updatedAt;
35+
36+
@PrePersist
37+
public void prePersist() {
38+
Instant now = Instant.now();
39+
createdAt = now;
40+
updatedAt = now;
41+
if (wordCount == null) wordCount = 0;
42+
}
43+
44+
@PreUpdate
45+
public void preUpdate() {
46+
updatedAt = Instant.now();
47+
}
48+
49+
public ArticleBody() {
50+
}
51+
52+
public Long getArticleId() {
53+
return articleId;
54+
}
55+
56+
public void setArticleId(Long articleId) {
57+
this.articleId = articleId;
58+
}
59+
60+
public String getContentMarkdown() {
61+
return contentMarkdown;
62+
}
63+
64+
public void setContentMarkdown(String contentMarkdown) {
65+
this.contentMarkdown = contentMarkdown;
66+
}
67+
68+
public String getContentHtml() {
69+
return contentHtml;
70+
}
71+
72+
public void setContentHtml(String contentHtml) {
73+
this.contentHtml = contentHtml;
74+
}
75+
76+
public Integer getWordCount() {
77+
return wordCount;
78+
}
79+
80+
public void setWordCount(Integer wordCount) {
81+
this.wordCount = wordCount;
82+
}
83+
84+
public Instant getCreatedAt() {
85+
return createdAt;
86+
}
87+
88+
public Instant getUpdatedAt() {
89+
return updatedAt;
90+
}
91+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.yqz.openblog.article.repo;
2+
3+
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4+
import com.yqz.openblog.article.entity.ArticleBody;
5+
import org.apache.ibatis.annotations.Mapper;
6+
import org.apache.ibatis.annotations.Param;
7+
import org.apache.ibatis.annotations.Update;
8+
9+
@Mapper
10+
public interface ArticleBodyMapper extends BaseMapper<ArticleBody> {
11+
12+
@Update("""
13+
update article_bodies
14+
set content_html = #{html},
15+
word_count = #{wordCount},
16+
updated_at = now(6)
17+
where article_id = #{articleId}
18+
and content_html is null
19+
""")
20+
int backfillHtmlIfNull(@Param("articleId") Long articleId,
21+
@Param("html") String html,
22+
@Param("wordCount") int wordCount);
23+
}

0 commit comments

Comments
 (0)