bb5d3431c1
- 在 Task 模型中添加 ExternalID 字段用于关联内存中的 taskID - 修改 Generate 函数,将任务记录同时存入内存和数据库 - 添加 saveTaskToDB 和 updateTaskInDB 函数处理任务持久化 - 同步更新任务状态到数据库,确保 GetProjectTasks 能正确查询 - 处理 default 工程的特殊情况(跳过数据库存储)
35 lines
1.3 KiB
Go
35 lines
1.3 KiB
Go
package model
|
|
|
|
import "time"
|
|
|
|
// Task 任务数据模型,对应数据库表。
|
|
type Task struct {
|
|
ID uint `gorm:"primaryKey" json:"id"`
|
|
ExternalID string `gorm:"size:100;index" json:"externalId,omitempty"` // 外部任务ID,关联内存中的taskID
|
|
ProjectID uint `gorm:"index" json:"-"`
|
|
Prompt string `gorm:"type:text" json:"prompt"`
|
|
AssetType string `gorm:"size:50" json:"assetType"`
|
|
Status string `gorm:"size:20;default:'pending'" json:"status"`
|
|
Stage string `gorm:"size:50" json:"stage,omitempty"`
|
|
Progress int `gorm:"default:0" json:"progress"`
|
|
RetryCount int `gorm:"default:0" json:"retryCount"`
|
|
Error string `gorm:"type:text" json:"error,omitempty"`
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
UpdatedAt time.Time `json:"updatedAt,omitempty"`
|
|
}
|
|
|
|
// TaskResponse 任务响应。
|
|
type TaskResponse struct {
|
|
ID string `json:"id"`
|
|
ProjectID string `json:"projectId"`
|
|
Prompt string `json:"prompt"`
|
|
AssetType string `json:"assetType"`
|
|
Status string `json:"status"`
|
|
Stage string `json:"stage,omitempty"`
|
|
Progress int `json:"progress"`
|
|
RetryCount int `json:"retryCount"`
|
|
Error string `json:"error,omitempty"`
|
|
CreatedAt string `json:"createdAt"`
|
|
UpdatedAt string `json:"updatedAt,omitempty"`
|
|
}
|