ArticleGenerationConfig.java
5.9 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
package com.aigeo.article.entity;
import com.aigeo.common.enums.AiTasteLevel;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;
/**
* 文章生成配置实体类
* 对应数据库表:ai_article_generation_configs
*
* 用于存储文章生成的各种配置参数,包括:
* - AI写作风格和复杂度设置
* - 文章结构和长度配置
* - SEO优化参数设置
* - 输出格式和样式配置
*
* @author AIGEO Team
* @since 1.0.0
*/
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name = "ai_article_generation_configs")
public class ArticleGenerationConfig {
/**
* 主键ID
*/
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id", nullable = false, updatable = false)
private Integer id;
/**
* 公司ID(多租户字段)
*/
@NotNull(message = "公司ID不能为空")
@Column(name = "company_id", nullable = false)
private Integer companyId;
/**
* 配置名称
*/
@NotBlank(message = "配置名称不能为空")
@Column(name = "config_name", nullable = false, length = 100)
private String configName;
/**
* AI写作风格等级
*/
@Enumerated(EnumType.STRING)
@Column(name = "ai_taste_level")
@Builder.Default
private AiTasteLevel aiTasteLevel = AiTasteLevel.JUNIOR_HIGH;
/**
* 目标字数(范围的最小值)
*/
@Column(name = "target_word_count_min")
@Builder.Default
private Integer targetWordCountMin = 800;
/**
* 目标字数(范围的最大值)
*/
@Column(name = "target_word_count_max")
@Builder.Default
private Integer targetWordCountMax = 1500;
/**
* 是否包含FAQ部分
*/
@Column(name = "include_faq")
@Builder.Default
private Boolean includeFaq = true;
/**
* 是否生成结构化数据(Schema.org)
*/
@Column(name = "generate_structured_data")
@Builder.Default
private Boolean generateStructuredData = true;
/**
* 是否包含相关链接
*/
@Column(name = "include_related_links")
@Builder.Default
private Boolean includeRelatedLinks = true;
/**
* SEO标题模板
*/
@Column(name = "seo_title_template", length = 500)
private String seoTitleTemplate;
/**
* SEO描述模板
*/
@Column(name = "seo_description_template", length = 500)
private String seoDescriptionTemplate;
/**
* 文章标签模板(用逗号分隔)
*/
@Column(name = "article_tags_template", length = 500)
private String articleTagsTemplate;
/**
* 自定义提示词
*/
@Column(name = "custom_prompt", columnDefinition = "TEXT")
private String customPrompt;
/**
* 语言设置
*/
@Column(name = "language", length = 10)
@Builder.Default
private String language = "zh-CN";
/**
* 输出格式(markdown, html等)
*/
@Column(name = "output_format", length = 20)
@Builder.Default
private String outputFormat = "markdown";
/**
* 是否为默认配置
*/
@Column(name = "is_default")
@Builder.Default
private Boolean isDefault = false;
/**
* 是否启用
*/
@Column(name = "is_active")
@Builder.Default
private Boolean isActive = true;
/**
* 配置描述
*/
@Column(name = "description")
private String description;
/**
* 创建时间
*/
@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 (isActive == null) isActive = true;
if (isDefault == null) isDefault = false;
if (includeFaq == null) includeFaq = true;
if (generateStructuredData == null) generateStructuredData = true;
if (includeRelatedLinks == null) includeRelatedLinks = true;
if (aiTasteLevel == null) aiTasteLevel = AiTasteLevel.JUNIOR_HIGH;
if (language == null) language = "zh-CN";
if (outputFormat == null) outputFormat = "markdown";
if (targetWordCountMin == null) targetWordCountMin = 800;
if (targetWordCountMax == null) targetWordCountMax = 1500;
}
/**
* 获取目标字数范围描述
*/
public String getWordCountRange() {
return targetWordCountMin + "-" + targetWordCountMax + "字";
}
/**
* 检查是否为完整配置(包含所有必要参数)
*/
public boolean isComplete() {
return configName != null && !configName.trim().isEmpty()
&& aiTasteLevel != null
&& targetWordCountMin != null && targetWordCountMin > 0
&& targetWordCountMax != null && targetWordCountMax > targetWordCountMin;
}
/**
* 获取配置的复杂度评分(1-5分)
*/
public int getComplexityScore() {
int score = aiTasteLevel != null ? aiTasteLevel.getComplexityLevel() : 2;
// 根据配置的复杂程度调整评分
if (Boolean.TRUE.equals(generateStructuredData)) score += 1;
if (Boolean.TRUE.equals(includeFaq)) score += 1;
if (customPrompt != null && !customPrompt.trim().isEmpty()) score += 1;
return Math.min(score, 5); // 最高5分
}
}