瀏覽代碼

调整获取试题方法

guqiang 1 月之前
父節點
當前提交
d147469cc5
共有 1 個文件被更改,包括 6 次插入6 次删除
  1. 6 6
      src/Hotline.Application/Exam/Service/TestPapers/TestPaperService.cs

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

@@ -332,8 +332,8 @@ namespace Hotline.Application.Exam.Service.TestPapers
             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).ToListAsync();
+            .WhereIF(testPaperQuestionRequest.TagIds.IsNotNull() && testPaperQuestionRequest.TagIds.Any(), (q, qt) => testPaperQuestionRequest.TagIds.Contains(qt.TagId))
+                .Select((q, qt) => q).Take(testPaperQuestionRequest.Count).OrderBy(q => SqlFunc.GetRandom()).ToListAsync();
 
             var questionDtos = new List<SimpleQuestionViewResponse>();
 
@@ -360,11 +360,11 @@ namespace Hotline.Application.Exam.Service.TestPapers
 
             var count = await testPaperRuleTable.Select(x => x.Count).FirstAsync();
 
-            var questions = await questionTable.InnerJoin(questionTagTable, (q, qt) => q.Id == qt.QuestionId)
-                .InnerJoin(testPaperTagTable, (q, qt, tt) => qt.TagId == tt.TagId)
-                .InnerJoin(testPaperRuleTable, (q, qt, tt, tpr) => tt.TestPaperRuleId == tpr.Id)
+            var questions = await questionTable.LeftJoin(questionTagTable, (q, qt) => q.Id == qt.QuestionId)
+                .LeftJoin(testPaperTagTable, (q, qt, tt) => qt.TagId == tt.TagId)
+                .LeftJoin(testPaperRuleTable, (q, qt, tt, tpr) => tt.TestPaperRuleId == tpr.Id)
                 .Where((q, qt, tt, tpr) => q.QuestionType == tpr.QuestionType)
-                .Select((q, qt, tt, tpr) => q).Take(count).OrderBy(SqlFunc.GetRandom()).ToListAsync();
+                .Select((q, qt, tt, tpr) => q).Take(count).OrderBy(q => SqlFunc.GetRandom()).ToListAsync();
 
 
             return questions;