This commit is contained in:
2026-03-20 21:41:00 +08:00
Unverified
commit 3d1d4cf506
53 changed files with 7105 additions and 0 deletions

119
internal/model/models.go Normal file
View File

@@ -0,0 +1,119 @@
package model
import (
"gorm.io/gorm"
"time"
)
// User 用户表
type User struct {
ID uint64 `gorm:"primarykey" json:"id"`
Username string `gorm:"type:varchar(50);uniqueIndex;not null" json:"username"`
Password string `gorm:"type:varchar(100);not null" json:"-"`
Email string `gorm:"type:varchar(100);index" json:"email"`
Phone string `gorm:"type:varchar(20);index" json:"phone"`
RealName string `gorm:"type:varchar(50)" json:"real_name"`
IDCard string `gorm:"type:varchar(20)" json:"id_card"`
Role string `gorm:"type:varchar(20);default:'user'" json:"role"` // admin, user
Status int `gorm:"type:tinyint;default:1;index" json:"status"` // 1:正常0:禁用
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// Exam 考试表
type Exam struct {
ID uint64 `gorm:"primarykey" json:"id"`
Title string `gorm:"type:varchar(200);not null" json:"title"`
Code string `gorm:"type:varchar(50);uniqueIndex;not null" json:"code"`
Description string `gorm:"type:text" json:"description"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
RegistrationStart time.Time `json:"registration_start"`
RegistrationEnd time.Time `json:"registration_end"`
MaxCandidates int `gorm:"default:0" json:"max_candidates"` // 0 表示不限制
ExamFee float64 `gorm:"type:decimal(10,2);default:0" json:"exam_fee"`
ExamLocation string `gorm:"type:varchar(200)" json:"exam_location"`
Subject string `gorm:"type:varchar(100)" json:"subject"`
Status int `gorm:"type:tinyint;default:1;index" json:"status"` // 1:未开始2:进行中3:已结束
CreatorID uint64 `gorm:"index" json:"creator_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// ExamRegistration 报名表
type ExamRegistration struct {
ID uint64 `gorm:"primarykey" json:"id"`
UserID uint64 `gorm:"index;not null" json:"user_id"`
ExamID uint64 `gorm:"index;not null" json:"exam_id"`
Status int `gorm:"type:tinyint;default:0;index" json:"status"` // 0:待审核1:已通过2:已拒绝3:已取消
PaymentStatus int `gorm:"type:tinyint;default:0;index" json:"payment_status"` // 0:未支付1:已支付
PaymentTime *time.Time `json:"payment_time"`
AuditTime *time.Time `json:"audit_time"`
AuditComment string `gorm:"type:varchar(500)" json:"audit_comment"`
TicketNumber string `gorm:"type:varchar(50);uniqueIndex" json:"ticket_number"` // 准考证号
ExamSeat string `gorm:"type:varchar(20)" json:"exam_seat"` // 考场座位
Remark string `gorm:"type:varchar(500)" json:"remark"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
User User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
Exam Exam `gorm:"foreignKey:ExamID;constraint:OnDelete:CASCADE" json:"exam,omitempty"`
}
// ExamNotice 考试通知
type ExamNotice struct {
ID uint64 `gorm:"primarykey" json:"id"`
ExamID uint64 `gorm:"index;not null" json:"exam_id"`
Title string `gorm:"type:varchar(200);not null" json:"title"`
Content string `gorm:"type:text;not null" json:"content"`
Type int `gorm:"type:tinyint;default:1" json:"type"` // 1:普通通知2:重要通知3:紧急通知
PublishTime time.Time `json:"publish_time"`
PublisherID uint64 `gorm:"index" json:"publisher_id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
Exam Exam `gorm:"foreignKey:ExamID;constraint:OnDelete:CASCADE" json:"exam,omitempty"`
}
// ExamScore 考试成绩
type ExamScore struct {
ID uint64 `gorm:"primarykey" json:"id"`
UserID uint64 `gorm:"index;not null" json:"user_id"`
ExamID uint64 `gorm:"index;not null" json:"exam_id"`
Score float64 `gorm:"type:decimal(5,2)" json:"score"`
TotalScore float64 `gorm:"type:decimal(5,2)" json:"total_score"`
Pass bool `gorm:"default:false" json:"pass"`
Rank int `gorm:"default:0" json:"rank"`
Remark string `gorm:"type:varchar(500)" json:"remark"`
Published bool `gorm:"default:false;index" json:"published"` // 是否已发布
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
User User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"user,omitempty"`
Exam Exam `gorm:"foreignKey:ExamID;constraint:OnDelete:CASCADE" json:"exam,omitempty"`
}
func (User) TableName() string {
return "user"
}
func (Exam) TableName() string {
return "exam"
}
func (ExamRegistration) TableName() string {
return "exam_registration"
}
func (ExamNotice) TableName() string {
return "exam_notice"
}
func (ExamScore) TableName() string {
return "exam_score"
}