article_backup.go 2.4 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 `gorm:"type:jsonb;serializer:json"` // 操作人
	ArticleId   int64
	Title       string                  // 标题
	Section     []domain.ArticleSection `gorm:"type:jsonb;serializer:json"` // 分段内容
	Images      []domain.Image          `gorm:"type:jsonb;serializer:json"` // 图片
	Videos      []domain.Video          `gorm:"type:jsonb;serializer:json"` // 视频
	ChangeField []string                `gorm:"type:jsonb;serializer:json"` //
	Action      string                  // 操作
	WhoRead     []int64                 `gorm:"type:jsonb;serializer:json"` // 谁可以看
	WhoReview   []int64                 `gorm:"type:jsonb;serializer:json"` // 评论人
	Tags        []int64                 `gorm:"type:jsonb;serializer:json"` // 标签
	Location    domain.Location         `gorm:"type:jsonb;serializer:json"` // 坐标
	TargetUser  int                     // 分发方式 0 分发给所有人 1 分发给指定的人
	MatchUrl    map[string]string       `gorm:"type:jsonb;serializer:json"` // 匹配文章内容中的url文本
	Show        int
	Attachments []domain.FileInfo `gorm:"type:jsonb;serializer:json"`
}

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")
}