case-admin-api/api/model/StatCaseQuestion.go
2025-03-07 17:23:50 +08:00

37 lines
1.2 KiB
Go

package model
import (
"case-admin-api/global"
"gorm.io/gorm"
"time"
)
// StatCaseQuestion 统计-病例题目回答统计
type StatCaseQuestion struct {
StatId int64 `gorm:"column:stat_id;type:bigint(19);primary_key;comment:主键id" json:"stat_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id;NOT NULL" json:"case_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
OptionId int64 `gorm:"column:option_id;type:bigint(19);comment:选项id;NOT NULL" json:"option_id"`
SelectNum int `gorm:"column:select_num;type:int(10);comment:被选择数量" json:"select_num"`
Model
CaseItemQuestionOption *CaseItemQuestionOption `gorm:"foreignKey:OptionId;references:option_id" json:"case_item_question_option"`
}
func (m *StatCaseQuestion) TableName() string {
return "stat_case_question"
}
func (m *StatCaseQuestion) BeforeCreate(tx *gorm.DB) error {
if m.StatId == 0 {
m.StatId = 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
}