🚀 AI 近视防控系统 - 生产环境上线版本 v1.0
✅ 已完成功能: - 后端 Go 服务 (认证/授权/检测) - JWT 认证 + RBAC 权限控制 - 登录速率限制 (5 次失败锁定 15 分钟) - 密码强度校验 - 敏感数据脱敏 - Vue3 管理后台 - 路由守卫 - 删除二次确认 📦 部署配置: - Docker Compose 生产环境配置 - MySQL/Redis/MongoDB 数据库 - Nginx 前端服务 - 强密码安全配置 ⚠️ P2 待办 (下次迭代): - 学生/检测/预警等业务模块实现 - 错误处理统一化 - 缓存策略优化 - 日志分级 📍 生产环境: - 服务器:192.168.15.222 - 管理后台:http://192.168.15.222:8081 - API 服务:http://192.168.15.222:8080 2026-03-29 上线部署完成
This commit is contained in:
127
db/models/user.go
Normal file
127
db/models/user.go
Normal file
@@ -0,0 +1,127 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// User 通用用户模型
|
||||
type User struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
UUID string `gorm:"type:varchar(64);uniqueIndex" json:"uuid"`
|
||||
Name string `gorm:"type:varchar(64)" json:"name"`
|
||||
Username string `gorm:"type:varchar(64);uniqueIndex" json:"username"`
|
||||
Phone string `gorm:"type:varchar(20);uniqueIndex" json:"phone"`
|
||||
Password string `gorm:"type:varchar(255)" json:"-"` // 不返回密码
|
||||
Role string `gorm:"type:varchar(20)" json:"role"` // student, parent, teacher, admin
|
||||
Status int `gorm:"default:1" json:"status"` // 1:正常, 0:禁用
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Student 学生模型
|
||||
type Student struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
StudentNo string `gorm:"type:varchar(32);uniqueIndex" json:"student_no"`
|
||||
Name string `gorm:"type:varchar(64)" json:"name"`
|
||||
Gender int `gorm:"default:1" json:"gender"` // 1:男, 2:女
|
||||
BirthDate *time.Time `json:"birth_date"`
|
||||
ClassID uint `json:"class_id"`
|
||||
Class Class `gorm:"foreignKey:ClassID" json:"class"`
|
||||
ParentID *uint `json:"parent_id"` // 关联家长
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Parent 家长模型
|
||||
type Parent struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"type:varchar(64)" json:"name"`
|
||||
Phone string `gorm:"type:varchar(20);uniqueIndex" json:"phone"`
|
||||
IDCard string `gorm:"type:varchar(32)" json:"id_card"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联的学生
|
||||
|
||||
}
|
||||
|
||||
// Teacher 教师模型
|
||||
type Teacher struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"type:varchar(64)" json:"name"`
|
||||
Phone string `gorm:"type:varchar(20);uniqueIndex" json:"phone"`
|
||||
SchoolID uint `json:"school_id"`
|
||||
School School `gorm:"foreignKey:SchoolID" json:"school"`
|
||||
Role string `gorm:"type:varchar(32)" json:"role"` // homeroom, school_doctor, sports
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 所带班级
|
||||
ClassIDs []byte `gorm:"type:json" json:"class_ids"` // JSON格式存储班级ID数组
|
||||
}
|
||||
|
||||
// School 学校模型
|
||||
type School struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"type:varchar(128)" json:"name"`
|
||||
Code string `gorm:"type:varchar(32);uniqueIndex" json:"code"`
|
||||
Address string `gorm:"type:varchar(256)" json:"address"`
|
||||
ContactName string `gorm:"type:varchar(64)" json:"contact_name"`
|
||||
ContactPhone string `gorm:"type:varchar(20)" json:"contact_phone"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联的班级和教师
|
||||
Classes []Class `gorm:"foreignKey:SchoolID" json:"classes"`
|
||||
Teachers []Teacher `gorm:"foreignKey:SchoolID" json:"teachers"`
|
||||
}
|
||||
|
||||
// Class 班级模型
|
||||
type Class struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Name string `gorm:"type:varchar(64)" json:"name"`
|
||||
Grade string `gorm:"type:varchar(16)" json:"grade"` // 年级
|
||||
SchoolID uint `json:"school_id"`
|
||||
School School `gorm:"foreignKey:SchoolID" json:"school"`
|
||||
TeacherID *uint `json:"teacher_id"` // 班主任
|
||||
Teacher *Teacher `gorm:"foreignKey:TeacherID" json:"teacher"`
|
||||
StudentCount int `gorm:"default:0" json:"student_count"`
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// 关联的学生
|
||||
Students []Student `gorm:"foreignKey:ClassID" json:"students"`
|
||||
}
|
||||
|
||||
// ParentStudentRel 家长-学生关联表
|
||||
type ParentStudentRel struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
ParentID uint `json:"parent_id"`
|
||||
StudentID uint `json:"student_id"`
|
||||
Relation string `gorm:"type:varchar(16)" json:"relation"` // father, mother, other
|
||||
IsPrimary bool `gorm:"default:false" json:"is_primary"` // 是否主要监护人
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// UserAccount 用户账号模型(统一账号体系)
|
||||
type UserAccount struct {
|
||||
ID uint `gorm:"primaryKey" json:"id"`
|
||||
Username string `gorm:"type:varchar(64);uniqueIndex" json:"username"`
|
||||
PasswordHash string `gorm:"type:varchar(128)" json:"-"`
|
||||
Phone string `gorm:"type:varchar(20);uniqueIndex" json:"phone"`
|
||||
UserType string `gorm:"type:varchar(16)" json:"user_type"` // student, parent, teacher, admin
|
||||
UserID uint `json:"user_id"` // 关联的具体用户ID
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
LastLoginAt *time.Time `json:"last_login_at"`
|
||||
LastLoginIP string `gorm:"type:varchar(45)" json:"last_login_ip"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
Reference in New Issue
Block a user