优化毕业审核、学位审核
This commit is contained in:
1 parent
71ee21b063
commit
5dc1ae4e3a
19 files changed
+9645
-57
No files matched your search
@@ -4,6 +4,10 @@ using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Graduation;
|
||||
using Jiaowu.Api.Infrastructure.Excel;
|
||||
using Jiaowu.Api.Infrastructure.Files;
|
||||
using Jiaowu.Api.Infrastructure.BackgroundJobs;
|
||||
using Jiaowu.Api.Domain.System;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -35,11 +39,14 @@ public sealed class DegreeAwardsController(
|
||||
x.Id,
|
||||
x.Name,
|
||||
x.GraduationYear,
|
||||
x.EnrollmentYear,
|
||||
x.DegreeName,
|
||||
x.MinimumGradePoint,
|
||||
x.Status,
|
||||
x.Notes,
|
||||
x.CalculatedAt,
|
||||
x.CalculationStatus,
|
||||
x.CalculationError,
|
||||
x.PublishedAt,
|
||||
ResultCount = x.Results.Count(result =>
|
||||
!collegeId.HasValue ||
|
||||
@@ -67,6 +74,8 @@ public sealed class DegreeAwardsController(
|
||||
[FromQuery] int pageSize = 20,
|
||||
[FromQuery] string? keyword = null,
|
||||
[FromQuery] DegreeAwardConclusion? conclusion = null,
|
||||
[FromQuery] Guid? majorId = null,
|
||||
[FromQuery] Guid? administrativeClassId = null,
|
||||
CancellationToken token = default)
|
||||
{
|
||||
pageSize = Math.Clamp(pageSize, 10, 100);
|
||||
@@ -81,6 +90,10 @@ public sealed class DegreeAwardsController(
|
||||
if (collegeId.HasValue)
|
||||
source = source.Where(x =>
|
||||
x.Student!.AdministrativeClass!.Major!.CollegeId == collegeId);
|
||||
if (majorId.HasValue)
|
||||
source = source.Where(x => x.Student!.AdministrativeClass!.MajorId == majorId);
|
||||
if (administrativeClassId.HasValue)
|
||||
source = source.Where(x => x.Student!.AdministrativeClassId == administrativeClassId);
|
||||
|
||||
var summary = await source
|
||||
.GroupBy(_ => 1)
|
||||
@@ -139,11 +152,14 @@ public sealed class DegreeAwardsController(
|
||||
batch.Id,
|
||||
batch.Name,
|
||||
batch.GraduationYear,
|
||||
batch.EnrollmentYear,
|
||||
batch.DegreeName,
|
||||
batch.MinimumGradePoint,
|
||||
batch.Status,
|
||||
batch.Notes,
|
||||
batch.CalculatedAt,
|
||||
batch.CalculationStatus,
|
||||
batch.CalculationError,
|
||||
batch.PublishedAt,
|
||||
ResultCount = summary?.ResultCount ?? 0,
|
||||
GrantedCount = summary?.GrantedCount ?? 0,
|
||||
@@ -173,6 +189,7 @@ public sealed class DegreeAwardsController(
|
||||
{
|
||||
Name = request.Name.Trim(),
|
||||
GraduationYear = request.GraduationYear,
|
||||
EnrollmentYear = request.EnrollmentYear,
|
||||
DegreeName = request.DegreeName.Trim(),
|
||||
MinimumGradePoint = request.MinimumGradePoint,
|
||||
Notes = request.Notes?.Trim()
|
||||
@@ -184,7 +201,33 @@ public sealed class DegreeAwardsController(
|
||||
|
||||
[HttpPost("batches/{id:guid}/calculate")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> Calculate(Guid id, CancellationToken token)
|
||||
public async Task<ActionResult> QueueCalculation(Guid id, CancellationToken token)
|
||||
{
|
||||
var batch = await db.DegreeAwardBatches.FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
if (batch is null) return NotFound();
|
||||
if (batch.Status != DegreeAwardBatchStatus.Draft) return ConflictProblem("已发布批次不能重新计算。");
|
||||
if (batch.CalculationStatus is AuditCalculationStatus.Queued or AuditCalculationStatus.Running)
|
||||
return ConflictProblem("该批次正在后台计算,请稍候。");
|
||||
batch.CalculationStatus = AuditCalculationStatus.Queued;
|
||||
batch.CalculationError = null;
|
||||
var outbox = await db.BackgroundJobOutboxMessages.FirstOrDefaultAsync(x =>
|
||||
x.JobKind == BackgroundJobKind.DegreeAwardCalculation && x.JobId == id, token);
|
||||
if (outbox is null)
|
||||
db.BackgroundJobOutboxMessages.Add(BackgroundJobOutboxMessage.Create(BackgroundJobKind.DegreeAwardCalculation, id));
|
||||
else
|
||||
{
|
||||
outbox.State = BackgroundJobOutboxState.Pending;
|
||||
outbox.CompletedAt = null;
|
||||
outbox.ProcessingToken = null;
|
||||
outbox.LeaseExpiresAt = null;
|
||||
outbox.LastError = null;
|
||||
}
|
||||
await db.SaveChangesAsync(token);
|
||||
return Accepted(new { batch.Id, batch.CalculationStatus });
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public async Task<ActionResult> CalculateNow(Guid id, CancellationToken token)
|
||||
{
|
||||
var batch = await db.DegreeAwardBatches
|
||||
.FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
@@ -192,31 +235,31 @@ public sealed class DegreeAwardsController(
|
||||
if (batch.Status != DegreeAwardBatchStatus.Draft)
|
||||
return ConflictProblem("已发布批次不能重新计算。");
|
||||
|
||||
var auditCandidates = await db.GraduationAuditResults.AsNoTracking()
|
||||
.Where(x =>
|
||||
x.GraduationAuditBatch!.GraduationYear == batch.GraduationYear &&
|
||||
x.GraduationAuditBatch.Status == GraduationAuditBatchStatus.Published &&
|
||||
x.Conclusion == GraduationAuditConclusion.Eligible)
|
||||
.OrderByDescending(x => x.GraduationAuditBatch!.PublishedAt)
|
||||
var students = await db.Students.AsNoTracking()
|
||||
.Where(x => x.EnrollmentYear == batch.EnrollmentYear &&
|
||||
(x.Status == StudentStatus.Active || x.Status == StudentStatus.Suspended ||
|
||||
x.Status == StudentStatus.Graduated))
|
||||
.OrderBy(x => x.StudentNumber)
|
||||
.Select(x => new
|
||||
{
|
||||
x.Id,
|
||||
x.StudentId,
|
||||
StudentStatus = x.Student!.Status
|
||||
x.Status
|
||||
})
|
||||
.ToListAsync(token);
|
||||
var audits = auditCandidates
|
||||
var auditCandidates = await db.GraduationAuditResults.AsNoTracking()
|
||||
.Where(x => x.GraduationAuditBatch!.GraduationYear == batch.GraduationYear &&
|
||||
x.GraduationAuditBatch.EnrollmentYear == batch.EnrollmentYear)
|
||||
.OrderByDescending(x => x.GraduationAuditBatch!.CalculatedAt)
|
||||
.Select(x => new { x.Id, x.StudentId, x.Conclusion, x.MissingCourseNames })
|
||||
.ToListAsync(token);
|
||||
var auditsByStudent = auditCandidates
|
||||
.GroupBy(x => x.StudentId)
|
||||
.Select(x => x.First())
|
||||
.ToList();
|
||||
.ToDictionary(x => x.StudentId);
|
||||
var gradePoints = await db.GradeRecords.AsNoTracking()
|
||||
.Where(x => x.GradeSheet!.Status == GradeSheetStatus.Published &&
|
||||
x.GradePoint.HasValue)
|
||||
.Where(x => db.GraduationAuditResults.Any(audit =>
|
||||
audit.StudentId == x.StudentId &&
|
||||
audit.GraduationAuditBatch!.GraduationYear == batch.GraduationYear &&
|
||||
audit.GraduationAuditBatch.Status == GraduationAuditBatchStatus.Published &&
|
||||
audit.Conclusion == GraduationAuditConclusion.Eligible))
|
||||
.Where(x => x.Student!.EnrollmentYear == batch.EnrollmentYear)
|
||||
.Select(x => new
|
||||
{
|
||||
x.StudentId,
|
||||
@@ -232,9 +275,10 @@ public sealed class DegreeAwardsController(
|
||||
.Where(x => x.DegreeAwardBatchId == id)
|
||||
.ExecuteDeleteAsync(token);
|
||||
|
||||
foreach (var audit in audits)
|
||||
foreach (var student in students)
|
||||
{
|
||||
var grades = gradePointsByStudent.GetValueOrDefault(audit.StudentId) ?? [];
|
||||
var audit = auditsByStudent.GetValueOrDefault(student.Id);
|
||||
var grades = gradePointsByStudent.GetValueOrDefault(student.Id) ?? [];
|
||||
var credits = grades.Sum(x => x.Credits);
|
||||
var average = credits == 0
|
||||
? 0
|
||||
@@ -243,17 +287,20 @@ public sealed class DegreeAwardsController(
|
||||
2,
|
||||
MidpointRounding.AwayFromZero);
|
||||
var conclusion = DegreeAwardRules.Evaluate(
|
||||
true, audit.StudentStatus, average, batch.MinimumGradePoint);
|
||||
var reason = audit.StudentStatus != StudentStatus.Graduated
|
||||
? "学籍状态尚未转为毕业"
|
||||
audit?.Conclusion == GraduationAuditConclusion.Eligible,
|
||||
average, batch.MinimumGradePoint);
|
||||
var reason = audit is null
|
||||
? "尚未生成对应的毕业资格审核结果"
|
||||
: audit.Conclusion != GraduationAuditConclusion.Eligible
|
||||
? $"毕业资格审核暂不符合:{audit.MissingCourseNames ?? "请核对毕业审核结果"}"
|
||||
: average < batch.MinimumGradePoint
|
||||
? $"平均绩点 {average:0.00},低于批次要求 {batch.MinimumGradePoint:0.00}"
|
||||
: string.Empty;
|
||||
db.DegreeAwardResults.Add(new DegreeAwardResult
|
||||
{
|
||||
DegreeAwardBatchId = batch.Id,
|
||||
StudentId = audit.StudentId,
|
||||
GraduationAuditResultId = audit.Id,
|
||||
StudentId = student.Id,
|
||||
GraduationAuditResultId = audit?.Id,
|
||||
AverageGradePoint = average,
|
||||
CalculatedConclusion = conclusion,
|
||||
Conclusion = conclusion,
|
||||
@@ -262,7 +309,7 @@ public sealed class DegreeAwardsController(
|
||||
}
|
||||
batch.CalculatedAt = DateTime.UtcNow;
|
||||
await db.SaveChangesAsync(token);
|
||||
return Ok(new { ResultCount = audits.Count });
|
||||
return Ok(new { ResultCount = students.Count });
|
||||
}
|
||||
|
||||
[HttpPut("results/{id:guid}")]
|
||||
@@ -311,6 +358,54 @@ public sealed class DegreeAwardsController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("batches/{id:guid}")]
|
||||
[Authorize(Roles = Managers)]
|
||||
public async Task<ActionResult> Delete(Guid id, CancellationToken token)
|
||||
{
|
||||
var batch = await db.DegreeAwardBatches.FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
if (batch is null) return NotFound();
|
||||
if (batch.Status != DegreeAwardBatchStatus.Draft)
|
||||
return ConflictProblem("已发布批次不能删除。");
|
||||
db.DegreeAwardBatches.Remove(batch);
|
||||
await db.SaveChangesAsync(token);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("batches/{id:guid}/export.xlsx")]
|
||||
[Authorize(Roles = Reviewers)]
|
||||
public async Task<ActionResult> Export(
|
||||
Guid id,
|
||||
[FromQuery] string? keyword,
|
||||
[FromQuery] DegreeAwardConclusion? conclusion,
|
||||
[FromQuery] Guid? majorId,
|
||||
[FromQuery] Guid? administrativeClassId,
|
||||
CancellationToken token)
|
||||
{
|
||||
var batch = await db.DegreeAwardBatches.AsNoTracking().FirstOrDefaultAsync(x => x.Id == id, token);
|
||||
if (batch is null) return NotFound();
|
||||
var results = db.DegreeAwardResults.AsNoTracking().Where(x => x.DegreeAwardBatchId == id);
|
||||
var collegeId = RestrictedCollegeId();
|
||||
if (collegeId.HasValue) results = results.Where(x => x.Student!.AdministrativeClass!.Major!.CollegeId == collegeId);
|
||||
if (majorId.HasValue) results = results.Where(x => x.Student!.AdministrativeClass!.MajorId == majorId);
|
||||
if (administrativeClassId.HasValue) results = results.Where(x => x.Student!.AdministrativeClassId == administrativeClassId);
|
||||
var normalizedKeyword = keyword?.Trim();
|
||||
if (!string.IsNullOrWhiteSpace(normalizedKeyword)) results = results.Where(x => x.Student!.StudentNumber.Contains(normalizedKeyword) || x.Student.Name.Contains(normalizedKeyword));
|
||||
if (conclusion.HasValue) results = results.Where(x => x.Conclusion == conclusion.Value);
|
||||
var rows = await results.OrderBy(x => x.Student!.StudentNumber).Select(x => new
|
||||
{
|
||||
x.Student!.StudentNumber, x.Student.Name,
|
||||
College = x.Student.AdministrativeClass!.Major!.College!.Name,
|
||||
Major = x.Student.AdministrativeClass.Major!.Name, Class = x.Student.AdministrativeClass.Name,
|
||||
x.AverageGradePoint, x.ExceptionReason, x.Conclusion, x.IsOverridden, x.ReviewComment
|
||||
}).ToListAsync(token);
|
||||
var bytes = ExcelWorkbookHelper.Create("学位授予审核",
|
||||
["学号", "姓名", "学院", "专业", "班级", "平均绩点", "结论", "规则说明", "人工复核", "复核意见"],
|
||||
rows.Select(x => (IReadOnlyList<object?>)[x.StudentNumber, x.Name, x.College, x.Major, x.Class,
|
||||
x.AverageGradePoint, x.Conclusion == DegreeAwardConclusion.Granted ? "建议授予" : "暂不授予",
|
||||
x.ExceptionReason, x.IsOverridden ? "是" : "否", x.ReviewComment]).ToList());
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType, DownloadFileName.Export("学位授予审核", ".xlsx", batch.GraduationYear.ToString(), batch.EnrollmentYear.ToString()));
|
||||
}
|
||||
|
||||
[HttpGet("my-result")]
|
||||
[Authorize(Roles = SystemRoles.Student)]
|
||||
public async Task<ActionResult> GetMyResult(CancellationToken token)
|
||||
@@ -360,6 +455,7 @@ public sealed class DegreeAwardsController(
|
||||
public sealed record DegreeAwardBatchRequest(
|
||||
[Required, MinLength(3), MaxLength(120)] string Name,
|
||||
[Range(2000, 2200)] int GraduationYear,
|
||||
[Range(2000, 2200)] int EnrollmentYear,
|
||||
[Required, MinLength(2), MaxLength(80)] string DegreeName,
|
||||
[Range(typeof(decimal), "0", "5")] decimal MinimumGradePoint,
|
||||
[MaxLength(500)] string? Notes);
|
||||
|
||||
Reference in new issue
Block a user