Documentation ¶
Index ¶
- Constants
- Variables
- func AddEntityTags(ctx context.Context, tx *gorm.DB, userID utils.UInt64, entityType EntityType, ...) error
- func AddUserCash(db *gorm.DB, userID utils.UInt64, points int) error
- func CreateItems(ctx context.Context, tx *gorm.DB, userID utils.UInt64, items []*Item, ...) error
- func GetItemIDsOfBook(tx *gorm.DB, bookID utils.UInt64, offset, limit int) (itemIDs []utils.UInt64, err error)
- func GetItemIDsOfBooks(tx *gorm.DB, bookIDs []utils.UInt64) (itemBookMap map[utils.UInt64]utils.UInt64, err error)
- func GetItemIDsOfTags(ctx context.Context, userID utils.UInt64, tags []string) (map[utils.UInt64]string, error)
- func MustInit(ctx context.Context, db *gorm.DB, queue *redismq.Queue)
- func RemoveEntityTags(ctx context.Context, tx *gorm.DB, userID utils.UInt64, entityID utils.UInt64, ...) error
- func UpdateEntityTagsDiff(ctx context.Context, tx *gorm.DB, userID utils.UInt64, entityID utils.UInt64, ...) error
- type Book
- func (b *Book) AfterCreate(tx *gorm.DB) (err error)
- func (b *Book) AfterDelete(tx *gorm.DB) (err error)
- func (b *Book) AfterUpdate(tx *gorm.DB) (err error)
- func (b *Book) BeforeCreate(tx *gorm.DB) (err error)
- func (b *Book) BeforeDelete(tx *gorm.DB) (err error)
- func (b *Book) GetTags(ctx context.Context) ([]string, error)
- func (b *Book) MPutItems(ctx context.Context, tx *gorm.DB, itemIDs []utils.UInt64) (successItemIDs []utils.UInt64, err error)
- func (b *Book) TableName() string
- type BookItem
- type CParamNewStuffCountDaily
- type Dungeon
- func (d *Dungeon) AddMonsterFromBook(ctx context.Context, tx *gorm.DB, sourceEntityIDs []utils.UInt64) error
- func (d *Dungeon) AddMonsters(ctx context.Context, tx *gorm.DB, items []utils.UInt64) error
- func (d *Dungeon) BeforeCreate(tx *gorm.DB) (err error)
- func (d *Dungeon) BeforeDelete(tx *gorm.DB) (err error)
- func (d *Dungeon) CountMonsters(ctx context.Context, tx *gorm.DB) (int64, error)
- func (d *Dungeon) GetAssociations(ctx context.Context, tx *gorm.DB) (books, items []utils.UInt64, tags []string, err error)
- func (d *Dungeon) GetBookIDs(ctx context.Context, tx *gorm.DB) ([]utils.UInt64, error)
- func (d *Dungeon) GetDirectMonsters(tx *gorm.DB, offset, limit int) ([]DungeonMonster, error)
- func (d *Dungeon) GetItemIDs(ctx context.Context, tx *gorm.DB) ([]utils.UInt64, error)
- func (d *Dungeon) GetMonster(ctx context.Context, tx *gorm.DB, itemID utils.UInt64) (*DungeonMonster, error)
- func (d *Dungeon) GetMonsters(ctx context.Context, tx *gorm.DB, offset, limit int) ([]DungeonMonster, error)
- func (d *Dungeon) GetMonstersForPractice(ctx context.Context, tx *gorm.DB, count int) ([]DungeonMonster, error)
- func (d *Dungeon) GetMonstersWithExpandedAssociations(ctx context.Context, tx *gorm.DB, offset, limit int) ([]DungeonMonster, error)
- func (d *Dungeon) GetTags(ctx context.Context) ([]string, error)
- func (d *Dungeon) SubtractBooks(ctx context.Context, tx *gorm.DB, books []utils.UInt64) (successIDs []utils.UInt64, err error)
- type DungeonBook
- type DungeonMonster
- type DungeonTag
- type EntityType
- type GormScope
- type Item
- func FindItems(ctx context.Context, tx *gorm.DB, itemIDs []utils.UInt64) ([]Item, error)
- func FindItemsOfTag(ctx context.Context, tx *gorm.DB, userID utils.UInt64, tag string, ...) ([]Item, error)
- func GetItemsByID(tx *gorm.DB, itemIDs []utils.UInt64) (items []*Item, err error)
- func GetItemsOfBook(tx *gorm.DB, bookID utils.UInt64, offset, limit int) (items []*Item, err error)
- type MemorizationSetting
- type MonsterSource
- type Profile
- func (p *Profile) BeforeCreate(tx *gorm.DB) (err error)
- func (p *Profile) BeforeUpdate(tx *gorm.DB) (err error)
- func (p *Profile) CreateProfile(db *gorm.DB) error
- func (p *Profile) EnsureLoadProfilePoints(db *gorm.DB) (*ProfilePoints, error)
- func (p *Profile) EnsureLoadProfileSettingsAdvance(db *gorm.DB) (*ProfileAdvanceSetting, error)
- func (p *Profile) EnsureSettingsMemorization(db *gorm.DB) (*ProfileMemorizationSetting, error)
- func (p *Profile) GetPoints() *ProfilePoints
- func (p *Profile) GetSettingsAdvance() *ProfileAdvanceSetting
- func (p *Profile) GetSettingsMemorization() *ProfileMemorizationSetting
- func (p *Profile) GetSettingsMemorizationOrDefault(ctx context.Context, tx *gorm.DB) (*ProfileMemorizationSetting, error)
- func (p *Profile) UpdateProfile(db *gorm.DB) error
- func (p *Profile) UpdateSettingsAdvance(db *gorm.DB, updater *ProfileAdvanceSetting) error
- func (p *Profile) UpdateSettingsMemorization(db *gorm.DB, updater *ProfileMemorizationSetting) error
- type ProfileAdvanceSetting
- type ProfileMemorizationSetting
- type ProfilePoints
- type TModel
- type Tag
- type TagRepo
- func (t TagRepo) AddTags(ctx context.Context, userID utils.UInt64, entityID utils.UInt64, ...) error
- func (t TagRepo) GetEntitiesByTag(ctx context.Context, userID utils.UInt64, tag string, entityType EntityType) ([]utils.UInt64, error)
- func (t TagRepo) GetTag(ctx context.Context, tag string) (*tags.Tag[EntityType], error)
- func (t TagRepo) GetTagsByEntity(ctx context.Context, entityID utils.UInt64) ([]string, error)
- func (t TagRepo) GetTagsByUser(ctx context.Context, userID utils.UInt64) ([]string, error)
- func (t TagRepo) GetUsersByTag(ctx context.Context, tag string) ([]utils.UInt64, error)
- func (t TagRepo) RemoveTags(ctx context.Context, userID utils.UInt64, entityID utils.UInt64, ...) error
- func (t TagRepo) RenameTag(ctx context.Context, userID utils.UInt64, oldTag, newTag string) error
- type UserMonster
Constants ¶
const ( TyItemFlashCard = "flash_card" TyItemMultipleChoice = "multiple_choice" TyItemCompletion = "completion" )
Variables ¶
var CKBook = cachekey.MustNewSchema[utils.UInt64]("book:{book_id}", 10*time.Minute)
var CKDungeonMonsterCounts = cachekey.MustNewSchema[utils.UInt64]( "dungeon:{dungeon_id}:monsters:count", time.Second*20) // 不主动淘汰,20s 左右更新
var CKDungeonNewStuffCountDaily = cachekey.MustNewSchema[CParamNewStuffCountDaily]( "dungeon:{dungeon_id}:new_stuff_count_daily:{date}", time.Hour*24) // 按天淘汰
var DefaultMemorizationSetting = MemorizationSetting{ ReviewInterval: def.DefaultRecallIntervals, DifficultyPreference: 1, QuizMode: def.QuizModeBalance, PriorityMode: def.PriorityMode{ def.PriorityModeFamiliarityDESC, def.PriorityModeTimePassASC, def.PriorityModeDifficultyASC, def.PriorityModeImportanceASC, }, }
Functions ¶
func AddEntityTags ¶
func AddEntityTags(ctx context.Context, tx *gorm.DB, userID utils.UInt64, entityType EntityType, entityID utils.UInt64, tags ...string) error
AddEntityTags adds tags to an entity for a user.
func AddUserCash ¶
AddUserCash 更新用户积分
func CreateItems ¶
func GetItemIDsOfBook ¶
func GetItemIDsOfBook(tx *gorm.DB, bookID utils.UInt64, offset, limit int) (itemIDs []utils.UInt64, err error)
GetItemIDsOfBook 获取某个 book 的 items
func GetItemIDsOfBooks ¶
func GetItemIDsOfBooks(tx *gorm.DB, bookIDs []utils.UInt64) (itemBookMap map[utils.UInt64]utils.UInt64, err error)
GetItemIDsOfBooks 获取 book 关联的 items
func GetItemIDsOfTags ¶
func GetItemIDsOfTags(ctx context.Context, userID utils.UInt64, tags []string) (map[utils.UInt64]string, error)
GetItemIDsOfTags 获取 tag 关联的 items
Types ¶
type Book ¶
type Book struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false" json:"id"` UserID utils.UInt64 `gorm:"index:idx_user;not null" json:"user_id"` Title string `gorm:"not null"` Description string CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` }
func FindBooksOfTag ¶
func FindBooksOfTag(ctx context.Context, tx *gorm.DB, userID utils.UInt64, tag string, pager *utils.Pager) ([]Book, error)
FindBooksOfTag returns the items
func (*Book) BeforeDelete ¶
BeforeDelete is a GORM hook that is called before deleting a book.
type BookItem ¶
type Dungeon ¶
type Dungeon struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false" json:"id"` UserID utils.UInt64 `gorm:"not null" json:"user_id,string"` Type def.DungeonType `gorm:"not null" json:"type"` Title string `gorm:"not null" json:"title"` Description string `json:"description"` MemorizationSetting // system CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"` DeletedAt gorm.DeletedAt }
func CreateDungeon ¶
func FindDungeon ¶
func (*Dungeon) AddMonsterFromBook ¶
func (*Dungeon) AddMonsters ¶
func (*Dungeon) BeforeCreate ¶
BeforeCreate 钩子
func (*Dungeon) BeforeDelete ¶
BeforeDelete hooks for cleaning up associations
func (*Dungeon) CountMonsters ¶
func (*Dungeon) GetAssociations ¶
func (d *Dungeon) GetAssociations(ctx context.Context, tx *gorm.DB) (books, items []utils.UInt64, tags []string, err error)
GetAssociations Helper function to get associated books, items, and tags for a dungeon
func (*Dungeon) GetBookIDs ¶
func (*Dungeon) GetDirectMonsters ¶
GetDirectMonsters - 获取当前 Dungeon 的 DungeonMonster,不会尝试解析 books 和 tags 的关联
func (*Dungeon) GetItemIDs ¶
func (*Dungeon) GetMonster ¶
func (d *Dungeon) GetMonster(ctx context.Context, tx *gorm.DB, itemID utils.UInt64) (*DungeonMonster, error)
GetMonster retrieves monster in the dungeon by given itemID
func (*Dungeon) GetMonsters ¶
func (d *Dungeon) GetMonsters(ctx context.Context, tx *gorm.DB, offset, limit int) ([]DungeonMonster, error)
GetMonsters retrieves the monsters for the dungeon with sorting and pagination
func (*Dungeon) GetMonstersForPractice ¶
func (*Dungeon) GetMonstersWithExpandedAssociations ¶
func (d *Dungeon) GetMonstersWithExpandedAssociations(ctx context.Context, tx *gorm.DB, offset, limit int) ([]DungeonMonster, error)
GetMonstersWithExpandedAssociations - 获取当前 Dungeon 的 DungeonMonster 及其关联的 Items, Books, Tags
type DungeonBook ¶
type DungeonMonster ¶
type DungeonMonster struct { DungeonID utils.UInt64 ItemID utils.UInt64 SourceType MonsterSource SourceID utils.UInt64 // 用于 runtime PracticeAt time.Time // 上次复习时间的记录 NextPracticeAt time.Time // 下次复习时间 PracticeCount uint32 // 复习次数 (考虑到可能会有 merge 次数等逻辑,这里先用一个相对大的空间) // Gaming Visibility utils.Percentage `gorm:"default:0"` // Visibility 显影程度,根据复习次数变化 Avatar string // 头像地址 // 以下为宽表内容,为了加速查询 Familiarity utils.Percentage `gorm:"default:0"` // UserMonster 向 DungeonMonster 单项同步 Difficulty def.DifficultyLevel `gorm:"default:0x01"` // Item 向 DungeonMonster 单项同步 Importance def.ImportanceLevel `gorm:"default:0x01"` // Item 向 DungeonMonster 单项同步 CreatedAt time.Time // StoryTelling & Gaming Name string Description string }
type DungeonTag ¶
type EntityType ¶
type EntityType uint8
const ( EntityTypeItem EntityType = 1 EntityTypeBook EntityType = 2 EntityTypeDungeon EntityType = 3 )
type Item ¶
type Item struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:true" json:"id"` CreatorID utils.UInt64 `gorm:"not null" json:"creator_id,string"` Type string Content string // todo: 示意,后续应该放到 user、item 关联的表中去 Difficulty def.DifficultyLevel `gorm:"default:0x01"` // 难度,默认值为 NoviceNormal (0x01) Importance def.ImportanceLevel `gorm:"default:0x01"` // 重要程度,默认值为 DomainGeneral (0x01) CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt }
func FindItemsOfTag ¶
func FindItemsOfTag(ctx context.Context, tx *gorm.DB, userID utils.UInt64, tag string, pager *utils.Pager) ([]Item, error)
FindItemsOfTag returns the items
func GetItemsByID ¶
func GetItemsOfBook ¶
GetItemsOfBook 获取某个 book 的 items
func (*Item) BeforeDelete ¶
BeforeDelete is a GORM hook that is called before deleting an item.
type MemorizationSetting ¶
type MemorizationSetting struct { // 复习时间的配置,是一组时间,作为根据复习结算时的熟练度来选择下次复习时间的依据 ReviewInterval def.RecallIntervalLevel `gorm:"type:string"` // 用户挑战偏好 DifficultyPreference utils.Percentage `gorm:"type:tinyint unsigned"` // 倾向的战斗模式,决定了已经在时间内 monster 出场时,新增和复习的出现策略 QuizMode def.QuizMode `gorm:"size:255"` // 倾向的战斗模式,决定了已经在时间内 monster 出场时,进行选择的优先级顺序 PriorityMode def.PriorityMode `gorm:"size:255"` }
ProfileMemorizationSetting 定义了用户记忆设置的模型
type MonsterSource ¶
type MonsterSource uint8
const ( MonsterSourceItem MonsterSource = 1 MonsterSourceBook MonsterSource = 2 )
func (MonsterSource) String ¶
func (ms MonsterSource) String() string
type Profile ¶
type Profile struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false"` Nickname string `gorm:"nickname,size:255"` Email string `gorm:"email,size:255;not null;unique"` AvatarURL string `gorm:"avatar_url,size:255"` Bio string `gorm:"bio,type:text"` CreatedAt time.Time UpdatedAt time.Time DeletedAt gorm.DeletedAt `gorm:"index"` // contains filtered or unexported fields }
Profile 定义了用户个人信息的模型
func EnsureProfile ¶
EnsureProfile 从数据库中加载用户个人信息
func FindProfile ¶
FindProfile 读取个人信息
func (*Profile) BeforeCreate ¶
BeforeCreate 钩子
func (*Profile) BeforeUpdate ¶
BeforeUpdate 钩子
func (*Profile) CreateProfile ¶
CreateProfile 创建新的用户资料
func (*Profile) EnsureLoadProfilePoints ¶
func (p *Profile) EnsureLoadProfilePoints(db *gorm.DB) (*ProfilePoints, error)
EnsureLoadProfilePoints 从数据库中"懒加载"用户高级设置
func (*Profile) EnsureLoadProfileSettingsAdvance ¶
func (p *Profile) EnsureLoadProfileSettingsAdvance(db *gorm.DB) (*ProfileAdvanceSetting, error)
EnsureLoadProfileSettingsAdvance 从数据库中"懒加载"用户高级设置
func (*Profile) EnsureSettingsMemorization ¶
func (p *Profile) EnsureSettingsMemorization(db *gorm.DB) (*ProfileMemorizationSetting, error)
EnsureSettingsMemorization 从数据库中"懒加载"用户记忆设置
func (*Profile) GetSettingsAdvance ¶
func (p *Profile) GetSettingsAdvance() *ProfileAdvanceSetting
GetSettingsAdvance 检索用户高级设置
func (*Profile) GetSettingsMemorization ¶
func (p *Profile) GetSettingsMemorization() *ProfileMemorizationSetting
GetSettingsMemorization 检索用户记忆设置
func (*Profile) GetSettingsMemorizationOrDefault ¶
func (*Profile) UpdateProfile ¶
UpdateProfile 更新现有用户资料
func (*Profile) UpdateSettingsAdvance ¶
func (p *Profile) UpdateSettingsAdvance(db *gorm.DB, updater *ProfileAdvanceSetting) error
UpdateSettingsAdvance 使用保存逻辑更新用户高级设置
func (*Profile) UpdateSettingsMemorization ¶
func (p *Profile) UpdateSettingsMemorization(db *gorm.DB, updater *ProfileMemorizationSetting) error
UpdateSettingsMemorization 使用保存逻辑更新用户记忆设置
type ProfileAdvanceSetting ¶
type ProfileAdvanceSetting struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false"` Theme string `gorm:"theme,size:255;default:'light'"` Language string `gorm:"language,size:255;default:'en'"` EmailNotifications bool `gorm:"email_notifications,default:true"` PushNotifications bool `gorm:"push_notifications,default:true"` }
ProfileAdvanceSetting 定义了用户高级设置的模型
type ProfileMemorizationSetting ¶
type ProfileMemorizationSetting struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false"` MemorizationSetting }
ProfileMemorizationSetting
在 User 的 ProfileMemorizationSetting 中,可以设置默认的 QuizMode 和 Priority Dungeon 创建时,会从 User 的 ProfileMemorizationSetting 中获取默认的 QuizMode 和 Priority 并独立于 User 的设置进行修改,后续 User 的设置不会覆盖 Dungeon 的设置 可以在 Dungeon 的 MemorizationSetting 中主动选择从 User 的 ProfileMemorizationSetting 中同步
type ProfilePoints ¶
type ProfilePoints struct { ID utils.UInt64 `gorm:"primaryKey;autoIncrement:false"` // 与用户ID一致 Cash utils.UInt64 `gorm:"default:0"` // 现金 Gem utils.UInt64 `gorm:"default:0"` // 宝石 VipScore utils.UInt64 `gorm:"default:0"` // VIP 积分 CreatedAt time.Time // 记录的创建时间 UpdatedAt time.Time // 记录的更新时间 DeletedAt gorm.DeletedAt `gorm:"index"` // 记录的删除时间 }
ProfilePoints 定义了用户积分信息的模型
func EnsureLoadProfilePoints ¶
EnsureLoadProfilePoints 从数据库中加载用户积分信息
type TModel ¶
type TModel struct { *tags.TagService[EntityType] }
type Tag ¶
type TagRepo ¶
type TagRepo struct {
// contains filtered or unexported fields
}
func (TagRepo) GetEntitiesByTag ¶
func (TagRepo) GetTagsByEntity ¶
func (TagRepo) GetTagsByUser ¶
func (TagRepo) GetUsersByTag ¶
func (TagRepo) RemoveTags ¶
type UserMonster ¶
type UserMonster struct { UserID utils.UInt64 ItemID utils.UInt64 Familiarity utils.Percentage `gorm:"default:0"` // 熟练度,范围为0-100,默认值为0 // contains filtered or unexported fields }
UserMonster - Item 对特定用户的属性