package model import ( "time" "gorm.io/gorm" ) type Word struct { ID string `json:"id" gorm:"primaryKey;size:32"` BookID string `json:"book_id" gorm:"size:32;index;not null"` WordRank int `json:"word_rank" gorm:"index;default:0"` HeadWord string `json:"head_word" gorm:"size:120;index"` Word string `json:"word" gorm:"size:120;uniqueIndex;not null"` SourceWordID string `json:"source_word_id" gorm:"size:64;index"` PhoneticUK string `json:"phonetic_uk" gorm:"size:255"` PhoneticUS string `json:"phonetic_us" gorm:"size:255"` AudioUK string `json:"audio_uk" gorm:"size:500"` AudioUS string `json:"audio_us" gorm:"size:500"` UKSpeech string `json:"uk_speech" gorm:"size:255"` USSpeech string `json:"us_speech" gorm:"size:255"` PartOfSpeech string `json:"part_of_speech" gorm:"size:50"` Definition string `json:"definition" gorm:"type:text"` ExampleSentence string `json:"example_sentence" gorm:"type:text"` RawPayload string `json:"raw_payload,omitempty" gorm:"type:longtext"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` Book *WordBook `json:"book.sql,omitempty" gorm:"foreignKey:BookID;references:ID"` } func (Word) TableName() string { return "words" } func (w *Word) BeforeCreate(tx *gorm.DB) error { if w.ID == "" { w.ID = NewID() } return nil } // WordSentence 对应 content.word.content.sentence.sentences // sContent/sCn 以原字段命名映射。 type WordSentence struct { ID string `json:"id" gorm:"primaryKey;size:32"` WordID string `json:"word_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` SContent string `json:"s_content" gorm:"type:text"` SCn string `json:"s_cn" gorm:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordSentence) TableName() string { return "word_sentences" } func (m *WordSentence) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } // WordTranslation 对应 content.word.content.trans // 保存中英释义及词性信息。 type WordTranslation struct { ID string `json:"id" gorm:"primaryKey;size:32"` WordID string `json:"word_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` Pos string `json:"pos" gorm:"size:32"` TranCn string `json:"tran_cn" gorm:"type:text"` TranOther string `json:"tran_other" gorm:"type:text"` DescCn string `json:"desc_cn" gorm:"size:64"` DescOther string `json:"desc_other" gorm:"size:64"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordTranslation) TableName() string { return "word_translations" } func (m *WordTranslation) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } // WordSynonym + WordSynonymItem 对应 content.word.content.syno.synos[*].hwds[*] type WordSynonym struct { ID string `json:"id" gorm:"primaryKey;size:32"` WordID string `json:"word_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` Pos string `json:"pos" gorm:"size:32"` Tran string `json:"tran" gorm:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordSynonym) TableName() string { return "word_synonyms" } func (m *WordSynonym) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } type WordSynonymItem struct { ID string `json:"id" gorm:"primaryKey;size:32"` SynonymID string `json:"synonym_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` Word string `json:"word" gorm:"size:120;not null"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordSynonymItem) TableName() string { return "word_synonym_items" } func (m *WordSynonymItem) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } // WordPhrase 对应 content.word.content.phrase.phrases type WordPhrase struct { ID string `json:"id" gorm:"primaryKey;size:32"` WordID string `json:"word_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` PContent string `json:"p_content" gorm:"type:text"` PCn string `json:"p_cn" gorm:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordPhrase) TableName() string { return "word_phrases" } func (m *WordPhrase) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } // WordRel + WordRelItem 对应 content.word.content.relWord.rels[*].words[*] type WordRel struct { ID string `json:"id" gorm:"primaryKey;size:32"` WordID string `json:"word_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` Pos string `json:"pos" gorm:"size:32"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordRel) TableName() string { return "word_rels" } func (m *WordRel) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil } type WordRelItem struct { ID string `json:"id" gorm:"primaryKey;size:32"` RelID string `json:"rel_id" gorm:"size:32;index;not null"` SortOrder int `json:"sort_order" gorm:"index;default:0"` Hwd string `json:"hwd" gorm:"size:120"` Tran string `json:"tran" gorm:"type:text"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` } func (WordRelItem) TableName() string { return "word_rel_items" } func (m *WordRelItem) BeforeCreate(tx *gorm.DB) error { if m.ID == "" { m.ID = NewID() } return nil }