user_follow.go 1.1 KB
package models

import (
	"fmt"
	"time"

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

type UserFollow struct {
	Id         int64 // 唯一标识
	FromUserId int64
	ToUserId   int64
	LastReadAt int64
	CreatedAt  int64
	UpdatedAt  int64
	DeletedAt  int64
	Version    int
}

func (m *UserFollow) TableName() string {
	return "user_follow"
}

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

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

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

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

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