using Microsoft.Extensions.Options;
using YBEE.EQM.Core;
namespace YBEE.EQM.Application;
///
/// 反馈结果管理服务
///
[ApiDescriptionSettings(Name = "exam-result")]
[Route("exam/result")]
public class ExamResultAppService : IDynamicApiController
{
private readonly IExamResultService _examResultService;
private readonly EqmSiteOptions _eqmSiteOptions;
public ExamResultAppService(IExamResultService examResultService, IOptions options)
{
_examResultService = examResultService;
_eqmSiteOptions = options.Value;
}
///
/// 上传统一反馈文件
///
///
///
[RequestSizeLimit(long.MaxValue)]
[RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
public async Task Upload([FromForm] UploadExamResultInput input)
{
var savePath = Path.Combine(input.ExamPlanId.ToString(), input.ExamDataPublishId.ToString());
var saveRoot = Path.Combine(_eqmSiteOptions.ExamResultRoot, savePath);
if (!Directory.Exists(saveRoot))
{
Directory.CreateDirectory(saveRoot);
}
var extName = Path.GetExtension(input.File.FileName);
var fileName = Guid.NewGuid().ToString("N") + extName;
using var stream = File.Create(Path.Combine(saveRoot, fileName));
await input.File.CopyToAsync(stream);
await stream.FlushAsync();
AddExamResultInput item = input.Adapt();
item.FileName = input.File.FileName;
item.FilePath = Path.Combine(savePath, fileName);
item.FileSize = input.File.Length;
item.FileExtName = Path.GetExtension(input.File.FileName);
await _examResultService.Add(item);
}
///
/// 根据发布内容ID获取文件列表
///
///
///
public async Task> GetListByPublishId([FromQuery][Required] int publishId)
{
return await _examResultService.GetListByPublishId(publishId);
}
}