package models import ( "gorm.io/gorm" "time" ) // KnowledgeBase 知识库模型 type KnowledgeBase struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` TenantID uint `gorm:"not null;index;comment:租户 ID" json:"tenant_id"` Name string `gorm:"size:200;not null;comment:知识库名称" json:"name"` Slug string `gorm:"unique;size:100;not null;comment:知识库唯一标识" json:"slug"` Description *string `gorm:"type:text;comment:知识库描述" json:"description"` Icon *string `gorm:"size:100;comment:图标" json:"icon"` SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"` Status string `gorm:"default:'draft';comment:状态 (draft/published/archived)" json:"status"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` // 关联 Tenant *Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"` KnowledgeItems []KnowledgeItem `gorm:"foreignKey:KnowledgeBaseID" json:"items,omitempty"` } // TableName 指定表名 func (KnowledgeBase) TableName() string { return "knowledge_bases" } // KnowledgeItem 知识库条目模型 type KnowledgeItem struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` TenantID uint `gorm:"not null;index;comment:租户 ID" json:"tenant_id"` KnowledgeBaseID uint `gorm:"not null;index;comment:知识库 ID" json:"knowledge_base_id"` Title string `gorm:"size:500;not null;comment:标题" json:"title"` Slug string `gorm:"size:200;not null;comment:唯一标识" json:"slug"` Content string `gorm:"type:longtext;not null;comment:内容 (Markdown)" json:"content"` Summary *string `gorm:"type:text;comment:摘要" json:"summary"` Tags *string `gorm:"type:json;comment:标签 (JSON)" json:"tags"` Metadata *string `gorm:"type:text;comment:元数据 (JSON)" json:"metadata"` AuthorID *uint `gorm:"comment:作者 ID" json:"author_id"` Status string `gorm:"default:'draft';index;comment:状态 (draft/review/published/archived)" json:"status"` Views int `gorm:"default:0;comment:浏览次数" json:"views"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` // 关联 Tenant *Tenant `gorm:"foreignKey:TenantID" json:"tenant,omitempty"` Author *User `gorm:"foreignKey:AuthorID" json:"author,omitempty"` KnowledgeBase *KnowledgeBase `gorm:"foreignKey:KnowledgeBaseID" json:"knowledge_base,omitempty"` } // TableName 指定表名 func (KnowledgeItem) TableName() string { return "knowledge_items" } // KnowledgeCategory 知识库分类 type KnowledgeCategory struct { ID uint `gorm:"primaryKey;autoIncrement" json:"id"` KnowledgeBaseID uint `gorm:"not null;index" json:"knowledge_base_id"` ParentID *uint `gorm:"index" json:"parent_id"` Name string `gorm:"size:200;not null" json:"name"` Slug string `gorm:"size:100;not null" json:"slug"` Description *string `gorm:"type:text" json:"description"` Icon *string `gorm:"size:100" json:"icon"` SortOrder int `gorm:"default:0" json:"sort_order"` Status string `gorm:"default:'active'" json:"status"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at"` } // TableName 指定表名 func (KnowledgeCategory) TableName() string { return "knowledge_categories" } // 知识库状态枚举 const ( KBStatusDraft = "draft" KBStatusPublished = "published" KBStatusArchived = "archived" ) // 知识库条目状态枚举 const ( KnowledgeStatusDraft = "draft" KnowledgeStatusReview = "review" KnowledgeStatusPublished = "published" KnowledgeStatusArchived = "archived" ) // KnowledgeSearchResult 知识库搜索结果 type KnowledgeSearchResult struct { Item KnowledgeItem `json:"item"` Score float64 `json:"score"` // 相关度得分 Matched string `json:"matched"` // 匹配的文本片段 Category string `json:"category"` // 分类 }