123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using YBEE.EQM.Core;
- namespace YBEE.EQM.Application;
- /// <summary>
- /// 学生成绩导入服务
- /// </summary>
- [ApiDescriptionSettings(Name = "exam-score-import")]
- [Route("exam/score/import")]
- public class ExamScoreImportAppService(IExamScoreImportService service) : IDynamicApiController
- {
- private readonly IExamScoreImportService _examScoreImportService = service;
- /// <summary>
- /// 上传文件并完成批量导入前期未上报学生名单的各科成绩
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [RequestSizeLimit(long.MaxValue)]
- [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
- public async Task UploadImportWithoutStudentTotalScore([FromForm] UploadExamDataInput input)
- {
- string fileExt = Path.GetExtension(input.File.FileName).ToLower();
- if (fileExt != ".xls" && fileExt != ".xlsx")
- {
- throw Oops.Oh(ErrorCode.E1010);
- }
- string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
- using FileStream fs = File.Create(filePath);
- await input.File.CopyToAsync(fs);
- await fs.FlushAsync();
- fs.Close();
- await _examScoreImportService.UploadImportWithoutStudentTotalScore(filePath, input.ExamPlanId);
- }
- /// <summary>
- /// 批量导入学生总成绩
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [RequestSizeLimit(long.MaxValue)]
- [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
- public async Task UploadImportStudentTotalScore([FromForm] UploadExamDataInput input)
- {
- string fileExt = Path.GetExtension(input.File.FileName).ToLower();
- if (fileExt != ".xls" && fileExt != ".xlsx")
- {
- throw Oops.Oh(ErrorCode.E1010);
- }
- string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
- using FileStream fs = File.Create(filePath);
- await input.File.CopyToAsync(fs);
- await fs.FlushAsync();
- fs.Close();
- await _examScoreImportService.UploadImportStudentTotalScore(filePath, input.ExamPlanId);
- }
- /// <summary>
- /// 导入区校合并小题成绩
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- [RequestSizeLimit(long.MaxValue)]
- [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
- public async Task<FileContentResult> UploadImportStudentMinorScore([FromForm] UploadExamDataInput input)
- {
- string fileExt = Path.GetExtension(input.File.FileName).ToLower();
- if (fileExt != ".zip")
- {
- throw Oops.Oh(ErrorCode.E1010);
- }
- string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
- using FileStream fs = File.Create(filePath);
- await input.File.CopyToAsync(fs);
- await fs.FlushAsync();
- fs.Close();
- var (fileName, fileBytes) = await _examScoreImportService.UploadImportStudentMinorScore(filePath, input.ExamPlanId);
- return new FileContentResult(fileBytes, "application/octet-stream")
- {
- FileDownloadName = fileName,
- };
- }
- }
|