新增了接口1

This commit is contained in:
2024-12-30 16:41:00 +08:00
parent 60850d98da
commit 29632f7d50
5 changed files with 163 additions and 163 deletions
+38
View File
@@ -0,0 +1,38 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// UserAnswerRecord 用户答题记录表
type UserAnswerRecord struct {
RecordId int64 `gorm:"column:record_id;type:bigint(19);primary_key;comment:主键id" json:"record_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Answer string `gorm:"column:answer;type:varchar(255);comment:答案" json:"answer"`
IsTrue int `gorm:"column:is_true;type:tinyint(1);comment:是否正确(0:否 1:是)" json:"is_true"`
Model
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
}
func (m *UserAnswerRecord) TableName() string {
return "user_answer_records"
}
func (m *UserAnswerRecord) BeforeCreate(tx *gorm.DB) error {
if m.RecordId == 0 {
m.RecordId = 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
}
-38
View File
@@ -1,38 +0,0 @@
package model
import (
"case-open-api/global"
"gorm.io/gorm"
"time"
)
// UserAnswerRecords 用户答题记录表
type UserAnswerRecords struct {
CaseUserQuestionId int64 `gorm:"column:case_user_question_id;type:bigint(19);primary_key;comment:主键id" json:"case_user_question_id"`
CaseId int64 `gorm:"column:case_id;type:bigint(19);comment:病例id;NOT NULL" json:"case_id"`
PlatformId int64 `gorm:"column:platform_id;type:bigint(19);comment:用户所属平台id;NOT NULL" json:"platform_id"`
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:题目id;NOT NULL" json:"question_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
Answer string `gorm:"column:answer;type:varchar(255);comment:答案" json:"answer"`
IsTrue int `gorm:"column:is_true;type:tinyint(1);comment:是否正确(0:否 1:是)" json:"is_true"`
Model
CaseItemQuestion *CaseItemQuestion `gorm:"foreignKey:QuestionId;references:question_id" json:"case_item_question"`
}
func (m *UserAnswerRecords) TableName() string {
return "user_answer_records"
}
func (m *UserAnswerRecords) BeforeCreate(tx *gorm.DB) error {
if m.CaseUserQuestionId == 0 {
m.CaseUserQuestionId = 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
}