package model import ( "fmt" "gorm.io/gorm" ) // DynamicChapterLog 动态章节表名(章节表分表) type DynamicChapterLog interface { ChapterInfo() string } // ChapterLogTable gormDB的scopes, 根据clog来获取对应的表名 func ChapterLogTable(clog ChapterLog) func(tx *gorm.DB) *gorm.DB { return func(tx *gorm.DB) *gorm.DB { return tx.Table(clog.ChapterInfo()) } } func ChapterLogTableSetNum(n int) func(tx *gorm.DB) *gorm.DB { return func(tx *gorm.DB) *gorm.DB { return tx.Table(fmt.Sprintf("chapter_logs_%v", n)) } } // ChapterInfo 章节id作为表后缀 事件12,13为章节用户信息上报的,统计到单独的表里(暂定保存1个月的,超期则压缩,看数据情况而定TODO) func (clog *ChapterLog) ChapterInfo() string { return GetChapterTable(clog.EventID, clog.ChapterID) } func GetChapterTable(eventID, chapterID int32) string { if eventID == 13 || eventID == 12 { return "chapter_logs_user_details" } return fmt.Sprintf("chapter_logs_%d", chapterID) } func GetChapterTable2(chapterID int32) string { return fmt.Sprintf("chapter_logs_%d", chapterID) } func ChapterLogTableSetName(name string) func(tx *gorm.DB) *gorm.DB { return func(tx *gorm.DB) *gorm.DB { return tx.Table(name) } }