package model import ( "gorm.io/gorm" "hepa-calc-admin-api/global" "time" ) // UserInfo 用户表-基础信息 type UserInfo struct { UserInfoId int64 `gorm:"column:user_info_id;type:bigint(19);primary_key;comment:主键id" json:"user_info_id"` UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"` Height string `gorm:"column:height;type:varchar(20);comment:身高(cm)" json:"height"` Weight string `gorm:"column:weight;type:varchar(20);comment:体重(kg)" json:"weight"` NationId *int64 `gorm:"column:nation_id;type:bigint(19);comment:民族id" json:"nation_id"` IsFamilyHistory *int `gorm:"column:is_family_history;type:tinyint(1);comment:是否存在家族病史(0:未知 1:是 2:否)" json:"is_family_history"` IsPregnant *int `gorm:"column:is_pregnant;type:tinyint(1);comment:是否怀孕(1:无计划 2:计划中 3:已怀孕 4:家有宝宝)" json:"is_pregnant"` ExpectedDate *LocalTime `gorm:"column:expected_date;type:datetime;comment:预产期" json:"expected_date"` ProvinceId string `gorm:"column:province_id;type:int(11);comment:省份id" json:"province_id"` Province string `gorm:"column:province;type:varchar(40);comment:省份" json:"province"` CityId string `gorm:"column:city_id;type:int(11);comment:城市id" json:"city_id"` City string `gorm:"column:city;type:varchar(50);comment:城市" json:"city"` CountyId string `gorm:"column:county_id;type:int(11);comment:区县id" json:"county_id"` County string `gorm:"column:county;type:varchar(255);comment:区县" json:"county"` Model } func (m *UserInfo) TableName() string { return "user_info" } func (m *UserInfo) BeforeCreate(tx *gorm.DB) error { if m.UserInfoId == 0 { m.UserInfoId = 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 }