|
@@ -259,21 +259,18 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
/// <exception cref="NotImplementedException"></exception>
|
|
|
public async Task<List<TestPaperQuestionCountViewResponse>> GetTestPaperQuestionCount(TestPaperQuestionCountRequest testPaperQuestionCountRequest)
|
|
|
{
|
|
|
- var expression = testPaperQuestionCountRequest.GetTestPaperCountExpression();
|
|
|
- var testPaper = await _repository.Queryable().Where(expression).FirstAsync();
|
|
|
-
|
|
|
var testPaperQuestionCountViewResponses = new List<TestPaperQuestionCountViewResponse>();
|
|
|
- if (testPaper != null)
|
|
|
+
|
|
|
+
|
|
|
+ if (testPaperQuestionCountRequest.TestPaperId.IsNotNullOrEmpty())
|
|
|
{
|
|
|
- if(testPaper.Mode == Share.Enums.Exams.EExamMode.Random)
|
|
|
- {
|
|
|
- testPaperQuestionCountViewResponses = await CalcuteRandomQuestionCount(testPaperQuestionCountRequest);
|
|
|
- }
|
|
|
- else if(testPaper.Mode == Share.Enums.Exams.EExamMode.Manual)
|
|
|
- {
|
|
|
- testPaperQuestionCountViewResponses = await CalcuteManualQuestionCount(testPaperQuestionCountRequest);
|
|
|
- }
|
|
|
+ testPaperQuestionCountViewResponses = await CalcuteManualQuestionCount(testPaperQuestionCountRequest);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ testPaperQuestionCountViewResponses = await CalcuteRandomQuestionCount(testPaperQuestionCountRequest);
|
|
|
}
|
|
|
+
|
|
|
return testPaperQuestionCountViewResponses;
|
|
|
}
|
|
|
|
|
@@ -331,10 +328,11 @@ 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 && testPaperQuestionRequest.TagIds.Contains(qt.TagId)
|
|
|
- )
|
|
|
+ var questions = await questionTable.InnerJoin(questionTagTable, (q, qt) => q.Id == qt.QuestionId)
|
|
|
+ .Where((q, qt) => q.DifficultyLevel == testPaperQuestionRequest.DifficultyLevel
|
|
|
+ && 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();
|
|
|
|
|
|
var questionDtos = new List<QuestionDto>();
|
|
@@ -369,6 +367,31 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
}
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 获取标签试题数
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="tagQuestionCountRequest"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public async Task<TagQuestionCountViewResponse> GetTagQuestionCount(TagQuestionCountRequest tagQuestionCountRequest)
|
|
|
+ {
|
|
|
+ var expression = tagQuestionCountRequest.GetExpression();
|
|
|
+
|
|
|
+ var tagQuestionRepository = new ExamRepository<QuestionTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+
|
|
|
+ var tagQuestionTable = tagQuestionRepository.Queryable().Where(expression);
|
|
|
+
|
|
|
+ var taqQuestions = await tagQuestionTable.ToListAsync();
|
|
|
+
|
|
|
+ var result = taqQuestions.GroupBy(x => x.TagId).Select(m => new TagQuestionCountViewResponse
|
|
|
+ {
|
|
|
+ TagId = m.Key,
|
|
|
+ TotalCount = m.Count()
|
|
|
+ });
|
|
|
+
|
|
|
+ return result.FirstOrDefault();
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region private method
|
|
@@ -777,10 +800,21 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
private async Task<List<TestPaperQuestionCountViewResponse>> CalcuteRandomQuestionCount(TestPaperQuestionCountRequest testPaperQuestionCountRequest)
|
|
|
{
|
|
|
var testPaperQuestionCountViewResponses = new List<TestPaperQuestionCountViewResponse>();
|
|
|
+ var extractRuleRepository = new ExamRepository<ExtractRule>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var ruleTagRepository = new ExamRepository<RuleTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var tagQuestionRepository = new ExamRepository<TagQuestion>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+
|
|
|
+
|
|
|
+ var expression = testPaperQuestionCountRequest.GetExpression();
|
|
|
+ var exatractTable = extractRuleRepository.Queryable().Where(expression);
|
|
|
+ var ruleTagTable = ruleTagRepository.Queryable();
|
|
|
+ var tagQuestionTable = tagQuestionRepository.Queryable();
|
|
|
|
|
|
- var expression = testPaperQuestionCountRequest.GetTestPaperRuleExpression();
|
|
|
|
|
|
- var testPaperRules = await _testPaperRuleRepository.Queryable().Where(expression).ToListAsync();
|
|
|
+ var testPaperRules = await exatractTable.InnerJoin(ruleTagTable,(e,rt)=>e.Id == rt.RuleId)
|
|
|
+ .InnerJoin(tagQuestionTable,(e,rt,tq)=>rt.TagId == tq.TagId)
|
|
|
+ .Select((e,rt,tq)=>tq)
|
|
|
+ .ToListAsync();
|
|
|
|
|
|
if (testPaperRules != null)
|
|
|
{
|