article_backup.go 1.7 KB
package models

import (
	"fmt"
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
	"gorm.io/gorm"
	"gorm.io/plugin/soft_delete"
)

type ArticleBackup struct {
	Id         int64 `gorm:"primaryKey"` // 唯一标识
	CompanyId  int64
	CreatedAt  int64
	UpdatedAt  int64
	DeletedAt  int64
	IsDel      soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
	Version    int
	Operator   domain.UserSimple       // 操作人
	Title      string                  // 标题
	Section    []domain.ArticleSection // 分段内容
	Images     []domain.Image          // 图片
	Action     string                  // 操作
	WhoRead    []int64                 // 谁可以看
	WhoReview  []int64                 // 评论人
	Tags       []int                   // 标签
	TargetUser int                     // 分发方式 0 分发给所有人 1 分发给指定的人
}

func (m *ArticleBackup) TableName() string {
	return "article_backup"
}

func (m *ArticleBackup) BeforeCreate(tx *gorm.DB) (err error) {
	m.CreatedAt = time.Now().Unix()
	m.UpdatedAt = time.Now().Unix()
	return
}

func (m *ArticleBackup) BeforeUpdate(tx *gorm.DB) (err error) {
	m.UpdatedAt = time.Now().Unix()
	return
}

func (m *ArticleBackup) CacheKeyFunc() string {
	if m.Id == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
}

func (m *ArticleBackup) CacheKeyFuncByObject(obj interface{}) string {
	if v, ok := obj.(*ArticleBackup); ok {
		return v.CacheKeyFunc()
	}
	return ""
}

func (m *ArticleBackup) CachePrimaryKeyFunc() string {
	if len("") == 0 {
		return ""
	}
	return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
}