hepa-calc-api/api/model/UserCase.go

41 lines
1.7 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"
"hepa-calc-api/global"
"time"
)
// UserCase 用户表-病例
type UserCase struct {
UserCaseId int64 `gorm:"column:user_case_id;type:bigint(19);primary_key;comment:主键id" json:"user_case_id"`
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id;NOT NULL" json:"user_id"`
IsHospital *int `gorm:"column:is_hospital;type:tinyint(1);comment:是否医院就诊0:否 1:是)" json:"is_hospital"`
LiverStatus string `gorm:"column:liver_status;type:varchar(30);comment:肝脏状态" json:"liver_status"`
IsMedication *int `gorm:"column:is_medication;type:tinyint(1);comment:是否服药0:否 1:是)" json:"is_medication"`
Medication string `gorm:"column:medication;type:varchar(20);comment:服药名称" json:"medication"`
ChronicDisease string `gorm:"column:chronic_disease;type:varchar(500);comment:慢性疾病名称(逗号分隔)" json:"chronic_disease"`
IsAllergyHistory *int `gorm:"column:is_allergy_history;type:tinyint(1);comment:过敏史0:否 1:是)" json:"is_allergy_history"`
AllergyHistory string `gorm:"column:allergy_history;type:varchar(100);comment:过敏史描述" json:"allergy_history"`
Model
UserCaseDiseaseItem []*UserCaseDiseaseItem `gorm:"foreignKey:UserCaseId;references:user_case_id" json:"user_case_disease_item"`
}
func (m *UserCase) TableName() string {
return "user_case"
}
func (m *UserCase) BeforeCreate(tx *gorm.DB) error {
if m.UserCaseId == 0 {
m.UserCaseId = 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
}