NceeScoreAppService.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 高中模拟划线成绩管理服务
  5. /// </summary>
  6. [ApiDescriptionSettings(Name = "ncee-score")]
  7. [Route("ncee/score")]
  8. public class NceeScoreAppService : IDynamicApiController
  9. {
  10. private readonly INceeScoreService _nceeScoreService;
  11. public NceeScoreAppService(INceeScoreService nceeScoreService)
  12. {
  13. _nceeScoreService = nceeScoreService;
  14. }
  15. /// <summary>
  16. /// 上传成绩(仅原始分,适用于五区联考)
  17. /// </summary>
  18. /// <param name="input"></param>
  19. /// <returns></returns>
  20. [AllowAnonymous]
  21. [RequestSizeLimit(long.MaxValue)]
  22. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  23. public async Task UploadOnlyRawScore([FromForm] UploadNceeScoreInput input)
  24. {
  25. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  26. if (fileExt != ".xls" && fileExt != ".xlsx")
  27. {
  28. throw Oops.Oh(ErrorCode.E1010);
  29. }
  30. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  31. using FileStream fs = File.Create(filePath);
  32. await input.File.CopyToAsync(fs);
  33. await fs.FlushAsync();
  34. fs.Close();
  35. await _nceeScoreService.UploadOnlyRawScore(filePath, input.NceePlanId);
  36. }
  37. /// <summary>
  38. /// 上传成绩(带转换分和等级,适用于六校联考)
  39. /// </summary>
  40. /// <param name="input"></param>
  41. /// <returns></returns>
  42. [AllowAnonymous]
  43. [RequestSizeLimit(long.MaxValue)]
  44. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  45. public async Task UploadWithConvertScore([FromForm] UploadNceeScoreInput input)
  46. {
  47. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  48. if (fileExt != ".xls" && fileExt != ".xlsx")
  49. {
  50. throw Oops.Oh(ErrorCode.E1010);
  51. }
  52. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  53. using FileStream fs = File.Create(filePath);
  54. await input.File.CopyToAsync(fs);
  55. await fs.FlushAsync();
  56. fs.Close();
  57. await _nceeScoreService.UploadWithConvertScore(filePath, input.NceePlanId);
  58. }
  59. /// <summary>
  60. /// 上传未选科原始成绩(适用于高一未选科)
  61. /// </summary>
  62. /// <param name="input"></param>
  63. /// <returns></returns>
  64. [AllowAnonymous]
  65. [RequestSizeLimit(long.MaxValue)]
  66. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  67. public async Task UploadNoDirectionCourse([FromForm] UploadNceeScoreInput input)
  68. {
  69. string fileExt = Path.GetExtension(input.File.FileName).ToLower();
  70. if (fileExt != ".xls" && fileExt != ".xlsx")
  71. {
  72. throw Oops.Oh(ErrorCode.E1010);
  73. }
  74. string filePath = Path.Combine(FileUtil.GetTempFileRoot(), $"{Guid.NewGuid()}{fileExt}");
  75. using FileStream fs = File.Create(filePath);
  76. await input.File.CopyToAsync(fs);
  77. await fs.FlushAsync();
  78. fs.Close();
  79. await _nceeScoreService.UploadNoDirectionCourse(filePath, input.NceePlanId);
  80. }
  81. /// <summary>
  82. /// 执行模拟划线
  83. /// </summary>
  84. /// <param name="nceePlanId"></param>
  85. /// <returns></returns>
  86. [AllowAnonymous]
  87. public async Task Execute([FromQuery][Required] int nceePlanId)
  88. {
  89. await _nceeScoreService.Execute(nceePlanId);
  90. }
  91. }