作者 tangxvhui

添加文件

  1 +package models
  2 +
  3 +import (
  4 + "fmt"
  5 + "time"
  6 +
  7 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
  8 + "gorm.io/gorm"
  9 + "gorm.io/plugin/soft_delete"
  10 +)
  11 +
  12 +type ArticleTag struct {
  13 + Id int64 `gorm:"primaryKey"` // 唯一标识
  14 + CompanyId int64
  15 + CreatedAt int64
  16 + UpdatedAt int64
  17 + DeletedAt int64
  18 + IsDel soft_delete.DeletedAt `gorm:"softDelete:flag,DeletedAtField:DeletedAt"`
  19 + Version int
  20 + Image domain.Image `gorm:"type:jsonb;serializer:json"` // 图片
  21 + Name string // 标签名称
  22 + Group string // 标签分类
  23 + Remark string // 备注
  24 +}
  25 +
  26 +func (m *ArticleTag) TableName() string {
  27 + return "article_tag"
  28 +}
  29 +
  30 +func (m *ArticleTag) BeforeCreate(tx *gorm.DB) (err error) {
  31 + m.CreatedAt = time.Now().Unix()
  32 + m.UpdatedAt = time.Now().Unix()
  33 + return
  34 +}
  35 +
  36 +func (m *ArticleTag) BeforeUpdate(tx *gorm.DB) (err error) {
  37 + m.UpdatedAt = time.Now().Unix()
  38 + return
  39 +}
  40 +
  41 +func (m *ArticleTag) CacheKeyFunc() string {
  42 + if m.Id == 0 {
  43 + return ""
  44 + }
  45 + return fmt.Sprintf("%v:cache:%v:id:%v", domain.ProjectName, m.TableName(), m.Id)
  46 +}
  47 +
  48 +func (m *ArticleTag) CacheKeyFuncByObject(obj interface{}) string {
  49 + if v, ok := obj.(*ArticleTag); ok {
  50 + return v.CacheKeyFunc()
  51 + }
  52 + return ""
  53 +}
  54 +
  55 +func (m *ArticleTag) CachePrimaryKeyFunc() string {
  56 + if len("") == 0 {
  57 + return ""
  58 + }
  59 + return fmt.Sprintf("%v:cache:%v:primarykey:%v", domain.ProjectName, m.TableName(), "key")
  60 +}