Record student status approval history
This commit is contained in:
1 parent
75f1751629
commit
634ec48f53
14 files changed
+12307
-16
No files matched your search
@@ -61,6 +61,7 @@ public sealed class ApprovalsController(
|
||||
var manager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var userId = current.UserId;
|
||||
var steps = new List<ApprovalProgressStep>();
|
||||
var historyIncomplete = false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
@@ -103,10 +104,52 @@ public sealed class ApprovalsController(
|
||||
steps.Add(new(item.Status == GradeModificationStatus.Rejected ? "finalRejected" : "finalApproved", finalTime, item.ReviewComment));
|
||||
break;
|
||||
}
|
||||
case "StudentStatusChange":
|
||||
{
|
||||
var query = db.StudentStatusChanges.AsNoTracking().Where(x => x.Id == id);
|
||||
if (manager || current.IsInRole(SystemRoles.Counselor))
|
||||
{
|
||||
if (current.Scope == DataScope.College)
|
||||
query = query.Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == current.RestrictedCollegeId);
|
||||
else if (current.Scope == DataScope.Class)
|
||||
query = query.Where(x => x.Student!.AdministrativeClass!.CounselorUserId == userId);
|
||||
else if (current.Scope != DataScope.All)
|
||||
query = query.Where(x => x.Student!.UserId == userId);
|
||||
}
|
||||
else query = query.Where(x => x.Student!.UserId == userId);
|
||||
var item = await query.FirstOrDefaultAsync(ct);
|
||||
if (item is null) return NotFound();
|
||||
steps.Add(new("submitted", item.SubmittedAt, null));
|
||||
var events = await db.StudentStatusChangeEvents.AsNoTracking()
|
||||
.Where(x => x.StudentStatusChangeId == id)
|
||||
.OrderBy(x => x.FromState).ThenBy(x => x.OccurredAt).ThenBy(x => x.Id).ToListAsync(ct);
|
||||
var expected = StudentStatusChangeState.Submitted;
|
||||
foreach (var entry in events)
|
||||
{
|
||||
if (entry.FromState != expected) historyIncomplete = true;
|
||||
var kind = entry.ToState switch
|
||||
{
|
||||
StudentStatusChangeState.CounselorApproved => "counselorApproved",
|
||||
StudentStatusChangeState.CollegeApproved => "collegeApproved",
|
||||
StudentStatusChangeState.Approved => "finalApproved",
|
||||
StudentStatusChangeState.Cancelled => "cancelled",
|
||||
StudentStatusChangeState.Rejected when entry.FromState == StudentStatusChangeState.Submitted => "counselorRejected",
|
||||
StudentStatusChangeState.Rejected when entry.FromState == StudentStatusChangeState.CounselorApproved => "collegeRejected",
|
||||
StudentStatusChangeState.Rejected when entry.FromState == StudentStatusChangeState.CollegeApproved => "finalRejected",
|
||||
_ => "legacyReviewed"
|
||||
};
|
||||
steps.Add(new(kind, entry.OccurredAt, entry.Comment));
|
||||
expected = entry.ToState;
|
||||
}
|
||||
if (expected != item.State) historyIncomplete = true;
|
||||
if (events.Count == 0 && item.ReviewedAt is { } lastReview && item.State != StudentStatusChangeState.Submitted)
|
||||
steps.Add(new(item.State == StudentStatusChangeState.Cancelled ? "cancelled" : "legacyReviewed", lastReview, item.ReviewComment));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(new ApprovalProgressResponse(type, id, steps));
|
||||
return Ok(new ApprovalProgressResponse(type, id, steps, historyIncomplete));
|
||||
}
|
||||
|
||||
private static void AddSingleApprovalSteps(List<ApprovalProgressStep> steps, DateTime submittedAt, DateTime? reviewedAt, ApprovalStatus status, string? comment)
|
||||
@@ -1086,7 +1129,7 @@ public sealed record ApprovalItem(Guid Id, string Type, string Label, string Tit
|
||||
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts);
|
||||
public sealed record ApprovalRouteSettingRequest([Required] string ReviewerRole);
|
||||
public sealed record ApprovalProgressStep(string Kind, DateTime Time, string? Comment);
|
||||
public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyList<ApprovalProgressStep> Steps);
|
||||
public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyList<ApprovalProgressStep> Steps, bool HistoryIncomplete = false);
|
||||
|
||||
internal static class ApprovalOrderingExtensions
|
||||
{
|
||||
|
||||
@@ -148,6 +148,9 @@ public sealed class StudentStatusChangesController(
|
||||
if (!CanReviewCurrentStage(scope, change.State))
|
||||
return ConflictProblem("当前角色或审核阶段不允许执行该操作。");
|
||||
|
||||
var fromState = change.State;
|
||||
var reviewedAt = DateTime.UtcNow;
|
||||
|
||||
if (!request.Approved)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.Comment))
|
||||
@@ -171,13 +174,19 @@ public sealed class StudentStatusChangesController(
|
||||
{
|
||||
change.State = StudentStatusChangeState.Approved;
|
||||
change.Student!.Status = change.TargetStatus;
|
||||
change.ApprovedAt = DateTime.UtcNow;
|
||||
change.ApprovedAt = reviewedAt;
|
||||
}
|
||||
else return ConflictProblem("当前角色或审核阶段不允许执行该操作。");
|
||||
|
||||
change.ReviewComment = request.Comment?.Trim();
|
||||
change.ReviewedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync(token);
|
||||
change.ReviewedAt = reviewedAt;
|
||||
db.StudentStatusChangeEvents.Add(new StudentStatusChangeEvent
|
||||
{
|
||||
StudentStatusChangeId = change.Id, FromState = fromState, ToState = change.State,
|
||||
ActorUserId = scope.UserId, OccurredAt = reviewedAt, Comment = change.ReviewComment
|
||||
});
|
||||
try { await db.SaveChangesAsync(token); }
|
||||
catch (DbUpdateConcurrencyException) { return ConflictProblem("申请状态已发生变化,请刷新后重试。"); }
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
@@ -192,9 +201,16 @@ public sealed class StudentStatusChangesController(
|
||||
if (change.State != StudentStatusChangeState.Submitted)
|
||||
return ConflictProblem("只有尚未进入审核的申请可以撤回。");
|
||||
|
||||
var cancelledAt = DateTime.UtcNow;
|
||||
change.State = StudentStatusChangeState.Cancelled;
|
||||
change.ReviewedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync(token);
|
||||
change.ReviewedAt = cancelledAt;
|
||||
db.StudentStatusChangeEvents.Add(new StudentStatusChangeEvent
|
||||
{
|
||||
StudentStatusChangeId = change.Id, FromState = StudentStatusChangeState.Submitted,
|
||||
ToState = StudentStatusChangeState.Cancelled, ActorUserId = userId, OccurredAt = cancelledAt
|
||||
});
|
||||
try { await db.SaveChangesAsync(token); }
|
||||
catch (DbUpdateConcurrencyException) { return ConflictProblem("申请状态已发生变化,请刷新后重试。"); }
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,17 @@ public sealed class StudentStatusChange : EntityBase
|
||||
public DateTime? ApprovedAt { get; set; }
|
||||
}
|
||||
|
||||
public sealed class StudentStatusChangeEvent : EntityBase
|
||||
{
|
||||
public Guid StudentStatusChangeId { get; set; }
|
||||
public StudentStatusChange? StudentStatusChange { get; set; }
|
||||
public StudentStatusChangeState FromState { get; set; }
|
||||
public StudentStatusChangeState ToState { get; set; }
|
||||
public Guid ActorUserId { get; set; }
|
||||
public DateTime OccurredAt { get; set; }
|
||||
public string? Comment { get; set; }
|
||||
}
|
||||
|
||||
public enum StudentStatusChangeType
|
||||
{
|
||||
Suspension = 1,
|
||||
|
||||
Loaded 3 of 14 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user