ExamResultAppService.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.Extensions.Options;
  2. using YBEE.EQM.Core;
  3. namespace YBEE.EQM.Application;
  4. /// <summary>
  5. /// 反馈结果管理服务
  6. /// </summary>
  7. [ApiDescriptionSettings(Name = "exam-result")]
  8. [Route("exam/result")]
  9. public class ExamResultAppService : IDynamicApiController
  10. {
  11. private readonly IExamResultService _examResultService;
  12. private readonly EqmSiteOptions _eqmSiteOptions;
  13. public ExamResultAppService(IExamResultService examResultService, IOptions<EqmSiteOptions> options)
  14. {
  15. _examResultService = examResultService;
  16. _eqmSiteOptions = options.Value;
  17. }
  18. /// <summary>
  19. /// 上传统一反馈文件
  20. /// </summary>
  21. /// <param name="input"></param>
  22. /// <returns></returns>
  23. [RequestSizeLimit(long.MaxValue)]
  24. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  25. public async Task Upload([FromForm] UploadExamResultInput input)
  26. {
  27. var savePath = Path.Combine(input.ExamPlanId.ToString(), input.ExamDataPublishId.ToString());
  28. var saveRoot = Path.Combine(_eqmSiteOptions.ExamResultRoot, savePath);
  29. if (!Directory.Exists(saveRoot))
  30. {
  31. Directory.CreateDirectory(saveRoot);
  32. }
  33. var extName = Path.GetExtension(input.File.FileName);
  34. var fileName = Guid.NewGuid().ToString("N") + extName;
  35. using var stream = File.Create(Path.Combine(saveRoot, fileName));
  36. await input.File.CopyToAsync(stream);
  37. await stream.FlushAsync();
  38. AddExamResultInput item = input.Adapt<AddExamResultInput>();
  39. item.FileName = input.File.FileName;
  40. item.FilePath = Path.Combine(savePath, fileName);
  41. item.FileSize = input.File.Length;
  42. item.FileExtName = Path.GetExtension(input.File.FileName);
  43. await _examResultService.Add(item);
  44. }
  45. /// <summary>
  46. /// 根据发布内容ID获取文件列表
  47. /// </summary>
  48. /// <param name="publishId"></param>
  49. /// <returns></returns>
  50. public async Task<List<ExamResultOutput>> GetListByPublishId([FromQuery][Required] int publishId)
  51. {
  52. return await _examResultService.GetListByPublishId(publishId);
  53. }
  54. }