feat: 添加FAQ导入结果持久化展示功能

This commit is contained in:
wizardchen
2026-01-07 20:39:05 +08:00
parent 042d860329
commit 9215c82d3b
10 changed files with 575 additions and 0 deletions
+36
View File
@@ -320,6 +320,30 @@ type FAQImportMetadata struct {
ImportProcessed int `json:"import_processed"`
}
// FAQImportResult 存储FAQ导入完成后的统计结果
// 这个信息是持久化的,不跟随进度状态,直到下次导入时被替换
type FAQImportResult struct {
// 导入统计信息
TotalEntries int `json:"total_entries"` // 总条目数
SuccessCount int `json:"success_count"` // 成功导入的条目数
FailedCount int `json:"failed_count"` // 失败的条目数
SkippedCount int `json:"skipped_count"` // 跳过的条目数(如重复等)
// 导入模式和时间信息
ImportMode string `json:"import_mode"` // 导入模式:append 或 replace
ImportedAt time.Time `json:"imported_at"` // 导入完成时间
TaskID string `json:"task_id"` // 导入任务ID
// 失败详情URL(失败条目较多时提供下载链接)
FailedEntriesURL string `json:"failed_entries_url,omitempty"` // 失败条目CSV下载URL
// 显示控制
DisplayStatus string `json:"display_status"` // 显示状态:open 或 close
// 额外统计信息
ProcessingTime int64 `json:"processing_time"` // 处理耗时(毫秒)
}
// ToJSON converts the metadata to JSON type.
func (m *FAQImportMetadata) ToJSON() (JSON, error) {
if m == nil {
@@ -332,6 +356,18 @@ func (m *FAQImportMetadata) ToJSON() (JSON, error) {
return JSON(bytes), nil
}
// ToJSON converts the import result to JSON type.
func (r *FAQImportResult) ToJSON() (JSON, error) {
if r == nil {
return nil, nil
}
bytes, err := json.Marshal(r)
if err != nil {
return nil, err
}
return JSON(bytes), nil
}
// ParseFAQImportMetadata parses FAQ import metadata from Knowledge.
func ParseFAQImportMetadata(k *Knowledge) (*FAQImportMetadata, error) {
if k == nil || len(k.Metadata) == 0 {
+4
View File
@@ -126,6 +126,10 @@ type KnowledgeService interface {
SaveKBCloneProgress(ctx context.Context, progress *types.KBCloneProgress) error
// GetFAQImportProgress retrieves the progress of an FAQ import task
GetFAQImportProgress(ctx context.Context, taskID string) (*types.FAQImportProgress, error)
// GetLastFAQImportResult retrieves the latest FAQ import result for a knowledge base
GetLastFAQImportResult(ctx context.Context, kbID string) (*types.FAQImportResult, error)
// UpdateLastFAQImportResultDisplayStatus updates the display status of FAQ import result
UpdateLastFAQImportResultDisplayStatus(ctx context.Context, kbID string, displayStatus string) error
// SearchKnowledge searches knowledge items by keyword across the tenant.
// fileTypes: optional list of file extensions to filter by (e.g., ["csv", "xlsx"])
SearchKnowledge(ctx context.Context, keyword string, offset, limit int, fileTypes []string) ([]*types.Knowledge, bool, error)
+28
View File
@@ -93,6 +93,8 @@ type Knowledge struct {
StorageSize int64 `json:"storage_size"`
// Metadata of the knowledge
Metadata JSON `json:"metadata" gorm:"type:json"`
// Last FAQ import result (for FAQ type knowledge only)
LastFAQImportResult JSON `json:"last_faq_import_result" gorm:"type:json"`
// Creation time of the knowledge
CreatedAt time.Time `json:"created_at"`
// Last updated time of the knowledge
@@ -214,6 +216,32 @@ func (k *Knowledge) SetManualMetadata(meta *ManualKnowledgeMetadata) error {
return nil
}
// SetLastFAQImportResult sets FAQ import result to the dedicated field.
func (k *Knowledge) SetLastFAQImportResult(result *FAQImportResult) error {
if result == nil {
k.LastFAQImportResult = nil
return nil
}
jsonValue, err := result.ToJSON()
if err != nil {
return err
}
k.LastFAQImportResult = jsonValue
return nil
}
// GetLastFAQImportResult parses and returns FAQ import result from the dedicated field.
func (k *Knowledge) GetLastFAQImportResult() (*FAQImportResult, error) {
if len(k.LastFAQImportResult) == 0 {
return nil, nil
}
var result FAQImportResult
if err := json.Unmarshal(k.LastFAQImportResult, &result); err != nil {
return nil, err
}
return &result, nil
}
// IsManual returns true if the knowledge item is manual Markdown knowledge.
func (k *Knowledge) IsManual() bool {
return k != nil && k.Type == KnowledgeTypeManual