knowledge-api/api/model/QuestionQaItem.go
2024-07-02 17:37:50 +08:00

37 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"gorm.io/gorm"
"knowledge/global"
"time"
)
// QuestionQaItem 知识问答-明细
type QuestionQaItem struct {
ItemId int64 `gorm:"column:item_id;type:bigint(19);primary_key;comment:主键id" json:"item_id"`
QaId int64 `gorm:"column:qa_id;type:bigint(19);comment:知识问答id;NOT NULL" json:"qa_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
IsMustSelect int `gorm:"column:is_must_select;type:tinyint(1);default:0;comment:是否必被选中0:否 1:是)" json:"is_must_select"`
Model
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
QuestionQa *QuestionQa `gorm:"foreignKey:QaId;references:qa_id" json:"question_qa"`
}
func (m *QuestionQaItem) TableName() string {
return "kb_question_qa_item"
}
func (m *QuestionQaItem) BeforeCreate(tx *gorm.DB) error {
if m.ItemId == 0 {
m.ItemId = global.Snowflake.Generate().Int64()
}
m.CreatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
m.UpdatedAt = LocalTime(time.Now())
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
return nil
}