2025-07-15 13:21:34 +08:00
|
|
|
|
package entities
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"time"
|
|
|
|
|
|
|
2025-07-20 20:53:26 +08:00
|
|
|
|
"github.com/google/uuid"
|
2025-07-15 13:21:34 +08:00
|
|
|
|
"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:"文档标题"`
|
2025-07-20 20:53:26 +08:00
|
|
|
|
Content string `gorm:"type:text;not null" comment:"文档内容"`
|
|
|
|
|
|
UsageGuide string `gorm:"type:text" comment:"使用指南"`
|
|
|
|
|
|
APIDocs string `gorm:"type:text" comment:"API文档"`
|
|
|
|
|
|
Examples string `gorm:"type:text" comment:"使用示例"`
|
|
|
|
|
|
FAQ string `gorm:"type:text" comment:"常见问题"`
|
2025-07-15 13:21:34 +08:00
|
|
|
|
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:"软删除时间"`
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-20 20:53:26 +08:00
|
|
|
|
// BeforeCreate GORM钩子:创建前自动生成UUID
|
|
|
|
|
|
func (pd *ProductDocumentation) BeforeCreate(tx *gorm.DB) error {
|
|
|
|
|
|
if pd.ID == "" {
|
|
|
|
|
|
pd.ID = uuid.New().String()
|
|
|
|
|
|
}
|
|
|
|
|
|
return nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-07-15 13:21:34 +08:00
|
|
|
|
// 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"
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|