ArticleGenerationTask.java
2.3 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
package com.aigeo.article.entity;
import jakarta.persistence.*;
import lombok.Data;
import java.time.LocalDateTime;
/**
* 文章生成任务实体类
*/
@Data
@Entity
@Table(name = "ai_article_generation_tasks")
public class ArticleGenerationTask {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "company_id")
private Integer companyId;
@Column(name = "user_id")
private Integer userId;
@Column(name = "config_id")
private Integer configId;
@Column(name = "article_theme")
private String articleTheme;
@Column(name = "topic_ids")
private String topicIds;
@Column(name = "reference_urls")
private String referenceUrls;
@Column(name = "reference_content")
private String referenceContent;
@Enumerated(EnumType.STRING)
@Column(name = "status")
private TaskStatus status;
@Column(name = "progress")
private Byte progress;
@Column(name = "error_message")
private String errorMessage;
@Column(name = "dify_api_config_id")
private Integer difyApiConfigId;
@Column(name = "prompt_template_id")
private Integer promptTemplateId;
@Column(name = "created_at")
private LocalDateTime createdAt;
@Column(name = "completed_at")
private LocalDateTime completedAt;
@PrePersist
protected void onCreate() {
createdAt = LocalDateTime.now();
if (status == null) {
status = TaskStatus.PENDING;
}
if (progress == null) {
progress = 0;
}
}
/**
* 任务状态枚举
*/
public enum TaskStatus {
PENDING("pending"), // 待处理
PROCESSING("processing"), // 处理中
COMPLETED("completed"), // 已完成
FAILED("failed"); // 失败
private final String code;
TaskStatus(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public static TaskStatus fromCode(String code) {
for (TaskStatus status : TaskStatus.values()) {
if (status.getCode().equals(code)) {
return status;
}
}
throw new IllegalArgumentException("未知的任务状态: " + code);
}
}
}