|
@@ -18,6 +18,7 @@ using Hotline.Repository.SqlSugar.Extensions;
|
|
|
using Hotline.Share.Dtos.TestPapers;
|
|
|
using Hotline.Share.Requests.Exam;
|
|
|
using Hotline.Share.Tools;
|
|
|
+using Hotline.Share.ViewResponses.Exam;
|
|
|
using JiebaNet.Segmenter.Common;
|
|
|
using MapsterMapper;
|
|
|
using SqlSugar;
|
|
@@ -113,6 +114,12 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
return id;
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// 修改试卷
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="actionRequest"></param>
|
|
|
+ /// <param name="cancellationToken"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public override async Task UpdateAsync(UpdateTestPaperDto actionRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
await base.UpdateAsync(actionRequest, cancellationToken);
|
|
@@ -159,15 +166,29 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
await DeleteTestPaperRuleTags(tempEntityQueryRequest, cancellationToken);
|
|
|
}
|
|
|
|
|
|
- private async Task<List<TestPaperRuleTag>> GetTestPaperRuleTags(EntityQueryRequest entityQueryRequest)
|
|
|
+ /// <summary>
|
|
|
+ /// 获取试卷试题数量
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ /// <exception cref="NotImplementedException"></exception>
|
|
|
+ public async Task<List<TestPaperQuestionCountViewResponse>> GetTestPaperQuestionCount(TestPaperQuestionCountRequest testPaperQuestionCountRequest)
|
|
|
{
|
|
|
- var expression = entityQueryRequest.GetTestPaperRuleExpression();
|
|
|
- var testPageRuleTable = _testPaperRuleRepository.Queryable().Where(expression);
|
|
|
- var testPageRuleTagTable = _testPaperRuleTagRepository.Queryable();
|
|
|
+ var expression = testPaperQuestionCountRequest.GetTestPaperCountExpression();
|
|
|
+ var testPaper = await _repository.Queryable().Where(expression).FirstAsync();
|
|
|
|
|
|
- var query = testPageRuleTagTable.InnerJoin(testPageRuleTable, (t, r) => t.TestPaperRuleId == r.Id).Select((t,r) => t);
|
|
|
-
|
|
|
- return await query.ToListAsync();
|
|
|
+ var testPaperQuestionCountViewResponses = new List<TestPaperQuestionCountViewResponse>();
|
|
|
+ if (testPaper != null)
|
|
|
+ {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return testPaperQuestionCountViewResponses;
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
@@ -442,6 +463,57 @@ namespace Hotline.Application.Exam.Service.TestPapers
|
|
|
|
|
|
actionRequest.TestPaperItemDtos.ForEach(x => x.TestPaperId = id);
|
|
|
}
|
|
|
+
|
|
|
+ private async Task<List<TestPaperRuleTag>> GetTestPaperRuleTags(EntityQueryRequest entityQueryRequest)
|
|
|
+ {
|
|
|
+ var expression = entityQueryRequest.GetTestPaperRuleExpression();
|
|
|
+ var testPageRuleTable = _testPaperRuleRepository.Queryable().Where(expression);
|
|
|
+ var testPageRuleTagTable = _testPaperRuleTagRepository.Queryable();
|
|
|
+
|
|
|
+ var query = testPageRuleTagTable.InnerJoin(testPageRuleTable, (t, r) => t.TestPaperRuleId == r.Id).Select((t, r) => t);
|
|
|
+
|
|
|
+ return await query.ToListAsync();
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<List<TestPaperQuestionCountViewResponse>> CalcuteRandomQuestionCount(TestPaperQuestionCountRequest testPaperQuestionCountRequest)
|
|
|
+ {
|
|
|
+ var testPaperQuestionCountViewResponses = new List<TestPaperQuestionCountViewResponse>();
|
|
|
+
|
|
|
+ var expression = testPaperQuestionCountRequest.GetTestPaperRuleExpression();
|
|
|
+
|
|
|
+ var testPaperRules = await _testPaperRuleRepository.Queryable().Where(expression).ToListAsync();
|
|
|
+
|
|
|
+ if (testPaperRules != null)
|
|
|
+ {
|
|
|
+ testPaperRules.ForEach(x => testPaperQuestionCountViewResponses.Add(new TestPaperQuestionCountViewResponse
|
|
|
+ {
|
|
|
+ QuestionType = x.QuestionType,
|
|
|
+ Count = x.Count
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ return testPaperQuestionCountViewResponses;
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<List<TestPaperQuestionCountViewResponse>> CalcuteManualQuestionCount(TestPaperQuestionCountRequest testPaperQuestionCountRequest)
|
|
|
+ {
|
|
|
+ var testPaperQuestionCountViewResponses = new List<TestPaperQuestionCountViewResponse>();
|
|
|
+
|
|
|
+ var expression = testPaperQuestionCountRequest.GetTestPaperItemsExpression();
|
|
|
+
|
|
|
+ var testPaperItemTable = _testPaperItemRepository.Queryable().Where(expression);
|
|
|
+ var questionTable = new ExamRepository<Question>(_testPaperItemRepository.UOW, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
+
|
|
|
+ testPaperQuestionCountViewResponses = await testPaperItemTable.InnerJoin(questionTable, (t, q) => t.QuestionId == q.Id)
|
|
|
+ .GroupBy((t, q) => q.QuestionType).Select((t, q) => new TestPaperQuestionCountViewResponse
|
|
|
+ {
|
|
|
+ QuestionType = q.QuestionType,
|
|
|
+ Count = SqlFunc.AggregateCount(t.Id)
|
|
|
+ }).ToListAsync();
|
|
|
+
|
|
|
+
|
|
|
+ return testPaperQuestionCountViewResponses;
|
|
|
+ }
|
|
|
#endregion
|
|
|
}
|
|
|
}
|