39 lines
1.4 KiB
Go
39 lines
1.4 KiB
Go
package model
|
|
|
|
import (
|
|
"case-open-api/global"
|
|
"gorm.io/gorm"
|
|
"time"
|
|
)
|
|
|
|
// CasePlatform 统计数据-病例-平台
|
|
type CasePlatform struct {
|
|
CasePlatformId int64 `gorm:"column:case_platform_id;type:bigint(19);primary_key;comment:主键id" json:"case_platform_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"`
|
|
IssuedScore int `gorm:"column:issued_score;type:int(5);default:0;comment:已发放积分" json:"issued_score"`
|
|
JoinNum int `gorm:"column:join_num;type:int(5);default:0;comment:参加人数" json:"join_num"`
|
|
JoinWhiteNum int `gorm:"column:join_white_num;type:int(5);default:0;comment:白名单参加人数" json:"join_white_num"`
|
|
MessageNum int `gorm:"column:message_num;type:int(5);default:0;comment:留言人数" json:"message_num"`
|
|
Model
|
|
Platform *Platform `gorm:"foreignKey:PlatformId;references:platform_id" json:"platform"`
|
|
}
|
|
|
|
func (m *CasePlatform) TableName() string {
|
|
return "case_platform"
|
|
}
|
|
|
|
func (m *CasePlatform) BeforeCreate(tx *gorm.DB) error {
|
|
if m.CasePlatformId == 0 {
|
|
m.CasePlatformId = 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
|
|
}
|