点名、成绩册统一读取“行政班在籍学生 ∪ 已选课学生”,不再错误显示 0 人。
教师选课名单改为展示全部本人教学班及完整学生名单,支持 Excel 导出。 调停课改用教师专用教学班接口,并在服务端限制只能操作本人教学班。
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Jiaowu.Api.Infrastructure.Teaching;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
@@ -98,6 +99,21 @@ public sealed class MySqlMigrationTests
|
||||
Assert.Contains(ids[1].ToString(), sql, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MySql_teaching_task_roster_query_is_translatable()
|
||||
{
|
||||
using var db = new AppDbContext(CreateMySqlOptions());
|
||||
|
||||
var sql = TeachingTaskRosterQuery
|
||||
.ForTask(
|
||||
db,
|
||||
Guid.Parse("11111111-1111-1111-1111-111111111111"))
|
||||
.ToQueryString();
|
||||
|
||||
Assert.Contains("TeachingTaskClasses", sql, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Contains("CourseEnrollments", sql, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MySql_index_names_fit_the_server_identifier_limit()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,178 @@
|
||||
using Jiaowu.Api.Controllers;
|
||||
using Jiaowu.Api.Domain.Academic;
|
||||
using Jiaowu.Api.Domain.Identity;
|
||||
using Jiaowu.Api.Infrastructure.Auth;
|
||||
using Jiaowu.Api.Infrastructure.Persistence;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
public sealed class TeachingWorkflowRosterTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task ClassAssignedStudents_AppearAcrossTeacherWorkflows()
|
||||
{
|
||||
await using var connection = new SqliteConnection("Data Source=:memory:");
|
||||
await connection.OpenAsync();
|
||||
var options = new DbContextOptionsBuilder<AppDbContext>()
|
||||
.UseSqlite(connection)
|
||||
.Options;
|
||||
await using var db = new AppDbContext(options);
|
||||
await db.Database.EnsureCreatedAsync();
|
||||
|
||||
var teacherUserId = Guid.NewGuid();
|
||||
var teacherUser = new ApplicationUser
|
||||
{
|
||||
Id = teacherUserId,
|
||||
UserName = "T001",
|
||||
NormalizedUserName = "T001",
|
||||
DisplayName = "张老师"
|
||||
};
|
||||
var college = new College { Code = "CS", Name = "计算机学院" };
|
||||
var major = new Major
|
||||
{
|
||||
Code = "080901",
|
||||
Name = "计算机科学与技术",
|
||||
CollegeId = college.Id,
|
||||
DegreeType = "工学学士"
|
||||
};
|
||||
var administrativeClass = new AdministrativeClass
|
||||
{
|
||||
Code = "CS2026-01",
|
||||
Name = "计科 2026-1 班",
|
||||
MajorId = major.Id,
|
||||
Grade = 2026
|
||||
};
|
||||
var student = new Student
|
||||
{
|
||||
StudentNumber = "202601001",
|
||||
Name = "周同学",
|
||||
AdministrativeClassId = administrativeClass.Id,
|
||||
EnrollmentYear = 2026,
|
||||
EnrollmentDate = new DateOnly(2026, 9, 1)
|
||||
};
|
||||
var teacher = new Teacher
|
||||
{
|
||||
TeacherNumber = "T001",
|
||||
Name = "张老师",
|
||||
CollegeId = college.Id,
|
||||
UserId = teacherUserId
|
||||
};
|
||||
var course = new Course
|
||||
{
|
||||
Code = "CS101",
|
||||
Name = "程序设计基础",
|
||||
CollegeId = college.Id,
|
||||
Credits = 4,
|
||||
TotalHours = 64,
|
||||
LectureHours = 48,
|
||||
PracticeHours = 16,
|
||||
Nature = CourseNature.MajorRequired,
|
||||
AssessmentMethod = AssessmentMethod.Examination
|
||||
};
|
||||
var term = new AcademicTerm
|
||||
{
|
||||
Code = "2026-1",
|
||||
Name = "2026—2027 学年第一学期",
|
||||
AcademicYear = "2026-2027",
|
||||
Season = TermSeason.Autumn,
|
||||
StartDate = new DateOnly(2026, 9, 1),
|
||||
EndDate = new DateOnly(2027, 1, 20)
|
||||
};
|
||||
var task = new TeachingTask
|
||||
{
|
||||
TaskNumber = "2026-1-CS101-01",
|
||||
Name = "程序设计基础教学班",
|
||||
AcademicTermId = term.Id,
|
||||
CourseId = course.Id,
|
||||
Capacity = 60,
|
||||
Status = TeachingTaskStatus.Published,
|
||||
Teachers =
|
||||
[
|
||||
new TeachingTaskTeacher
|
||||
{
|
||||
TeacherId = teacher.Id,
|
||||
IsPrimary = true
|
||||
}
|
||||
],
|
||||
Classes =
|
||||
[
|
||||
new TeachingTaskClass
|
||||
{
|
||||
AdministrativeClassId = administrativeClass.Id
|
||||
}
|
||||
]
|
||||
};
|
||||
db.AddRange(
|
||||
teacherUser,
|
||||
college,
|
||||
major,
|
||||
administrativeClass,
|
||||
student,
|
||||
teacher,
|
||||
course,
|
||||
term,
|
||||
task);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
var scope = new TeacherDataScope(teacherUserId);
|
||||
var attendance = new AttendanceController(db, scope);
|
||||
var attendanceResult = await attendance.CreateSheet(
|
||||
new AttendanceSheetRequest(
|
||||
task.Id,
|
||||
"第1周点名",
|
||||
new DateTime(2026, 9, 3),
|
||||
null,
|
||||
AttendanceCheckInMethod.Manual,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null),
|
||||
CancellationToken.None);
|
||||
Assert.IsType<CreatedResult>(attendanceResult);
|
||||
Assert.Equal(1, await db.AttendanceRecords.CountAsync());
|
||||
|
||||
var grades = new GradesController(db, scope);
|
||||
var gradeResult = await grades.CreateSheet(
|
||||
new GradeSheetRequest(task.Id, 40, 60, []),
|
||||
CancellationToken.None);
|
||||
Assert.IsType<CreatedResult>(gradeResult);
|
||||
Assert.Equal(1, await db.GradeRecords.CountAsync());
|
||||
|
||||
var selections = new CourseSelectionsController(db, scope);
|
||||
Assert.Single(ReadItems(await selections.GetMyTeachingTasks(
|
||||
term.Id,
|
||||
CancellationToken.None)));
|
||||
var roster = Assert.IsType<OkObjectResult>(
|
||||
await selections.GetTeachingTaskRoster(task.Id, CancellationToken.None));
|
||||
Assert.Equal(1, ReadIntProperty(roster.Value!, "StudentCount"));
|
||||
|
||||
var adjustments = new CourseAdjustmentsController(db, scope);
|
||||
Assert.Single(ReadItems(await adjustments.GetTaskOptions(
|
||||
term.Id,
|
||||
CancellationToken.None)));
|
||||
}
|
||||
|
||||
private static List<object> ReadItems(ActionResult result)
|
||||
{
|
||||
var ok = Assert.IsType<OkObjectResult>(result);
|
||||
return Assert.IsAssignableFrom<System.Collections.IEnumerable>(ok.Value)
|
||||
.Cast<object>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static int ReadIntProperty(object value, string name) =>
|
||||
(int)value.GetType().GetProperty(name)!.GetValue(value)!;
|
||||
|
||||
private sealed class TeacherDataScope(Guid userId) : ICurrentUserDataScope
|
||||
{
|
||||
public CurrentUserScope Current { get; } = new(
|
||||
userId,
|
||||
"张老师",
|
||||
null,
|
||||
DataScope.Self,
|
||||
new HashSet<string>([SystemRoles.Teacher]));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user