教学点名强化
This commit is contained in:
1 parent
2c6103d3ae
commit
d02b0c56a1
10 files changed
+486
-6
No files matched your search
@@ -23,6 +23,7 @@ public sealed class AttendanceController(
|
|||||||
SystemRoles.SuperAdmin + "," +
|
SystemRoles.SuperAdmin + "," +
|
||||||
SystemRoles.AcademicAdmin + "," +
|
SystemRoles.AcademicAdmin + "," +
|
||||||
SystemRoles.CollegeAdmin + "," +
|
SystemRoles.CollegeAdmin + "," +
|
||||||
|
SystemRoles.Counselor + "," +
|
||||||
SystemRoles.Teacher;
|
SystemRoles.Teacher;
|
||||||
|
|
||||||
[HttpGet("my-tasks")]
|
[HttpGet("my-tasks")]
|
||||||
@@ -299,6 +300,220 @@ public sealed class AttendanceController(
|
|||||||
return NoContent();
|
return NoContent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ═══════════════ Student endpoints ═══════════════
|
||||||
|
|
||||||
|
[HttpGet("my-records")]
|
||||||
|
[Authorize(Roles = SystemRoles.Student)]
|
||||||
|
public async Task<ActionResult> GetMyRecords(
|
||||||
|
Guid? academicTermId,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var userId = currentUserDataScope.Current.UserId;
|
||||||
|
var studentId = await db.Students
|
||||||
|
.Where(s => s.UserId == userId)
|
||||||
|
.Select(s => (Guid?)s.Id)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
if (!studentId.HasValue)
|
||||||
|
return ConflictProblem("当前账号未关联学生档案。");
|
||||||
|
|
||||||
|
var source = db.AttendanceRecords.AsNoTracking()
|
||||||
|
.Where(r => r.StudentId == studentId.Value &&
|
||||||
|
r.AttendanceSheet!.Status == AttendanceSheetStatus.Submitted);
|
||||||
|
if (academicTermId.HasValue)
|
||||||
|
source = source.Where(r =>
|
||||||
|
r.AttendanceSheet!.TeachingTask!.AcademicTermId == academicTermId);
|
||||||
|
|
||||||
|
return Ok(await source
|
||||||
|
.OrderByDescending(r => r.AttendanceSheet!.AttendanceDate)
|
||||||
|
.Select(r => new
|
||||||
|
{
|
||||||
|
r.AttendanceSheetId,
|
||||||
|
SheetName = r.AttendanceSheet!.Name,
|
||||||
|
r.AttendanceSheet.AttendanceDate,
|
||||||
|
TaskNumber = r.AttendanceSheet.TeachingTask!.TaskNumber,
|
||||||
|
CourseCode = r.AttendanceSheet.TeachingTask.Course!.Code,
|
||||||
|
CourseName = r.AttendanceSheet.TeachingTask.Course.Name,
|
||||||
|
TeacherNames = r.AttendanceSheet.TeachingTask.Teachers
|
||||||
|
.OrderByDescending(t => t.IsPrimary)
|
||||||
|
.Select(t => t.Teacher!.Name),
|
||||||
|
r.Status,
|
||||||
|
r.Notes,
|
||||||
|
r.AppealStatus,
|
||||||
|
r.AppealReason,
|
||||||
|
r.AppealSubmittedAt,
|
||||||
|
r.AppealReviewComment,
|
||||||
|
r.AppealReviewedAt
|
||||||
|
})
|
||||||
|
.ToListAsync(cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("records/appeal")]
|
||||||
|
[Authorize(Roles = SystemRoles.Student)]
|
||||||
|
public async Task<ActionResult> SubmitAppeal(
|
||||||
|
AttendanceAppealRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var userId = currentUserDataScope.Current.UserId;
|
||||||
|
var studentId = await db.Students
|
||||||
|
.Where(s => s.UserId == userId)
|
||||||
|
.Select(s => (Guid?)s.Id)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
if (!studentId.HasValue)
|
||||||
|
return ConflictProblem("当前账号未关联学生档案。");
|
||||||
|
|
||||||
|
var record = await db.AttendanceRecords
|
||||||
|
.FirstOrDefaultAsync(r =>
|
||||||
|
r.AttendanceSheetId == request.AttendanceSheetId &&
|
||||||
|
r.StudentId == studentId.Value,
|
||||||
|
cancellationToken);
|
||||||
|
if (record is null) return NotFound();
|
||||||
|
if (record.AppealStatus == AttendanceAppealStatus.Pending)
|
||||||
|
return ConflictProblem("已有申诉正在处理中。");
|
||||||
|
if (record.AppealStatus == AttendanceAppealStatus.Approved)
|
||||||
|
return ConflictProblem("该考勤记录申诉已通过。");
|
||||||
|
|
||||||
|
record.AppealStatus = AttendanceAppealStatus.Pending;
|
||||||
|
record.AppealReason = request.Reason.Trim();
|
||||||
|
record.AppealSubmittedAt = DateTime.UtcNow;
|
||||||
|
record.AppealReviewComment = null;
|
||||||
|
record.AppealReviewedAt = null;
|
||||||
|
await db.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
// Notify the course teacher
|
||||||
|
var teacherUserIds = await db.TeachingTaskTeachers
|
||||||
|
.Where(x => x.TeachingTaskId == record.AttendanceSheet!.TeachingTaskId)
|
||||||
|
.Select(x => x.Teacher!.UserId)
|
||||||
|
.Where(id => id != null)
|
||||||
|
.Select(id => id!.Value)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
if (teacherUserIds.Count > 0)
|
||||||
|
{
|
||||||
|
var studentName = await db.Students
|
||||||
|
.Where(s => s.Id == studentId.Value)
|
||||||
|
.Select(s => s.Name)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
var courseName = record.AttendanceSheet!.TeachingTask?.Course?.Name ?? "";
|
||||||
|
await NotificationService.SendToUserIdsAsync(db, teacherUserIds,
|
||||||
|
"考勤申诉待处理",
|
||||||
|
$"学生 {studentName} 对《{courseName}》考勤记录提出申诉。",
|
||||||
|
"/teacher-attendance", cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ═══════════════ Counselor endpoints ═══════════════
|
||||||
|
|
||||||
|
[HttpGet("counselor-records")]
|
||||||
|
[Authorize(Roles = SystemRoles.Counselor)]
|
||||||
|
public async Task<ActionResult> GetCounselorRecords(
|
||||||
|
Guid? academicTermId,
|
||||||
|
Guid? classId,
|
||||||
|
bool? withAppeal,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var userId = currentUserDataScope.Current.UserId;
|
||||||
|
var classIds = await db.AdministrativeClasses
|
||||||
|
.Where(c => c.CounselorUserId == userId)
|
||||||
|
.Select(c => c.Id)
|
||||||
|
.ToListAsync(cancellationToken);
|
||||||
|
if (classIds.Count == 0)
|
||||||
|
return ConflictProblem("当前账号未关联任何班级。");
|
||||||
|
|
||||||
|
if (classId.HasValue && !classIds.Contains(classId.Value))
|
||||||
|
return ConflictProblem("您不是该班级的辅导员。");
|
||||||
|
|
||||||
|
var targetClassIds = classId.HasValue
|
||||||
|
? [classId.Value]
|
||||||
|
: classIds;
|
||||||
|
|
||||||
|
var source = db.AttendanceRecords.AsNoTracking()
|
||||||
|
.Where(r =>
|
||||||
|
r.AttendanceSheet!.Status == AttendanceSheetStatus.Submitted &&
|
||||||
|
r.Student!.AdministrativeClassId != null &&
|
||||||
|
targetClassIds.Contains(r.Student.AdministrativeClassId));
|
||||||
|
if (academicTermId.HasValue)
|
||||||
|
source = source.Where(r =>
|
||||||
|
r.AttendanceSheet!.TeachingTask!.AcademicTermId == academicTermId);
|
||||||
|
if (withAppeal == true)
|
||||||
|
source = source.Where(r => r.AppealStatus == AttendanceAppealStatus.Pending);
|
||||||
|
|
||||||
|
return Ok(await source
|
||||||
|
.OrderByDescending(r => r.AttendanceSheet!.AttendanceDate)
|
||||||
|
.Select(r => new
|
||||||
|
{
|
||||||
|
r.AttendanceSheetId,
|
||||||
|
SheetName = r.AttendanceSheet!.Name,
|
||||||
|
r.AttendanceSheet.AttendanceDate,
|
||||||
|
TaskNumber = r.AttendanceSheet.TeachingTask!.TaskNumber,
|
||||||
|
CourseCode = r.AttendanceSheet.TeachingTask.Course!.Code,
|
||||||
|
CourseName = r.AttendanceSheet.TeachingTask.Course.Name,
|
||||||
|
StudentNumber = r.Student!.StudentNumber,
|
||||||
|
StudentName = r.Student.Name,
|
||||||
|
ClassName = r.Student.AdministrativeClass!.Name,
|
||||||
|
r.Status,
|
||||||
|
r.Notes,
|
||||||
|
r.AppealStatus,
|
||||||
|
r.AppealReason,
|
||||||
|
r.AppealSubmittedAt,
|
||||||
|
r.AppealReviewComment
|
||||||
|
})
|
||||||
|
.ToListAsync(cancellationToken));
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost("appeals/{attendanceSheetId:guid}/{studentId:guid}/review")]
|
||||||
|
[Authorize(Roles = AttendanceRoles)]
|
||||||
|
public async Task<ActionResult> ReviewAppeal(
|
||||||
|
Guid attendanceSheetId,
|
||||||
|
Guid studentId,
|
||||||
|
AttendanceAppealReviewRequest request,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var record = await db.AttendanceRecords
|
||||||
|
.Include(r => r.AttendanceSheet)
|
||||||
|
.ThenInclude(s => s!.TeachingTask)
|
||||||
|
.ThenInclude(t => t!.Teachers)
|
||||||
|
.FirstOrDefaultAsync(r =>
|
||||||
|
r.AttendanceSheetId == attendanceSheetId &&
|
||||||
|
r.StudentId == studentId,
|
||||||
|
cancellationToken);
|
||||||
|
if (record is null) return NotFound();
|
||||||
|
if (!CanManageSheet(record.AttendanceSheet!))
|
||||||
|
return Forbid();
|
||||||
|
if (record.AppealStatus != AttendanceAppealStatus.Pending)
|
||||||
|
return ConflictProblem("该申诉不在待处理状态。");
|
||||||
|
|
||||||
|
record.AppealStatus = request.Approve
|
||||||
|
? AttendanceAppealStatus.Approved
|
||||||
|
: AttendanceAppealStatus.Rejected;
|
||||||
|
record.AppealReviewComment = request.Comment?.Trim();
|
||||||
|
record.AppealReviewedAt = DateTime.UtcNow;
|
||||||
|
|
||||||
|
// Update record status on approved appeal
|
||||||
|
if (request.Approve)
|
||||||
|
record.Status = AttendanceStatus.Excused;
|
||||||
|
|
||||||
|
await db.SaveChangesAsync(cancellationToken);
|
||||||
|
|
||||||
|
// Notify student
|
||||||
|
var studentUserId = await db.Students
|
||||||
|
.Where(s => s.Id == studentId)
|
||||||
|
.Select(s => s.UserId)
|
||||||
|
.FirstOrDefaultAsync(cancellationToken);
|
||||||
|
if (studentUserId.HasValue)
|
||||||
|
{
|
||||||
|
var result = request.Approve ? "已通过" : "已驳回";
|
||||||
|
await NotificationService.SendAsync(db, studentUserId.Value,
|
||||||
|
$"考勤申诉{result}",
|
||||||
|
request.Comment is not null
|
||||||
|
? $"您的考勤申诉{result}。意见:{request.Comment}"
|
||||||
|
: $"您的考勤申诉{result}。",
|
||||||
|
null, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
[HttpDelete("sheets/{id:guid}")]
|
[HttpDelete("sheets/{id:guid}")]
|
||||||
public async Task<ActionResult> Delete(Guid id, CancellationToken cancellationToken)
|
public async Task<ActionResult> Delete(Guid id, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
@@ -320,6 +535,14 @@ public sealed class AttendanceController(
|
|||||||
if (scope.Scope == DataScope.All) return source;
|
if (scope.Scope == DataScope.All) return source;
|
||||||
if (scope.Scope == DataScope.College)
|
if (scope.Scope == DataScope.College)
|
||||||
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
||||||
|
if (scope.IsInRole(SystemRoles.Counselor))
|
||||||
|
{
|
||||||
|
var collegeIds = db.AdministrativeClasses
|
||||||
|
.Where(c => c.CounselorUserId == scope.UserId)
|
||||||
|
.Select(c => c.Major!.CollegeId)
|
||||||
|
.Distinct();
|
||||||
|
return source.Where(x => collegeIds.Contains(x.Course!.CollegeId));
|
||||||
|
}
|
||||||
if (scope.IsInRole(SystemRoles.Teacher))
|
if (scope.IsInRole(SystemRoles.Teacher))
|
||||||
return source.Where(x =>
|
return source.Where(x =>
|
||||||
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
||||||
@@ -357,3 +580,11 @@ public sealed record AttendanceRecordRequest(
|
|||||||
Guid StudentId,
|
Guid StudentId,
|
||||||
AttendanceStatus Status,
|
AttendanceStatus Status,
|
||||||
[MaxLength(300)] string? Notes);
|
[MaxLength(300)] string? Notes);
|
||||||
|
|
||||||
|
public sealed record AttendanceAppealRequest(
|
||||||
|
Guid AttendanceSheetId,
|
||||||
|
[Required, MaxLength(500)] string Reason);
|
||||||
|
|
||||||
|
public sealed record AttendanceAppealReviewRequest(
|
||||||
|
bool Approve,
|
||||||
|
[MaxLength(300)] string? Comment);
|
||||||
@@ -21,6 +21,7 @@ public sealed class GradesController(
|
|||||||
SystemRoles.SuperAdmin + "," +
|
SystemRoles.SuperAdmin + "," +
|
||||||
SystemRoles.AcademicAdmin + "," +
|
SystemRoles.AcademicAdmin + "," +
|
||||||
SystemRoles.CollegeAdmin + "," +
|
SystemRoles.CollegeAdmin + "," +
|
||||||
|
SystemRoles.Counselor + "," +
|
||||||
SystemRoles.Teacher;
|
SystemRoles.Teacher;
|
||||||
|
|
||||||
private const string Reviewers =
|
private const string Reviewers =
|
||||||
@@ -587,6 +588,15 @@ public sealed class GradesController(
|
|||||||
if (scope.Scope == DataScope.All) return source;
|
if (scope.Scope == DataScope.All) return source;
|
||||||
if (scope.Scope == DataScope.College)
|
if (scope.Scope == DataScope.College)
|
||||||
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
return source.Where(x => x.Course!.CollegeId == scope.RestrictedCollegeId);
|
||||||
|
if (scope.IsInRole(SystemRoles.Counselor))
|
||||||
|
{
|
||||||
|
// Counselor sees grades for courses in their managed classes' college
|
||||||
|
var collegeIds = db.AdministrativeClasses
|
||||||
|
.Where(c => c.CounselorUserId == scope.UserId)
|
||||||
|
.Select(c => c.Major!.CollegeId)
|
||||||
|
.Distinct();
|
||||||
|
return source.Where(x => collegeIds.Contains(x.Course!.CollegeId));
|
||||||
|
}
|
||||||
if (scope.IsInRole(SystemRoles.Teacher))
|
if (scope.IsInRole(SystemRoles.Teacher))
|
||||||
return source.Where(x =>
|
return source.Where(x =>
|
||||||
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
x.Teachers.Any(item => item.Teacher!.UserId == scope.UserId));
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ public sealed class AttendanceRecord
|
|||||||
public Student? Student { get; set; }
|
public Student? Student { get; set; }
|
||||||
public AttendanceStatus Status { get; set; } = AttendanceStatus.Present;
|
public AttendanceStatus Status { get; set; } = AttendanceStatus.Present;
|
||||||
public string? Notes { get; set; }
|
public string? Notes { get; set; }
|
||||||
|
public AttendanceAppealStatus AppealStatus { get; set; } = AttendanceAppealStatus.None;
|
||||||
|
public string? AppealReason { get; set; }
|
||||||
|
public DateTime? AppealSubmittedAt { get; set; }
|
||||||
|
public string? AppealReviewComment { get; set; }
|
||||||
|
public DateTime? AppealReviewedAt { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum AttendanceSheetStatus
|
public enum AttendanceSheetStatus
|
||||||
@@ -38,3 +43,11 @@ public enum AttendanceStatus
|
|||||||
Leave = 4,
|
Leave = 4,
|
||||||
Excused = 5
|
Excused = 5
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum AttendanceAppealStatus
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Pending = 1,
|
||||||
|
Approved = 2,
|
||||||
|
Rejected = 3
|
||||||
|
}
|
||||||
Loaded 3 of 10 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user