统一通知中心

This commit is contained in:
2026-07-25 15:50:00 +08:00 Unverified
parent 13b61f191a
commit 2c6103d3ae
8 changed files with 552 additions and 144 deletions
+57 -4
View File
@@ -397,7 +397,19 @@ public sealed class GradesController(
sheet.Status = GradeSheetStatus.Submitted;
sheet.SubmittedAt = DateTime.UtcNow;
sheet.ReviewComment = null;
return await SaveAsync(id, false, cancellationToken);
await db.SaveChangesAsync(cancellationToken);
// Notify college admins
var courseName = sheet.TeachingTask!.Course!.Name;
var collegeId = sheet.TeachingTask.Course.CollegeId;
await NotificationService.SendToRoleAsync(db,
SystemRoles.CollegeAdmin,
"成绩单待审核",
$"《{courseName}》成绩已提交,请及时审核。",
collegeId,
"/grades",
cancellationToken);
return NoContent();
}
[HttpPost("sheets/{id:guid}/approve")]
@@ -425,7 +437,20 @@ public sealed class GradesController(
sheet.Status = GradeSheetStatus.Approved;
sheet.ReviewedAt = DateTime.UtcNow;
sheet.ReviewComment = null;
return await SaveAsync(id, false, cancellationToken);
await db.SaveChangesAsync(cancellationToken);
// Notify teachers
var teacherUserIds = await db.TeachingTaskTeachers
.Where(x => x.TeachingTaskId == sheet.TeachingTaskId)
.Select(x => x.Teacher!.UserId)
.Where(id => id != null)
.Select(id => id!.Value)
.ToListAsync(cancellationToken);
await NotificationService.SendToUserIdsAsync(db, teacherUserIds,
"成绩审核通过",
$"《{sheet.TeachingTask!.Course!.Name}》成绩已通过学院审核,等待校级发布。",
"/grades", cancellationToken);
return NoContent();
}
[HttpPost("sheets/{id:guid}/return")]
@@ -458,7 +483,19 @@ public sealed class GradesController(
sheet.Status = GradeSheetStatus.Returned;
sheet.ReviewedAt = DateTime.UtcNow;
sheet.ReviewComment = request.Comment.Trim();
return await SaveAsync(id, false, cancellationToken);
await db.SaveChangesAsync(cancellationToken);
var teacherUserIds = await db.TeachingTaskTeachers
.Where(x => x.TeachingTaskId == sheet.TeachingTaskId)
.Select(x => x.Teacher!.UserId)
.Where(id => id != null)
.Select(id => id!.Value)
.ToListAsync(cancellationToken);
await NotificationService.SendToUserIdsAsync(db, teacherUserIds,
"成绩被退回",
$"《{sheet.TeachingTask!.Course!.Name}》成绩被退回修改:{sheet.ReviewComment}",
"/grades", cancellationToken);
return NoContent();
}
[HttpPost("sheets/{id:guid}/publish")]
@@ -474,7 +511,23 @@ public sealed class GradesController(
return ConflictProblem("只有审核通过的成绩单可以发布。");
sheet.Status = GradeSheetStatus.Published;
sheet.PublishedAt = DateTime.UtcNow;
return await SaveAsync(id, false, cancellationToken);
await db.SaveChangesAsync(cancellationToken);
// Notify enrolled students
var studentUserIds = await db.CourseEnrollments
.Where(x =>
x.CourseSelectionOffering!.TeachingTaskId == sheet.TeachingTaskId &&
x.Status == CourseEnrollmentStatus.Enrolled)
.Select(x => x.Student!.UserId)
.Where(id => id != null)
.Select(id => id!.Value)
.Distinct()
.ToListAsync(cancellationToken);
await NotificationService.SendToUserIdsAsync(db, studentUserIds,
"成绩已发布",
$"《{sheet.TeachingTask!.Course!.Name}》成绩已发布,请查看。",
"/grades", cancellationToken);
return NoContent();
}
[HttpGet("student/transcript")]