Add customizable tabular data exports
This commit is contained in:
1 parent
5d5781e707
commit
3e6cd85662
15 files changed
+312
-40
No files matched your search
@@ -51,6 +51,10 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType, DownloadFileName.Template(KindName(kind), ".xlsx"));
|
||||
}
|
||||
|
||||
[HttpGet("{kind}/export-columns")]
|
||||
public IActionResult ExportColumns(string kind) =>
|
||||
TryGetHeaders(kind, out var headers) ? Ok(headers) : NotFound();
|
||||
|
||||
[HttpGet("{kind}/export")]
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<IActionResult> Export(
|
||||
@@ -65,15 +69,15 @@ public sealed class BaseDataExcelController(AppDbContext db, IAppCache cache) :
|
||||
Guid? buildingId = null,
|
||||
int? minimumCapacity = null,
|
||||
TeachingVenueNature? teachingVenueNature = null,
|
||||
bool? isEnabled = null)
|
||||
bool? isEnabled = null,
|
||||
string? columns = null,
|
||||
string? format = null)
|
||||
{
|
||||
if (!TryGetHeaders(kind, out var headers)) return NotFound();
|
||||
var rows = await GetExportRowsAsync(kind, cancellationToken, isArchived, keyword?.Trim(),
|
||||
collegeId, majorId, grade, campusId, buildingId, minimumCapacity,
|
||||
teachingVenueNature, isEnabled);
|
||||
var bytes = ExcelWorkbookHelper.Create(KindName(kind), headers, rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export(KindName(kind), ".xlsx"));
|
||||
return TabularExport.Create(this, KindName(kind), headers, rows, columns, format);
|
||||
}
|
||||
|
||||
[HttpPost("{kind}/import")]
|
||||
|
||||
@@ -62,12 +62,21 @@ public sealed class CourseSelectionsController(
|
||||
return Ok(new PagedResult<object>(items.Cast<object>().ToList(), total, page, pageSize));
|
||||
}
|
||||
|
||||
private static readonly string[] EnrollmentExportHeaders = [
|
||||
"学期", "开课院系", "课程代码", "课程名称", "教学班", "学号", "姓名",
|
||||
"专业", "行政班", "年级", "修读状态", "修读类型", "选入时间", "退选时间", "免修审批"];
|
||||
private static readonly string[] StudentEnrollmentExportHeaders = ["学号", "姓名", "专业", "行政班", "年级", "修读课程", "在修学分"];
|
||||
|
||||
[HttpGet("enrollments/export-columns")]
|
||||
[Authorize(Roles = OfferingManagers)]
|
||||
public IActionResult EnrollmentExportColumns(bool student = false) => Ok(student ? StudentEnrollmentExportHeaders : EnrollmentExportHeaders);
|
||||
|
||||
[HttpGet("enrollments/export.xlsx")]
|
||||
[Authorize(Roles = OfferingManagers)]
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<ActionResult> ExportEnrollments(
|
||||
[FromQuery] CourseEnrollmentQuery query,
|
||||
CancellationToken cancellationToken)
|
||||
CancellationToken cancellationToken, string? columns = null, string? format = null)
|
||||
{
|
||||
var items = await ProjectEnrollments(OrderEnrollments(
|
||||
ApplyEnrollmentFilters(ScopedEnrollments(), query)))
|
||||
@@ -78,12 +87,7 @@ public sealed class CourseSelectionsController(
|
||||
x.Status.ToString(), x.EnrollmentType.ToString(), x.EnrolledAt,
|
||||
x.WithdrawnAt, x.ExemptionStatus?.ToString() ?? "—"
|
||||
]).ToList();
|
||||
var bytes = ExcelWorkbookHelper.Create("修读课程名单", [
|
||||
"学期", "开课院系", "课程代码", "课程名称", "教学班", "学号", "姓名",
|
||||
"专业", "行政班", "年级", "修读状态", "修读类型", "选入时间", "退选时间", "免修审批"
|
||||
], rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export("修读课程名单", ".xlsx"));
|
||||
return TabularExport.Create(this, "修读课程名单", EnrollmentExportHeaders, rows, columns, format);
|
||||
}
|
||||
|
||||
[HttpGet("enrollments/students")]
|
||||
@@ -135,7 +139,7 @@ public sealed class CourseSelectionsController(
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<ActionResult> ExportStudentEnrollmentSummaries(
|
||||
[FromQuery] CourseEnrollmentQuery query,
|
||||
CancellationToken cancellationToken)
|
||||
CancellationToken cancellationToken, string? columns = null, string? format = null)
|
||||
{
|
||||
var items = await ProjectEnrollments(OrderEnrollments(
|
||||
ApplyEnrollmentFilters(ScopedEnrollments(), query)))
|
||||
@@ -158,11 +162,7 @@ public sealed class CourseSelectionsController(
|
||||
group.Where(x => x.Status == CourseEnrollmentStatus.Enrolled)
|
||||
.Sum(x => x.Credits)
|
||||
]).ToList();
|
||||
var bytes = ExcelWorkbookHelper.Create("学生修读汇总", [
|
||||
"学号", "姓名", "专业", "行政班", "年级", "修读课程", "在修学分"
|
||||
], rows);
|
||||
return File(bytes, ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export("学生修读汇总", ".xlsx"));
|
||||
return TabularExport.Create(this, "学生修读汇总", StudentEnrollmentExportHeaders, rows, columns, format);
|
||||
}
|
||||
|
||||
[HttpGet("rounds")]
|
||||
|
||||
@@ -56,6 +56,9 @@ public sealed class CoursesExcelController(
|
||||
DownloadFileName.Template("课程库", ".xlsx"));
|
||||
}
|
||||
|
||||
[HttpGet("export-columns")]
|
||||
public IActionResult ExportColumns() => Ok(Headers);
|
||||
|
||||
[HttpGet("export")]
|
||||
[ProducesResponseType<FileContentResult>(StatusCodes.Status200OK, ExcelWorkbookHelper.ContentType)]
|
||||
public async Task<IActionResult> Export(
|
||||
@@ -65,7 +68,9 @@ public sealed class CoursesExcelController(
|
||||
CourseNature? nature = null,
|
||||
bool? isEnabled = null,
|
||||
CancellationToken cancellationToken = default,
|
||||
bool? isArchived = null)
|
||||
bool? isArchived = null,
|
||||
string? columns = null,
|
||||
string? format = null)
|
||||
{
|
||||
var source = ApplyFilters(
|
||||
ScopedCourses().AsNoTracking(),
|
||||
@@ -100,11 +105,7 @@ public sealed class CoursesExcelController(
|
||||
x.SortOrder))
|
||||
.ToList();
|
||||
|
||||
var bytes = ExcelWorkbookHelper.Create("课程库", Headers, rows);
|
||||
return File(
|
||||
bytes,
|
||||
ExcelWorkbookHelper.ContentType,
|
||||
DownloadFileName.Export("课程库", ".xlsx"));
|
||||
return TabularExport.Create(this, "课程库", Headers, rows, columns, format);
|
||||
}
|
||||
|
||||
[HttpPost("import")]
|
||||
|
||||
Loaded 3 of 15 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user