基于 Go + Gin 的课堂专注度分析系统后端服务,提供视频/图片分析、专注度检测、情绪分析、疲劳度检测等功能。
- 语言: Go 1.21+
- Web 框架: Gin
- 数据库: MongoDB
- 缓存: Redis
- 消息队列: Apache Kafka
- 对象存储: MinIO
- 依赖注入: Google Wire
- 监控: Prometheus
analysis/
├── internal/
│ ├── domain/ # 领域模型
│ ├── repository/ # 数据访问层
│ │ └── dao/ # DAO 层
│ ├── service/ # 业务逻辑层
│ ├── web/ # Web 控制器
│ ├── ioc/ # 依赖注入容器
│ └── util/ # 工具函数
├── config/ # 配置文件
├── app.go # 应用入口
├── wire.go # Wire 依赖注入配置
└── wire_gen.go # Wire 生成的代码
- Go 1.21+
- MongoDB 5.0+
- Redis 6.0+
- Kafka 3.0+
- MinIO
go mod download复制配置文件模板并修改:
cp config/conf.yaml.example config/conf.yaml编辑 config/conf.yaml,配置数据库、Redis、Kafka、MinIO 等连接信息。
# 直接运行
go run .
# 或使用 Wire 生成依赖注入代码后运行
wire && go run .服务默认运行在 :8080 端口。
POST /teacher/login- 教师登录POST /teacher/register- 教师注册
POST /teacher/analyze- 提交分析任务GET /teacher/status- 获取任务状态GET /teacher/ws- WebSocket 实时进度
GET /teacher/dashboard- 仪表盘数据GET /teacher/students- 学生列表GET /teacher/class-analysis- 班级分析GET /teacher/history- 历史记录GET /teacher/emotion-analysis- 情绪分析GET /teacher/fatigue-analysis- 疲劳度分析
GET /teacher/report- 分析报告GET /teacher/report/list- 报告列表
完整 API 文档请参考 api.md
系统最初存在时区偏差问题:服务器使用 UTC 时间,而前端显示需要北京时间(UTC+8),导致时间显示相差 8 小时。
-
创建时区工具包 (
internal/util/timezone.go)GetBeijingTime()- 获取当前北京时间ToBeijingTime(t)- 将时间转换为北京时间FormatBeijingTime(t, layout)- 格式化北京时间
-
统一时间存储
- 所有 DAO 层使用
util.GetBeijingTime()替代time.Now() - 确保数据库存储的时间都是北京时间
- 所有 DAO 层使用
-
时间格式化
- 使用
util.FormatBeijingTime()替代.Format() - 避免 UTC 和北京时间转换问题
- 使用
internal/util/timezone.go(新建)internal/repository/dao/*.go(所有 DAO 文件)internal/repository/analysis.gointernal/service/teacher.gointernal/web/reports.gointernal/web/emotion.goapp.go
wirego test ./...go build -o analysis .docker build -t classroom-analysis .
docker run -p 8080:8080 classroom-analysisMIT License