🚀 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:
虾司令
2026-03-29 18:16:41 +08:00
commit 881144269c
38 changed files with 4967 additions and 0 deletions

156
db/models/training.go Normal file
View File

@@ -0,0 +1,156 @@
package models
import (
"time"
)
// TrainingContent 训练内容模型
type TrainingContent struct {
ID uint `gorm:"primaryKey" json:"id"`
Name string `gorm:"type:varchar(128)" json:"name"`
Type string `gorm:"type:varchar(32)" json:"type"` // eye_exercise, crystal_ball, acupoint, relax
Duration int `json:"duration"` // 时长 (秒)
VideoURL string `gorm:"type:text" json:"video_url"`
ThumbnailURL string `gorm:"type:text" json:"thumbnail_url"`
Description string `gorm:"type:text" json:"description"`
Difficulty int `gorm:"default:1" json:"difficulty"` // 1-5
Status int `gorm:"default:1" json:"status"` // 1:启用, 0:禁用
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联的训练任务
TrainingTasks []TrainingTask `gorm:"foreignKey:ContentID" json:"training_tasks"`
}
// TrainingTask 训练任务模型
type TrainingTask struct {
ID uint `gorm:"primaryKey" json:"id"`
StudentID uint `json:"student_id"`
Student Student `gorm:"foreignKey:StudentID" json:"student"`
ContentID uint `json:"content_id"`
Content TrainingContent `gorm:"foreignKey:ContentID" json:"content"`
ScheduledDate time.Time `json:"scheduled_date"`
ScheduledTime *time.Time `json:"scheduled_time"`
Status int `json:"status"` // 0:待完成, 1:已完成, 2:已跳过
CompletedAt *time.Time `json:"completed_at"`
Score *int `json:"score"` // 动作评分
PointsEarned int `json:"points_earned"` // 获得积分
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联的训练记录
TrainingRecords []TrainingRecord `gorm:"foreignKey:TaskID" json:"training_records"`
}
// TrainingRecord 训练记录模型
type TrainingRecord struct {
ID uint `gorm:"primaryKey" json:"id"`
StudentID uint `json:"student_id"`
Student Student `gorm:"foreignKey:StudentID" json:"student"`
TaskID uint `json:"task_id"`
Task TrainingTask `gorm:"foreignKey:TaskID" json:"task"`
ContentID uint `json:"content_id"`
Content TrainingContent `gorm:"foreignKey:ContentID" json:"content"`
Score int `json:"score"` // 动作评分
Accuracy float64 `json:"accuracy"` // 准确率
Duration float64 `json:"duration"` // 实际用时
PerformanceMetrics JSONMap `gorm:"type:json" json:"performance_metrics"` // 性能指标
Feedback string `gorm:"type:text" json:"feedback"` // 反馈信息
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TrainingPerformance 训练表现统计
type TrainingPerformance struct {
ID uint `gorm:"primaryKey" json:"id"`
EntityID uint `json:"entity_id"` // 学生/班级/学校ID
EntityType string `gorm:"type:varchar(20)" json:"entity_type"` // student, class, school
CompletionRate float64 `json:"completion_rate"` // 完成率
AverageScore float64 `json:"average_score"` // 平均分数
TotalTrainingCount int `json:"total_training_count"` // 总训练次数
EngagementRate float64 `json:"engagement_rate"` // 参与率
ImprovementRate float64 `json:"improvement_rate"` // 改善率
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// UserPoints 用户积分模型
type UserPoints struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `json:"user_id"`
UserType string `gorm:"type:varchar(16)" json:"user_type"` // student, parent, teacher
TotalPoints int `gorm:"default:0" json:"total_points"`
UsedPoints int `gorm:"default:0" json:"used_points"`
Level string `gorm:"type:varchar(32);default:'bronze'" json:"level"` // bronze, silver, gold, diamond
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
// 关联的积分流水
}
// PointTransaction 积分流水模型
type PointTransaction struct {
ID uint `gorm:"primaryKey" json:"id"`
UserID uint `json:"user_id"`
UserType string `gorm:"type:varchar(16)" json:"user_type"`
ChangeType string `gorm:"type:varchar(32)" json:"change_type"` // earn, use
Points int `json:"points"` // 变化积分数
BalanceAfter int `json:"balance_after"` // 变化后的余额
Source string `gorm:"type:varchar(64)" json:"source"` // 来源: training, detection, activity
Description string `gorm:"type:varchar(256)" json:"description"`
CreatedAt time.Time `json:"created_at"`
}
// TrainingRecommendation 训练建议模型
type TrainingRecommendation struct {
ID uint `gorm:"primaryKey" json:"id"`
StudentID uint `json:"student_id"`
Student Student `gorm:"foreignKey:StudentID" json:"student"`
Recommendation string `gorm:"type:text" json:"recommendation"`
Priority int `json:"priority"` // 优先级: 1-5
ValidFrom time.Time `json:"valid_from"`
ValidUntil time.Time `json:"valid_until"`
IsApplied bool `json:"is_applied"` // 是否已采纳
AppliedAt *time.Time `json:"applied_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// TrainingType 训练类型枚举
const (
TrainingTypeEyeExercise = "eye_exercise" // 眼保健操
TrainingTypeCrystalBall = "crystal_ball" // 晶状体调焦训练
TrainingTypeAcupoint = "acupoint" // 穴位按摩
TrainingTypeRelax = "relax" // 放松训练
)
// TrainingStatus 训练状态枚举
const (
TrainingStatusPending = 0 // 待完成
TrainingStatusDone = 1 // 已完成
TrainingStatusSkipped = 2 // 已跳过
)
// PointsChangeType 积分变化类型枚举
const (
PointsChangeTypeEarn = "earn" // 获得
PointsChangeTypeUse = "use" // 使用
)
// PointsSource 积分来源枚举
const (
PointsSourceTraining = "training" // 训练获得
PointsSourceDetection = "detection" // 检测获得
PointsSourceActivity = "activity" // 活动获得
PointsSourceAttendance = "attendance" // 出勤获得
PointsSourceAchievement = "achievement" // 成就获得
)
// UserLevel 用户等级枚举
const (
UserLevelBronze = "bronze" // 青铜
UserLevelSilver = "silver" // 白银
UserLevelGold = "gold" // 黄金
UserLevelDiamond = "diamond" // 钻石
)