ExamTeacherCourseAppService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. public async Task<IActionResult> ExportTqesFile([Required]int examPlanId)
  56. {
  57. var (fileName, fileBytes) = await _examTeacherCourseService.ExportTqesFile(examPlanId);
  58. return new FileContentResult(fileBytes, "application/octet-stream")
  59. {
  60. FileDownloadName = fileName,
  61. };
  62. }
  63. #endregion
  64. #region 创建编辑
  65. /// <summary>
  66. /// 添加监测教师
  67. /// </summary>
  68. /// <param name="input"></param>
  69. /// <returns></returns>
  70. public async Task Add(AddExamTeacherCourseInput input)
  71. {
  72. await _examTeacherCourseService.Add(input);
  73. }
  74. /// <summary>
  75. /// 更新监测教师
  76. /// </summary>
  77. /// <param name="input"></param>
  78. /// <returns></returns>
  79. public async Task Update(UpdateExamTeacherCourseInput input)
  80. {
  81. await _examTeacherCourseService.Update(input);
  82. }
  83. /// <summary>
  84. /// 删除监测教师
  85. /// </summary>
  86. /// <param name="input"></param>
  87. /// <returns></returns>
  88. public async Task Del(BaseId input)
  89. {
  90. await _examTeacherCourseService.Del(input);
  91. }
  92. /// <summary>
  93. /// 清空监测教师
  94. /// </summary>
  95. /// <param name="input"></param>
  96. /// <returns></returns>
  97. public async Task Clear(ClearExamTeacherCourseInput input)
  98. {
  99. await _examTeacherCourseService.Clear(input);
  100. }
  101. #endregion
  102. #region 查询统计
  103. /// <summary>
  104. /// 分页查询监测教师列表
  105. /// </summary>
  106. /// <param name="input"></param>
  107. /// <returns></returns>
  108. public async Task<PageResult<ExamTeacherCourseOutput>> QueryPageList(ExamTeacherCoursePageInput input)
  109. {
  110. return await _examTeacherCourseService.QueryPageList(input);
  111. }
  112. #endregion
  113. }