Customize dynamic assessment exports
This commit is contained in:
1 parent
4925763384
commit
fd9633121d
6 files changed
+73
-31
No files matched your search
@@ -864,7 +864,7 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<ActionResult> ExportResults(
|
||||
Guid id, string? keyword = null, int? grade = null, Guid? collegeId = null,
|
||||
Guid? majorId = null, Guid? classId = null, CancellationToken token = default)
|
||||
Guid? majorId = null, Guid? classId = null, CancellationToken token = default, bool columnsOnly = false, string? columns = null, string? format = null)
|
||||
{
|
||||
var batch = await ApplyBatchScope(db.ComprehensiveAssessmentBatches.AsNoTracking())
|
||||
.Include(x => x.Scheme).ThenInclude(x => x!.Dimensions)
|
||||
@@ -892,6 +892,7 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
var headers = new List<string> { "学号", "姓名", "年级", "行政班", "专业", "学院", "总分", "班级排名", "专业排名", "学院排名", "缺失必需维度数" };
|
||||
headers.AddRange(dimensions.Select(x => $"{x.Name}原始分"));
|
||||
headers.AddRange(dimensions.Select(x => $"{x.Name}折算分"));
|
||||
if (columnsOnly) return Ok(headers);
|
||||
var rows = resultRows.Select(result =>
|
||||
{
|
||||
var values = new List<object?>
|
||||
@@ -906,6 +907,8 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
values.AddRange(dimensions.Select(x => detailMap.GetValueOrDefault(x.Id)?.WeightedScore));
|
||||
return (IReadOnlyList<object?>)values;
|
||||
}).ToList();
|
||||
if (columns is not null || format is not null)
|
||||
return TabularExport.Create(this, "综合测评结果", headers.ToArray(), rows, columns, format);
|
||||
var bytes = ExcelWorkbookHelper.Create("综合测评结果", headers, rows,
|
||||
["导出内容只包含当前账号数据权限范围内的学生。", "原始分、折算分及排名均来自本批次最后一次成功计算快照。"]);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
@@ -917,7 +920,7 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<ActionResult> ExportLiveResults(
|
||||
Guid id, string? keyword = null, int? grade = null, Guid? collegeId = null,
|
||||
Guid? majorId = null, Guid? classId = null, CancellationToken token = default)
|
||||
Guid? majorId = null, Guid? classId = null, CancellationToken token = default, bool columnsOnly = false, string? columns = null, string? format = null)
|
||||
{
|
||||
var batch = await ApplyBatchScope(db.ComprehensiveAssessmentBatches.AsNoTracking())
|
||||
.Include(x => x.Scheme).ThenInclude(x => x!.Dimensions)
|
||||
@@ -948,6 +951,7 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
headers.AddRange(dimensions.Select(x => $"{x.Name}原始分"));
|
||||
headers.AddRange(dimensions.Select(x => $"{x.Name}折算分"));
|
||||
headers.AddRange(dimensions.Select(x => $"{x.Name}状态"));
|
||||
if (columnsOnly) return Ok(headers);
|
||||
var rows = results.Select(result =>
|
||||
{
|
||||
var values = new List<object?>
|
||||
@@ -967,6 +971,8 @@ public sealed class ComprehensiveAssessmentsController(
|
||||
}));
|
||||
return (IReadOnlyList<object?>)values;
|
||||
}).ToList();
|
||||
if (columns is not null || format is not null)
|
||||
return TabularExport.Create(this, "综合测评实时预估", headers.ToArray(), rows, columns, format);
|
||||
var bytes = ExcelWorkbookHelper.Create("综合测评实时预估", headers, rows,
|
||||
["导出内容与当前筛选和账号数据权限一致。", "实时预估不包含正式排名,不能替代维度锁定和正式评定。"]);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
|
||||
@@ -225,7 +225,7 @@ public sealed class ExperimentGradesController(
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<IActionResult> ExportTeachingTaskScores(
|
||||
Guid teachingTaskId,
|
||||
CancellationToken cancellationToken)
|
||||
CancellationToken cancellationToken, bool columnsOnly = false, string? columns = null, string? format = null)
|
||||
{
|
||||
var sheets = await ScopedSheets()
|
||||
.Where(sheet =>
|
||||
@@ -270,6 +270,7 @@ public sealed class ExperimentGradesController(
|
||||
$"{sheet.ExperimentProject!.Code}·{sheet.ExperimentProject.Name}" +
|
||||
$"({SheetStatusLabel(sheet.Status)})"));
|
||||
headers.Add("实验合成总分(仅已发布项目)");
|
||||
if (columnsOnly) return Ok(headers);
|
||||
|
||||
var rows = students.Select(student =>
|
||||
{
|
||||
@@ -290,6 +291,8 @@ public sealed class ExperimentGradesController(
|
||||
values.Add(aggregate.Scores.GetValueOrDefault(student.Id));
|
||||
return (IReadOnlyList<object?>)values;
|
||||
}).ToList();
|
||||
if (columns is not null || format is not null)
|
||||
return TabularExport.Create(this, "课程实验成绩", headers.ToArray(), rows, columns, format);
|
||||
var bytes = ExcelWorkbookHelper.Create("课程实验成绩", headers, rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export(
|
||||
|
||||
@@ -347,6 +347,17 @@ public sealed class ComprehensiveAssessmentsControllerTests
|
||||
token: CancellationToken.None));
|
||||
using var workbook = new XLWorkbook(new MemoryStream(export.FileContents));
|
||||
Assert.Equal(2, workbook.Worksheet("综合测评实时预估").LastRowUsed()!.RowNumber());
|
||||
var columns = Assert.IsType<OkObjectResult>(await collegeController.ExportLiveResults(
|
||||
fixture.Batch.Id, classId: fixture.Student.AdministrativeClassId,
|
||||
token: CancellationToken.None, columnsOnly: true));
|
||||
var headers = Assert.IsType<List<string>>(columns.Value);
|
||||
Assert.Contains("当前预估分", headers);
|
||||
var custom = Assert.IsType<FileContentResult>(await collegeController.ExportLiveResults(
|
||||
fixture.Batch.Id, classId: fixture.Student.AdministrativeClassId,
|
||||
token: CancellationToken.None, columns: "1,0", format: "xlsx"));
|
||||
using var selected = new XLWorkbook(new MemoryStream(custom.FileContents));
|
||||
Assert.Equal("姓名", selected.Worksheet(1).Cell(1, 1).GetString());
|
||||
Assert.Equal("学号", selected.Worksheet(1).Cell(1, 2).GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Loaded 3 of 6 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user