38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
package model
|
|
|
|
import (
|
|
"case-open-api/global"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
// CaseItemQuestion 病历表-明细-题目
|
|
type CaseItemQuestion struct {
|
|
QuestionId int64 `gorm:"column:question_id;type:bigint(19);primary_key;comment:主键id" json:"question_id"`
|
|
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id" json:"case_id"`
|
|
CaseItemId int64 `gorm:"column:case_item_id;type:bigint(19);comment:病例明细id;NOT NULL" json:"case_item_id"`
|
|
QuestionName string `gorm:"column:question_name;type:varchar(1000);comment:题目名称" json:"question_name"`
|
|
QuestionType int `gorm:"column:question_type;type:tinyint(1);comment:题目类型(1:单选 2:多选 3:问答 4:判断)" json:"question_type"`
|
|
QuestionAnswer string `gorm:"column:question_answer;type:varchar(255);comment:答案" json:"question_answer"`
|
|
Model
|
|
CaseItemQuestionOption []*CaseItemQuestionOption `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question_option"`
|
|
}
|
|
|
|
func (m *CaseItemQuestion) TableName() string {
|
|
return "case_item_question"
|
|
}
|
|
|
|
func (m *CaseItemQuestion) BeforeCreate(tx *gorm.DB) error {
|
|
if m.QuestionId == 0 {
|
|
m.QuestionId = 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
|
|
}
|