This commit is contained in:
2025-07-15 13:21:34 +08:00
parent 807004f78d
commit 83bf9aea7d
44 changed files with 9798 additions and 8 deletions

View File

@@ -0,0 +1,69 @@
package entities
import (
"time"
"gorm.io/gorm"
)
// ProductDocumentation 产品文档实体
type ProductDocumentation struct {
ID string `gorm:"primaryKey;type:varchar(36)" comment:"文档ID"`
ProductID string `gorm:"type:varchar(36);not null;uniqueIndex" comment:"产品ID"`
Title string `gorm:"type:varchar(200);not null" comment:"文档标题"`
Content string `gorm:"type:longtext;not null" comment:"文档内容"`
UsageGuide string `gorm:"type:longtext" comment:"使用指南"`
APIDocs string `gorm:"type:longtext" comment:"API文档"`
Examples string `gorm:"type:longtext" comment:"使用示例"`
FAQ string `gorm:"type:longtext" comment:"常见问题"`
Version string `gorm:"type:varchar(20);default:'1.0'" comment:"文档版本"`
Published bool `gorm:"default:false" comment:"是否已发布"`
// 关联关系
Product *Product `gorm:"foreignKey:ProductID" comment:"产品"`
CreatedAt time.Time `gorm:"autoCreateTime" comment:"创建时间"`
UpdatedAt time.Time `gorm:"autoUpdateTime" comment:"更新时间"`
DeletedAt gorm.DeletedAt `gorm:"index" comment:"软删除时间"`
}
// IsValid 检查文档是否有效
func (pd *ProductDocumentation) IsValid() bool {
return pd.DeletedAt.Time.IsZero()
}
// IsPublished 检查文档是否已发布
func (pd *ProductDocumentation) IsPublished() bool {
return pd.Published
}
// Publish 发布文档
func (pd *ProductDocumentation) Publish() {
pd.Published = true
}
// Unpublish 取消发布文档
func (pd *ProductDocumentation) Unpublish() {
pd.Published = false
}
// UpdateContent 更新文档内容
func (pd *ProductDocumentation) UpdateContent(title, content, usageGuide, apiDocs, examples, faq string) {
pd.Title = title
pd.Content = content
pd.UsageGuide = usageGuide
pd.APIDocs = apiDocs
pd.Examples = examples
pd.FAQ = faq
}
// IncrementVersion 增加版本号
func (pd *ProductDocumentation) IncrementVersion() {
// 简单的版本号递增逻辑,实际项目中可能需要更复杂的版本管理
if pd.Version == "" {
pd.Version = "1.0"
} else {
// 这里可以实现更复杂的版本号递增逻辑
pd.Version = pd.Version + ".1"
}
}