Bläddra i källkod

调整试题获取接口

guqiang 1 månad sedan
förälder
incheckning
73464c9082
1 ändrade filer med 7 tillägg och 4 borttagningar
  1. 7 4
      src/Hotline.Application/Exam/Service/TestPapers/TestPaperService.cs

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

@@ -329,18 +329,21 @@ namespace Hotline.Application.Exam.Service.TestPapers
             var questionTagTable = questionTagRepository.Queryable();
             var questionTable = questionRepository.Queryable();
 
-            var questions = await questionTable.InnerJoin(questionTagTable, (q, qt) => q.Id == qt.QuestionId)
-                .Where((q, qt) => q.DifficultyLevel == testPaperQuestionRequest.DifficultyLevel
-            && q.QuestionType == testPaperQuestionRequest.QuestionType
+            var questions = await questionTable.LeftJoin(questionTagTable, (q, qt) => q.Id == qt.QuestionId)
+                .Where((q, qt) => q.QuestionType == testPaperQuestionRequest.QuestionType
             ).WhereIF(testPaperQuestionRequest.DifficultyLevel.IsNotNull(), (q, qt) => q.DifficultyLevel == testPaperQuestionRequest.DifficultyLevel)
             .WhereIF(testPaperQuestionRequest.TagIds.IsNotNull(), (q, qt) => testPaperQuestionRequest.TagIds.Contains(qt.TagId))
-                .Select((q, qt) => q).Take(testPaperQuestionRequest.Count).OrderBy(SqlFunc.GetRandom()).ToListAsync();
+                .Select((q, qt) => q).Take(testPaperQuestionRequest.Count).ToListAsync();
 
             var questionDtos = new List<SimpleQuestionViewResponse>();
 
             questions.ForEach(item =>
             {
                 var questionDto = _mapper.Map<SimpleQuestionViewResponse>(item);
+                if (questionDto != null)
+                {
+                    questionDtos.Add(questionDto);
+                }
             });
 
             return questionDtos;