using YBEE.EQM.Core;
namespace YBEE.EQM.Application;
///
/// 学生成绩导入服务
///
[ApiDescriptionSettings(Name = "exam-score-import")]
[Route("exam/score/import")]
public class ExamScoreImportAppService : IDynamicApiController
{
private readonly IExamScoreImportService _examScoreImportService;
public ExamScoreImportAppService(IExamScoreImportService service)
{
_examScoreImportService = service;
}
///
/// 上传文件并完成批量导入前期未上报学生名单的各科成绩
///
///
///
[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);
}
///
/// 批量导入学生总成绩
///
///
///
[AllowAnonymous]
[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);
}
///
/// 导入区校合并小题成绩
///
///
///
[AllowAnonymous]
[RequestSizeLimit(long.MaxValue)]
[RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
public async Task 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,
};
}
}