ExamTeacherCourseAppService.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 监测教师任教科目管理服务
  5. /// </summary>
  6. [ApiDescriptionSettings(Name = "exam-teacher-course")]
  7. [Route("exam/teacher/course")]
  8. public class ExamTeacherCourseAppService : IDynamicApiController
  9. {
  10. private readonly IExamTeacherCourseService _examTeacherCourseService;
  11. public ExamTeacherCourseAppService(IExamTeacherCourseService examTeacherCourseService)
  12. {
  13. _examTeacherCourseService = examTeacherCourseService;
  14. }
  15. #region 批量导入
  16. /// <summary>
  17. /// 上传批量导入文件
  18. /// </summary>
  19. /// <param name="input"></param>
  20. /// <returns></returns>
  21. [RequestSizeLimit(long.MaxValue)]
  22. [RequestFormLimits(MultipartBodyLengthLimit = long.MaxValue)]
  23. public async Task<UploadExamDataOutput<UploadExamTeacherCourseOutput>> Upload([FromForm] UploadExamDataInput 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. var ret = await _examTeacherCourseService.Upload(filePath, input.ExamPlanId);
  36. return ret;
  37. }
  38. /// <summary>
  39. /// 批量导入监测教师
  40. /// </summary>
  41. /// <param name="input"></param>
  42. /// <returns></returns>
  43. public async Task Import(ImportExamTeacherCourseInput input)
  44. {
  45. await _examTeacherCourseService.Import(input);
  46. }
  47. #endregion
  48. #region 批量导出
  49. /// <summary>
  50. /// 导出TQES导入文件格式文件包
  51. /// </summary>
  52. /// <param name="examPlanId"></param>
  53. /// <returns></returns>
  54. /// <exception cref="Exception"></exception>
  55. [AllowAnonymous]
  56. public async Task<IActionResult> ExportTqesFile([Required]int examPlanId)
  57. {
  58. var (fileName, fileBytes) = await _examTeacherCourseService.ExportTqesFile(examPlanId);
  59. return new FileContentResult(fileBytes, "application/octet-stream")
  60. {
  61. FileDownloadName = fileName,
  62. };
  63. }
  64. #endregion
  65. #region 创建编辑
  66. /// <summary>
  67. /// 添加监测教师
  68. /// </summary>
  69. /// <param name="input"></param>
  70. /// <returns></returns>
  71. public async Task Add(AddExamTeacherCourseInput input)
  72. {
  73. await _examTeacherCourseService.Add(input);
  74. }
  75. /// <summary>
  76. /// 更新监测教师
  77. /// </summary>
  78. /// <param name="input"></param>
  79. /// <returns></returns>
  80. public async Task Update(UpdateExamTeacherCourseInput input)
  81. {
  82. await _examTeacherCourseService.Update(input);
  83. }
  84. /// <summary>
  85. /// 删除监测教师
  86. /// </summary>
  87. /// <param name="input"></param>
  88. /// <returns></returns>
  89. public async Task Del(BaseId input)
  90. {
  91. await _examTeacherCourseService.Del(input);
  92. }
  93. /// <summary>
  94. /// 清空监测教师
  95. /// </summary>
  96. /// <param name="input"></param>
  97. /// <returns></returns>
  98. public async Task Clear(ClearExamTeacherCourseInput input)
  99. {
  100. await _examTeacherCourseService.Clear(input);
  101. }
  102. #endregion
  103. #region 查询统计
  104. /// <summary>
  105. /// 分页查询监测教师列表
  106. /// </summary>
  107. /// <param name="input"></param>
  108. /// <returns></returns>
  109. public async Task<PageResult<ExamTeacherCourseOutput>> QueryPageList(ExamTeacherCoursePageInput input)
  110. {
  111. return await _examTeacherCourseService.QueryPageList(input);
  112. }
  113. #endregion
  114. }