40 lines
1.6 KiB
Go
40 lines
1.6 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
// TwitterPost 推文记录模型
|
|
type TwitterPost struct {
|
|
Id int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"`
|
|
AccountId int64 `gorm:"column:account_id;not null;default:0" json:"account_id"` // 账号ID
|
|
Content string `gorm:"column:content;type:varchar(255);default:''" json:"content"` // 推文内容
|
|
Images string `gorm:"column:images;type:json" json:"images"` // 图片列表(JSON格式)
|
|
Link string `gorm:"column:link;type:varchar(255);default:''" json:"link"` // 推文链接
|
|
ContentLink string `gorm:"column:content_link;type:varchar(255);default:''" json:"content_link"` // 内容链接
|
|
Status int8 `gorm:"column:status;type:tinyint(3);not null;default:1" json:"status"` // 状态: 1-正常 0-删除
|
|
UpdateTime int64 `gorm:"column:update_time;autoUpdateTime" json:"update_time"` // 更新时间
|
|
CreateTime int64 `gorm:"column:create_time;autoCreateTime" json:"create_time"` // 创建时间
|
|
}
|
|
|
|
// TableName 指定表名
|
|
func (TwitterPost) TableName() string {
|
|
return "ar_twitter_post"
|
|
}
|
|
|
|
// BeforeCreate GORM 钩子 - 创建前设置时间
|
|
func (tp *TwitterPost) BeforeCreate(tx interface{}) error {
|
|
now := time.Now().Unix()
|
|
if tp.CreateTime == 0 {
|
|
tp.CreateTime = now
|
|
}
|
|
if tp.UpdateTime == 0 {
|
|
tp.UpdateTime = now
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// BeforeUpdate GORM 钩子 - 更新前设置时间
|
|
func (tp *TwitterPost) BeforeUpdate(tx interface{}) error {
|
|
tp.UpdateTime = time.Now().Unix()
|
|
return nil
|
|
}
|