ExamScoreImportAppService.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 学生成绩导入服务
  5. /// </summary>
  6. [ApiDescriptionSettings(Name = "exam-score-import")]
  7. [Route("exam/score/import")]
  8. public class ExamScoreImportAppService(IExamScoreImportService service) : IDynamicApiController
  9. {
  10. private readonly IExamScoreImportService _examScoreImportService = service;
  11. /// <summary>
  12. /// 上传文件并完成批量导入前期未上报学生名单的各科成绩
  13. /// </summary>
  14. /// <param name="input"></param>
  15. /// <returns></returns>
  16. [RequestSizeLimit(long.MaxValue)]
  17. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  18. public async Task UploadImportWithoutStudentTotalScore([FromForm] UploadExamDataInput input)
  19. {
  20. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  21. if (fileExt != ".xls" && fileExt != ".xlsx")
  22. {
  23. throw Oops.Oh(ErrorCode.E1010);
  24. }
  25. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  26. using FileStream fs = File.Create(filePath);
  27. await input.File.CopyToAsync(fs);
  28. await fs.FlushAsync();
  29. fs.Close();
  30. await _examScoreImportService.UploadImportWithoutStudentTotalScore(filePath, input.ExamPlanId);
  31. }
  32. /// <summary>
  33. /// 批量导入学生总成绩
  34. /// </summary>
  35. /// <param name="input"></param>
  36. /// <returns></returns>
  37. [RequestSizeLimit(long.MaxValue)]
  38. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  39. public async Task UploadImportStudentTotalScore([FromForm] UploadExamDataInput input)
  40. {
  41. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  42. if (fileExt != ".xls" && fileExt != ".xlsx")
  43. {
  44. throw Oops.Oh(ErrorCode.E1010);
  45. }
  46. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  47. using FileStream fs = File.Create(filePath);
  48. await input.File.CopyToAsync(fs);
  49. await fs.FlushAsync();
  50. fs.Close();
  51. await _examScoreImportService.UploadImportStudentTotalScore(filePath, input.ExamPlanId);
  52. }
  53. /// <summary>
  54. /// 导入区校合并小题成绩
  55. /// </summary>
  56. /// <param name="input"></param>
  57. /// <returns></returns>
  58. [RequestSizeLimit(long.MaxValue)]
  59. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  60. public async Task<FileContentResult> UploadImportStudentMinorScore([FromForm] UploadExamDataInput input)
  61. {
  62. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  63. if (fileExt != ".zip")
  64. {
  65. throw Oops.Oh(ErrorCode.E1010);
  66. }
  67. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  68. using FileStream fs = File.Create(filePath);
  69. await input.File.CopyToAsync(fs);
  70. await fs.FlushAsync();
  71. fs.Close();
  72. var (fileName, fileBytes) = await _examScoreImportService.UploadImportStudentMinorScore(filePath, input.ExamPlanId);
  73. return new FileContentResult(fileBytes, "application/octet-stream")
  74. {
  75. FileDownloadName = fileName,
  76. };
  77. }
  78. }