Browse Source

调整试题数量接口

guqiang 1 month ago
parent
commit
97891caaac

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

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

+ 3 - 3
src/Hotline.Share/ViewResponses/Exam/TagQuestionViewResponse.cs

@@ -11,16 +11,16 @@ namespace Hotline.Share.ViewResponses.Exam
         /// </summary>
         /// </summary>
         [Description("试题类型")]
         [Description("试题类型")]
         public EQuestionType QuestionType { get; set; }
         public EQuestionType QuestionType { get; set; }
-    }
 
 
-    public class TagQuestionCountViewResponse : IViewResponse
-    {
         /// <summary>
         /// <summary>
         /// 标签Id
         /// 标签Id
         /// </summary>
         /// </summary>
         [Description("标签Id")]
         [Description("标签Id")]
         public string TagId { get; set; }
         public string TagId { get; set; }
+    }
 
 
+    public class TagQuestionCountViewResponse : IViewResponse
+    {
         /// <summary>
         /// <summary>
         /// 总数
         /// 总数
         /// </summary>
         /// </summary>