2 Commity 260d5cecb3 ... d95a760704

Autor SHA1 Wiadomość Data
  guqiang d95a760704 Merge branch 'feature/exam' into test 5 godzin temu
  guqiang 4803212e36 增加模版下载接口 5 godzin temu

+ 15 - 1
src/Hotline.Api/Controllers/Exam/QuestionController.cs

@@ -2,6 +2,8 @@
 using Exam.Share.ViewResponses.Question;
 using Hotline.Application.Exam.Constants.ApiRoutes;
 using Hotline.Application.Exam.Interface.Questions;
+using Hotline.Application.ExportExcel;
+using Hotline.Exams.Questions;
 using Hotline.Repository.SqlSugar.Exam.Interface;
 using Hotline.Share.Dtos.Questions;
 using Hotline.Share.Requests.Question;
@@ -15,11 +17,13 @@ namespace Hotline.Api.Controllers.Exam
     {
         private readonly IQuestionService _questionService;
         private readonly IMapper _mapper;
+        private readonly IExportApplication _exportApplication;
 
-        public QuestionController(IQuestionService questionService,IMapper mapper)
+        public QuestionController(IQuestionService questionService,IMapper mapper, IExportApplication exportApplication)
         {
             _questionService = questionService;
             this._mapper = mapper;
+            this._exportApplication = exportApplication;
         }
 
         /// <summary>
@@ -118,5 +122,15 @@ namespace Hotline.Api.Controllers.Exam
             await _questionService.ImportExcel(files, HttpContext.RequestAborted);
         }
 
+        /// <summary>
+        /// 下载Excel模版
+        /// </summary>
+        /// <returns></returns>
+        [HttpGet(ExamManageApiRoute.Download)]
+        public FileStreamResult Download()
+        {
+            var list = new List<QuestionExcel>();
+            return _exportApplication.ExportData(list, "Template.xlsx");
+        }
     }
 }

+ 2 - 0
src/Hotline.Application/Exam/Constants/ApiRoutes/ExamManageApiRoute.cs

@@ -3,5 +3,7 @@
     public class ExamManageApiRoute:GenerateApiRoute
     {
         public const string ImportExcel = "ImportExcel";
+
+        public const string Download = "Download";
     }
 }

+ 1 - 3
src/Hotline.Application/Exam/Service/ExamManages/ExtractRuleService.cs

@@ -258,9 +258,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
         {
             if (actionRequest.TagQuestionDtos == null) return null;
 
-            actionRequest.TagQuestionDtos.ResolveOperationStatus();
-
-            var tagQuestionDtos = actionRequest.TagQuestionDtos.Where(x => x.OperationStatus == EEOperationStatus.Add).ToList();
+            var tagQuestionDtos = actionRequest.TagQuestionDtos.Where(x => x.OperationStatus == EEOperationStatus.Add && x.Count!=null).ToList();
 
             var tagQuestions = _mapper.Map<List<ExamTagQuestion>>(tagQuestionDtos);
 

+ 6 - 7
src/Hotline.Application/Exam/Service/TestPapers/TestPaperService.cs

@@ -394,17 +394,16 @@ namespace Hotline.Application.Exam.Service.TestPapers
             var tagQuestionTable = tagQuestionRepository.Queryable().Where(expression);
             var questionTable = quesitonRepository.Queryable().Where(questionExpression);
 
-            var taqQuestions = await tagQuestionTable.InnerJoin(questionTable, (t, q) => t.QuestionId == q.Id)
-                .Select((t, q) => new TagQuestionCountViewResponse
-                {
-                    TotalCount = SqlFunc.AggregateCount(q.Id!=null)
-                })
+            var taqQuestions = await tagQuestionTable.InnerJoin(questionTable, (t, q) => t.QuestionId == q.Id).GroupBy((t, q) => q.Id)
+                .Select((t, q) =>q.Id)
                 .ToListAsync();
 
-            return taqQuestions.Count()> 0?taqQuestions.FirstOrDefault():new TagQuestionCountViewResponse
+            var result = new TagQuestionCountViewResponse
             {
-                TotalCount = 0
+                TotalCount = taqQuestions != null ? taqQuestions.Count() : 0
             };
+
+            return result;
         }
 
         #endregion

+ 6 - 4
src/Hotline.Share/Dtos/Questions/QuestionDto.cs

@@ -44,7 +44,7 @@ namespace Hotline.Share.Dtos.Questions
     }
 
 
-    public class AddQuestionDto:IAddRequest
+    public class AddQuestionDto : IAddRequest
     {
         /// <summary>
         /// 题干
@@ -120,7 +120,7 @@ namespace Hotline.Share.Dtos.Questions
         public List<AddQuestionKnowladgeDto> QuestionKnowladgeDtos { get; set; }
     }
 
-    public class UpdateQuestionDto:AddQuestionDto, IActionRequest
+    public class UpdateQuestionDto : AddQuestionDto, IActionRequest
     {
         /// <summary>
         /// 主键
@@ -138,7 +138,7 @@ namespace Hotline.Share.Dtos.Questions
         /// 参考答案
         /// </summary>
         [Description("参考答案")]
-        public new  UpdateQuestionAnswerDto QuestionAnswerDto { get; set; }
+        public new UpdateQuestionAnswerDto QuestionAnswerDto { get; set; }
 
         /// <summary>
         /// 试题选项
@@ -168,7 +168,7 @@ namespace Hotline.Share.Dtos.Questions
         /// 主键
         /// </summary>
         [Description("主键")]
-        public string Id { get ; set ; }
+        public string Id { get; set; }
 
         /// <summary>
         /// 题干
@@ -191,4 +191,6 @@ namespace Hotline.Share.Dtos.Questions
         [Description("知识题目")]
         public string Title { get; set; }
     }
+
+  
 }

+ 1 - 1
src/Hotline.Share/Dtos/TestPapers/TagQuestionDto.cs

@@ -63,7 +63,7 @@ namespace Hotline.Share.Dtos.TestPapers
         /// 试题数量
         /// </summary>
         [Description("试题数量")]
-        public int Count { get; set; }
+        public int? Count { get; set; }
 
         /// <summary>
         /// 操作状态        

+ 113 - 0
src/Hotline/Exams/Questions/QuestionExcel.cs

@@ -0,0 +1,113 @@
+using Hotline.Share.Enums.Exams;
+using MiniExcelLibs.Attributes;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Exams.Questions
+{
+    public class QuestionExcel
+    {
+        /// <summary>
+        /// 题干
+        /// </summary>
+        [ExcelColumnName("题干")]
+        public string Title { get; set; }
+
+        /// <summary>
+        /// 试题类型
+        /// </summary>
+        [ExcelColumnName("试题类型")]
+        public EQuestionType QuestionType { get; set; }
+
+        /// <summary>
+        /// 难易程度
+        /// </summary>
+        [ExcelColumnName("难易程度")]
+        public EDifficultyLevel DifficultyLevel { get; set; }
+
+        /// <summary>
+        /// 正式可用
+        /// </summary>
+        [ExcelColumnName("正式可用")]
+        public bool FormalEnable { get; set; }
+
+        /// <summary>
+        /// 模拟可用
+        /// </summary>
+        [ExcelColumnName("模拟可用")]
+
+        public bool SimulateEnable { get; set; }
+
+        /// <summary>
+        /// 选项A
+        /// </summary>
+        [ExcelColumnName("选项A")]
+        public string OptionsA { get; set; }
+
+        /// <summary>
+        /// 选项B
+        /// </summary>
+        [ExcelColumnName("选项B")]
+        public string OptionsB { get; set; }
+
+        /// <summary>
+        /// 选项C
+        /// </summary>
+        [ExcelColumnName("选项C")]
+        public string OptionsC { get; set; }
+
+        /// <summary>
+        /// 选项D
+        /// </summary>
+        [ExcelColumnName("选项D")]
+        public string OptionsD { get; set; }
+
+        /// <summary>
+        /// 选项E
+        /// </summary>
+        [ExcelColumnName("选项E")]
+        public string OptionsE { get; set; }
+
+        /// <summary>
+        /// 选项F
+        /// </summary>
+        [ExcelColumnName("选项F")]
+        public string OptionsF { get; set; }
+
+        /// <summary>
+        /// 选项G
+        /// </summary>
+        [ExcelColumnName("选项G")]
+        public string OptionsG { get; set; }
+
+        /// <summary>
+        /// 选项H
+        /// </summary>
+        [ExcelColumnName("选项H")]
+        public string OptionsH { get; set; }
+
+        /// <summary>
+        /// 选项I
+        /// </summary>
+        [ExcelColumnName("选项I")]
+        public string OptionsI { get; set; }
+
+        /// <summary>
+        /// 选项J
+        /// </summary>
+        [ExcelColumnName("选项J")]
+        public string OptionsJ { get; set; }
+
+        /// <summary>
+        /// 答案
+        /// </summary>
+        [ExcelColumnName("答案")]
+
+        public string Answer { get; set; }
+
+    }
+}

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/AddTagQuestionDtoValidator.cs

@@ -11,7 +11,7 @@ namespace Hotline.Validators.Exams.ExamManages
         public AddTagQuestionDtoValidator()
         {
             RuleFor(m => m.QuestionType).NotNull().WithMessage(x=>string.Format(ExamErrorMessage.IsRequired,x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
-            RuleFor(m=>m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
+            //RuleFor(m=>m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
             RuleFor(m => m.TagId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(ExamTag).GetDescription()));
         }
     }

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/UpdateExamTagDtoValidator.cs

@@ -16,7 +16,7 @@ namespace Hotline.Validators.Exams
     {
         public UpdateExamTagDtoValidator()
         {
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTag.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTag.Id))));
             RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTag.Name))));
 
         }

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/UpdateExtractRuleDtoValidator.cs

@@ -10,7 +10,7 @@ namespace Hotline.Validators.Exams.ExamManages
         public UpdateExtractRuleDtoValidator()
         {
 
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.Id))));
 
             RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.Name))));
             RuleFor(m => m.RuleType).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExtractRuleDto.RuleType))));

+ 1 - 1
src/Hotline/Validators/Exams/ExamManages/UpdateTagQuestionDtoValidator.cs

@@ -12,7 +12,7 @@ namespace Hotline.Validators.Exams.ExamManages
         public UpdateTagQuestionDtoValidator()
         {
             RuleFor(m => m.QuestionType).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.QuestionType))));
-            RuleFor(m => m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
+            //RuleFor(m => m.Count).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamTagQuestion.Count))));
             RuleFor(m => m.TagId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(ExamTag).GetDescription()));
         }
     }

+ 1 - 1
src/Hotline/Validators/Exams/Questions/UpdateQuestionDtoValidator.cs

@@ -11,7 +11,7 @@ namespace Hotline.Validators.Exams
     {
         public UpdateQuestionDtoValidator()
         {
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Id))));
             RuleFor(m => m.Title).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Title))));
             RuleFor(m => m.DifficultyLevel).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.DifficultyLevel))));
             RuleFor(m => m.FormalEnable).NotNull().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.FormalEnable))));

+ 1 - 1
src/Hotline/Validators/Exams/Questions/UpdateQuestionKnowladgeDtoValidator.cs

@@ -11,7 +11,7 @@ namespace Hotline.Validators.Exams
         public UpdateQuestionKnowladgeDtoValidator()
         {
             RuleFor(m => m.KnowladgeId).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, typeof(Hotline.KnowledgeBase.Knowledge).GetDescription()));
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamQuestion.Id))));
         }
     }
 }

+ 1 - 1
src/Hotline/Validators/Exams/Sourcewares/UpdateSourceCategoryDtoValidator.cs

@@ -15,7 +15,7 @@ namespace Hotline.Validators.Exams
     {
         public UpdateSourceCategoryDtoValidator()
         {
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourcewareCategory.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourcewareCategory.Id))));
             RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourcewareCategory.Name))));
         }
     }

+ 1 - 1
src/Hotline/Validators/Exams/Sourcewares/UpdateSourcewareDtoValidator.cs

@@ -10,7 +10,7 @@ namespace Hotline.Validators.Exams
     {
         public UpdateSourcewareDtoValidator()
         {
-            RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourceware.Id))));
+            //RuleFor(m => m.Id).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourceware.Id))));
             RuleFor(m => m.Name).NotEmpty().WithMessage(x => string.Format(ExamErrorMessage.IsRequired, x.GetType().GetDescription(nameof(ExamSourceware.Name))));
         }
     }