已修改完成,同时解决了“考生名单都是 0 人”的根因。
考生范围统一为“行政班关联学生 + 已选课学生”,并自动去重;考场分配、人数显示、冲突检测、学生考试安排均使用同一口径。[TeachingTaskRosterQuery.cs (line 40)](E:/jiaowu/src/Jiaowu.Api/Infrastructure/Teaching/TeachingTaskRosterQuery.cs:40) 新增考场签名单 Excel 导出接口。[ExamsController.cs (line 568)](E:/jiaowu/src/Jiaowu.Api/Controllers/ExamsController.cs:568) 考试计划页面新增“导出考场签名单”按钮。[ExamsView.vue (line 255)](E:/jiaowu/web/src/views/ExamsView.vue:255) 工作簿包含“考场汇总”以及每个考试场次独立的 A4 签到表,字段包括座位号、学号、姓名、行政班、考生签名和备注。[ExamSignInWorkbookExporter.cs (line 12)](E:/jiaowu/src/Jiaowu.Api/Infrastructure/Exams/ExamSignInWorkbookExporter.cs:12) 未分配考场或监考教师时,也能导出并显示“待分配”。
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using ClosedXML.Excel;
|
||||
using Jiaowu.Api.Controllers;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Caching;
|
||||
using Jiaowu.Api.Infrastructure.Exams;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
@@ -12,7 +15,7 @@ namespace Jiaowu.Api.Tests;
|
||||
public sealed class TeachingWorkflowRosterTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task ClassAssignedStudents_AppearAcrossTeacherWorkflows()
|
||||
public async Task ClassAssignedStudents_AppearAcrossTeachingAndExamWorkflows()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
@@ -23,6 +26,7 @@ public sealed class TeachingWorkflowRosterTests
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
var teacherUserId = Guid.NewGuid();
|
||||
var studentUserId = Guid.NewGuid();
|
||||
var teacherUser = new ApplicationUser
|
||||
{
|
||||
Id = teacherUserId,
|
||||
@@ -30,6 +34,13 @@ public sealed class TeachingWorkflowRosterTests
|
||||
NormalizedUserName = "T001",
|
||||
DisplayName = "张老师"
|
||||
};
|
||||
var studentUser = new ApplicationUser
|
||||
{
|
||||
Id = studentUserId,
|
||||
UserName = "202601001",
|
||||
NormalizedUserName = "202601001",
|
||||
DisplayName = "周同学"
|
||||
};
|
||||
var college = new College { Code = "CS", Name = "计算机学院" };
|
||||
var major = new Major
|
||||
{
|
||||
@@ -51,7 +62,8 @@ public sealed class TeachingWorkflowRosterTests
|
||||
Name = "周同学",
|
||||
AdministrativeClassId = administrativeClass.Id,
|
||||
EnrollmentYear = 2026,
|
||||
EnrollmentDate = new DateOnly(2026, 9, 1)
|
||||
EnrollmentDate = new DateOnly(2026, 9, 1),
|
||||
UserId = studentUserId
|
||||
};
|
||||
var teacher = new Teacher
|
||||
{
|
||||
@@ -107,6 +119,7 @@ public sealed class TeachingWorkflowRosterTests
|
||||
};
|
||||
db.AddRange(
|
||||
teacherUser,
|
||||
studentUser,
|
||||
college,
|
||||
major,
|
||||
administrativeClass,
|
||||
@@ -117,6 +130,28 @@ public sealed class TeachingWorkflowRosterTests
|
||||
task);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var examPlan = new ExamPlan
|
||||
{
|
||||
AcademicTermId = term.Id,
|
||||
Name = "期末考试",
|
||||
Status = ExamPlanStatus.Published,
|
||||
Sessions =
|
||||
[
|
||||
new ExamSession
|
||||
{
|
||||
TeachingTaskId = task.Id,
|
||||
ExamDate = new DateOnly(2027, 1, 8),
|
||||
StartPeriod = 1,
|
||||
PeriodCount = 2,
|
||||
StartsAt = new DateTime(2027, 1, 8, 8, 0, 0, DateTimeKind.Utc),
|
||||
EndsAt = new DateTime(2027, 1, 8, 9, 50, 0, DateTimeKind.Utc),
|
||||
RequiredInvigilatorCount = 1
|
||||
}
|
||||
]
|
||||
};
|
||||
db.ExamPlans.Add(examPlan);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var scope = new TeacherDataScope(teacherUserId);
|
||||
var attendance = new AttendanceController(db, scope);
|
||||
var attendanceResult = await attendance.CreateSheet(
|
||||
@@ -153,6 +188,39 @@ public sealed class TeachingWorkflowRosterTests
|
||||
Assert.Single(ReadItems(await adjustments.GetTaskOptions(
|
||||
term.Id,
|
||||
CancellationToken.None)));
|
||||
|
||||
var managerScope = new ManagerDataScope();
|
||||
var exams = new ExamsController(
|
||||
db,
|
||||
managerScope,
|
||||
new ExamArrangementService(db),
|
||||
NoOpAppCache.Instance);
|
||||
var planResult = Assert.IsType<OkObjectResult>(
|
||||
await exams.GetPlan(examPlan.Id, CancellationToken.None));
|
||||
var planSessions = ReadEnumerableProperty(planResult.Value!, "Sessions");
|
||||
Assert.Equal(1, ReadIntProperty(planSessions.Single(), "StudentCount"));
|
||||
|
||||
var examSessionId = examPlan.Sessions.Single().Id;
|
||||
var rosterResult = Assert.IsType<OkObjectResult>(
|
||||
await exams.GetRoster(examSessionId, CancellationToken.None));
|
||||
Assert.Single(ReadEnumerableProperty(rosterResult.Value!, "Students"));
|
||||
|
||||
var studentExams = new ExamsController(
|
||||
db,
|
||||
new StudentDataScope(studentUserId),
|
||||
new ExamArrangementService(db),
|
||||
NoOpAppCache.Instance);
|
||||
Assert.Single(ReadItems(
|
||||
await studentExams.GetMySchedule(CancellationToken.None)));
|
||||
|
||||
var exportResult = Assert.IsType<FileContentResult>(
|
||||
await exams.ExportSignInSheets(examPlan.Id, CancellationToken.None));
|
||||
using var workbookStream = new MemoryStream(exportResult.FileContents);
|
||||
using var workbook = new XLWorkbook(workbookStream);
|
||||
Assert.Equal(2, workbook.Worksheets.Count);
|
||||
var signInSheet = workbook.Worksheets.Single(x => x.Name != "考场汇总");
|
||||
Assert.Equal("202601001", signInSheet.Cell("C8").GetString());
|
||||
Assert.Equal("周同学", signInSheet.Cell("D8").GetString());
|
||||
}
|
||||
|
||||
private static List<object> ReadItems(ActionResult result)
|
||||
@@ -166,6 +234,12 @@ public sealed class TeachingWorkflowRosterTests
|
||||
private static int ReadIntProperty(object value, string name) =>
|
||||
(int)value.GetType().GetProperty(name)!.GetValue(value)!;
|
||||
|
||||
private static List<object> ReadEnumerableProperty(object value, string name) =>
|
||||
Assert.IsAssignableFrom<System.Collections.IEnumerable>(
|
||||
value.GetType().GetProperty(name)!.GetValue(value))
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
|
||||
private sealed class TeacherDataScope(Guid userId) : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
@@ -175,4 +249,24 @@ public sealed class TeachingWorkflowRosterTests
|
||||
DataScope.Self,
|
||||
new HashSet<string>([SystemRoles.Teacher]));
|
||||
}
|
||||
|
||||
private sealed class StudentDataScope(Guid userId) : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
userId,
|
||||
"周同学",
|
||||
null,
|
||||
DataScope.Self,
|
||||
new HashSet<string>([SystemRoles.Student]));
|
||||
}
|
||||
|
||||
private sealed class ManagerDataScope : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
Guid.NewGuid(),
|
||||
"考试管理员",
|
||||
null,
|
||||
DataScope.All,
|
||||
new HashSet<string>([SystemRoles.AcademicAdmin]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user