技术栈:Go (Gin + GORM) + PHP + MySQL 5.7 + Redis 主要功能: - 多班级完全隔离(class_id 贯穿全系统) - 后端从 Python FastAPI 重写为 Go Gin(端口 56789) - 超级管理员独立登录(env 配置路径,默认账密 admin/Admin123) - 科任老师/课代表新角色 - 课代表作业管理页面 - 排行榜分项排行(操行分/考勤/作业) - 角色加减分上下限由班主任配置 - 家长改密功能(可开关) - 班级角色按需开关 - 宿舍号格式:南0-000 - 周度/月度重置功能 - MySQL 5.7 兼容 - Nginx 反向代理部署 开发者: Canglan 版权归属: Sea Network Technology Studio 许可证: Apache License 2.0
172 lines
4.2 KiB
Go
172 lines
4.2 KiB
Go
// ===========================================
|
|
// 多班级版班级管理系统 - Go 后端
|
|
//
|
|
// 开发者: Canglan
|
|
// 联系方式: admin@sea-studio.top
|
|
// 版权归属: Sea Network Technology Studio
|
|
// 许可证: Apache License 2.0
|
|
//
|
|
// 版权所有 © Sea Network Technology Studio
|
|
// ===========================================
|
|
|
|
package service
|
|
|
|
import (
|
|
"hz-gitea.sea-studio.top/canglan/SharedClassManager/internal/repository"
|
|
)
|
|
|
|
// StudentService 学生端服务
|
|
type StudentService struct {
|
|
studentRepo *repository.StudentRepo
|
|
conductRepo *repository.ConductRepo
|
|
attendanceRepo *repository.AttendanceRepo
|
|
semesterRepo *repository.SemesterRepo
|
|
}
|
|
|
|
// NewStudentService 创建学生端服务
|
|
func NewStudentService(
|
|
studentRepo *repository.StudentRepo,
|
|
conductRepo *repository.ConductRepo,
|
|
attendanceRepo *repository.AttendanceRepo,
|
|
semesterRepo *repository.SemesterRepo,
|
|
) *StudentService {
|
|
return &StudentService{
|
|
studentRepo: studentRepo,
|
|
conductRepo: conductRepo,
|
|
attendanceRepo: attendanceRepo,
|
|
semesterRepo: semesterRepo,
|
|
}
|
|
}
|
|
|
|
// GetStudentInfo 获取学生个人信息
|
|
func (s *StudentService) GetStudentInfo(studentID int) (map[string]interface{}, error) {
|
|
student, err := s.studentRepo.GetByID(studentID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]interface{}{
|
|
"student": student,
|
|
}, nil
|
|
}
|
|
|
|
// GetConductHistory 获取学生操行分历史
|
|
func (s *StudentService) GetConductHistory(studentID int, limit, offset int) (map[string]interface{}, error) {
|
|
student, err := s.studentRepo.GetByID(studentID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
records, err := s.conductRepo.GetStudentRecords(studentID, limit, offset, false, "", "", 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 扣分项的操作人统一显示为"班主任"
|
|
for i := range records {
|
|
if records[i].PointsChange < 0 {
|
|
name := "班主任"
|
|
records[i].RecorderReal = &name
|
|
}
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
"student_id": studentID,
|
|
"student_name": student.Name,
|
|
"total_points": student.TotalPoints,
|
|
"records": records,
|
|
}, nil
|
|
}
|
|
|
|
// GetHomeworkStatus 获取学生作业情况
|
|
func (s *StudentService) GetHomeworkStatus(studentID int) (map[string]interface{}, error) {
|
|
student, err := s.studentRepo.GetByID(studentID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
records, err := s.conductRepo.GetStudentRecords(studentID, 1000, 0, false, "", "", 0)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 过滤出作业相关记录
|
|
var homeworkRecords []interface{}
|
|
for _, r := range records {
|
|
if r.RelatedType == "homework" {
|
|
homeworkRecords = append(homeworkRecords, r)
|
|
}
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
"student_id": studentID,
|
|
"student_name": student.Name,
|
|
"homework": homeworkRecords,
|
|
}, nil
|
|
}
|
|
|
|
// GetAttendanceRecords 获取学生考勤记录
|
|
func (s *StudentService) GetAttendanceRecords(studentID int, month string) (map[string]interface{}, error) {
|
|
student, err := s.studentRepo.GetByID(studentID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
records, err := s.attendanceRepo.GetStudentRecords(studentID, month)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// 统计
|
|
present, absent, late, leave := 0, 0, 0, 0
|
|
for _, r := range records {
|
|
switch r.Status {
|
|
case "present":
|
|
present++
|
|
case "absent":
|
|
absent++
|
|
case "late":
|
|
late++
|
|
case "leave":
|
|
leave++
|
|
}
|
|
}
|
|
|
|
return map[string]interface{}{
|
|
"student_id": studentID,
|
|
"student_name": student.Name,
|
|
"statistics": map[string]interface{}{
|
|
"present": present,
|
|
"absent": absent,
|
|
"late": late,
|
|
"leave": leave,
|
|
"total": len(records),
|
|
},
|
|
"records": records,
|
|
}, nil
|
|
}
|
|
|
|
// GetRanking 获取排行榜
|
|
func (s *StudentService) GetRanking(classID int, limit int) (map[string]interface{}, error) {
|
|
ranking, err := s.studentRepo.GetRanking(classID, limit)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
totalStudents, _ := s.studentRepo.GetTotalCount(classID)
|
|
|
|
return map[string]interface{}{
|
|
"ranking": ranking,
|
|
"total_students": totalStudents,
|
|
}, nil
|
|
}
|
|
|
|
// GetSemesterRecords 获取学生学期归档记录
|
|
func (s *StudentService) GetSemesterRecords(studentID int) (map[string]interface{}, error) {
|
|
archives, err := s.semesterRepo.GetArchivesByStudent(studentID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return map[string]interface{}{
|
|
"records": archives,
|
|
}, nil
|
|
}
|