WebsiteArticle.java
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// website/entity/WebsiteArticle.java
package com.aigeo.website.entity;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import java.time.LocalDateTime;
import com.aigeo.common.enums.ArticleStatus;
/**
* 网站文章实体类
* 对应数据库表:ai_website_articles
*
* 存储网站生成的文章内容,包括:
* - 文章基本信息和内容
* - 关联的项目和频道
* - 发布状态和时间管理
*
* @author AIGEO Team
* @since 1.0.0
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "ai_website_articles", indexes = {
@Index(name = "idx_website_articles_project", columnList = "project_id"),
@Index(name = "idx_website_articles_channel", columnList = "channel_id"),
@Index(name = "idx_website_articles_status", columnList = "status")
})
public class WebsiteArticle {
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Integer id;
/**
* 关联的网站项目ID
*/
@NotNull(message = "项目ID不能为空")
@Column(name = "project_id", nullable = false)
private Integer projectId;
/**
* 关联的频道ID
*/
@NotNull(message = "频道ID不能为空")
@Column(name = "channel_id", nullable = false)
private Integer channelId;
/**
* 文章标题
*/
@NotBlank(message = "文章标题不能为空")
@Column(name = "title", nullable = false, length = 500)
private String title;
/**
* 文章摘要
*/
@Column(name = "summary", length = 1000)
private String summary;
/**
* 文章内容
*/
@Column(name = "content", columnDefinition = "LONGTEXT")
private String content;
/**
* 文章状态
*/
@Enumerated(EnumType.STRING)
@Column(name = "status", length = 20)
@Builder.Default
private ArticleStatus status = ArticleStatus.DRAFT;
/**
* 发布时间
*/
@Column(name = "published_at")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime publishedAt;
/**
* 创建时间
*/
@CreationTimestamp
@Column(name = "created_at", updatable = false)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime createdAt;
/**
* 更新时间
*/
@UpdateTimestamp
@Column(name = "updated_at")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updatedAt;
/**
* 实体创建前的处理
*/
@PrePersist
protected void onCreate() {
if (status == null) status = ArticleStatus.DRAFT;
}
/**
* 检查是否已发布
*/
public boolean isPublished() {
return ArticleStatus.PUBLISHED.equals(status);
}
/**
* 发布文章
*/
public void publish() {
this.status = ArticleStatus.PUBLISHED;
this.publishedAt = LocalDateTime.now();
}
/**
* 撤回发布
*/
public void unpublish() {
this.status = ArticleStatus.DRAFT;
this.publishedAt = null;
}
/**
* 获取内容长度
*/
public int getContentLength() {
return content != null ? content.length() : 0;
}
/**
* 检查是否为长文章(超过5000字符)
*/
public boolean isLongArticle() {
return getContentLength() > 5000;
}
}