|
@@ -12,7 +12,9 @@ using Exam.Share.ViewResponses.Exam;
|
|
|
using Exam.Share.ViewResponses.Practices;
|
|
|
using Exam.TestPapers;
|
|
|
using Exam.Trains;
|
|
|
+using Hotline.Application.Exam.Core.Constants;
|
|
|
using Hotline.Application.Exam.Core.Extensions;
|
|
|
+using Hotline.Application.Exam.Core.Utilities;
|
|
|
using Hotline.Application.Exam.QueryExtensions.Practices;
|
|
|
using Hotline.Exams.Practices;
|
|
|
using Hotline.Exams.Sourcewares;
|
|
@@ -118,12 +120,14 @@ namespace Hotline.Application.Exam.Service.Practices
|
|
|
{
|
|
|
var questions = await ExactractQuestion(actionRequest);
|
|
|
base.StartTran();
|
|
|
+ actionRequest.Code = await GenerateCode(BusiConstants.PracticeCode,3);
|
|
|
var id = await base.AddAsync(actionRequest, cancellationToken);
|
|
|
var addPracticeQuestionDtos = new List<AddPracticeQuestionDto>();
|
|
|
questions.ForEach(item =>
|
|
|
{
|
|
|
var addPracticeQuestionDto = _mapper.Map<AddPracticeQuestionDto>(item);
|
|
|
addPracticeQuestionDto.PracticeId = id;
|
|
|
+ addPracticeQuestionDto.QuestionId = item.Id;
|
|
|
addPracticeQuestionDtos.Add(addPracticeQuestionDto);
|
|
|
});
|
|
|
|
|
@@ -319,12 +323,35 @@ namespace Hotline.Application.Exam.Service.Practices
|
|
|
|
|
|
practiceQuestionDto.PracticeQuestionOptionsDtos = await GetPracticeQuestionOptions(practiceQuestionRequest);
|
|
|
|
|
|
+ var practiceResultItems = await GetPracticeResultItems(practiceQuestionRequest);
|
|
|
+
|
|
|
+ if (practiceResultItems != null)
|
|
|
+ {
|
|
|
+ practiceQuestionDto.PracticeQuestionOptionsDtos.ForEach(item =>
|
|
|
+ {
|
|
|
+ item.IsSelected = practiceResultItems.Any(x => x.QuestionOptionId == item.QuestionOptionId);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
practiceQuestionDto.PracticeQuestionSourcewareDtos = await GetPracticeQuestionSourceware(practiceQuestionRequest);
|
|
|
|
|
|
practiceQuestionDto.PracticeQuestionKnowladgeDtos = await GetPracticeQuestionKnowladge(practiceQuestionRequest);
|
|
|
return practiceQuestionDto;
|
|
|
}
|
|
|
|
|
|
+ private async Task<List<PracticeResultItem>> GetPracticeResultItems(PracticeQuestionRequest practiceQuestionRequest)
|
|
|
+ {
|
|
|
+ var practiceRecordRepository = new ExamRepository<PracticeRecord>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var practiceRecordTable = practiceRecordRepository.Queryable().Where(x=>x.UserId == _sessionContext.UserId);
|
|
|
+
|
|
|
+ var practiceResultItems = practiceRecordTable.InnerJoin<PracticeResult>((p, r) => p.Id == r.PracticeRecordId)
|
|
|
+ .InnerJoin<PracticeResultItem>((p, r, i) => i.PracticeResultId == r.Id)
|
|
|
+ .Where((p, r, i) => r.PracticeQuestionId == practiceQuestionRequest.PracticeQuestionId)
|
|
|
+ .Select((p, r, i) => i);
|
|
|
+
|
|
|
+ return await practiceResultItems.ToListAsync();
|
|
|
+ }
|
|
|
+
|
|
|
private async Task<List<PracticeQuestionKnowladgeDto>> GetPracticeQuestionKnowladge(PracticeQuestionRequest practiceQuestionRequest)
|
|
|
{
|
|
|
var knowledgeRepository = new ExamRepository<KnowledgeBase.Knowledge>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
@@ -494,6 +521,8 @@ namespace Hotline.Application.Exam.Service.Practices
|
|
|
|
|
|
practiceQuestionOption.PracticeQuestionId = practiceQuestion?.Id;
|
|
|
|
|
|
+ practiceQuestionOption.QuestionOptionId = item.Id;
|
|
|
+
|
|
|
practiceQuestionOption.ToInsert(_sessionContext);
|
|
|
|
|
|
practiceQuestionOptions.Add(practiceQuestionOption);
|
|
@@ -567,17 +596,24 @@ namespace Hotline.Application.Exam.Service.Practices
|
|
|
else
|
|
|
{
|
|
|
var unionQuestions = new List<ISugarQueryable<QuestionTag>>();
|
|
|
+ var ids = new List<string>();
|
|
|
// 保证每个标签至少获取一道题
|
|
|
tagIds.ForEach(v =>
|
|
|
{
|
|
|
- var unionQuestion = questionTagTable.Where(x => x.TagId == v).Take(1);
|
|
|
+ var unionQuestion = questionTagTable;
|
|
|
+ unionQuestion= unionQuestion.Where(x => x.TagId == v).Take(1);
|
|
|
+ ids.Add(questionTagRepostiory.Queryable().Where(x => x.TagId == v).Select(x => x.Id).First());
|
|
|
unionQuestions.Add(unionQuestion);
|
|
|
+ questionTagTable = questionTagRepostiory.Queryable();
|
|
|
});
|
|
|
- questionTagTable = questionTagTable.Where(x => tagIds.Contains(x.TagId)).Take(tagIds.Count - actionRequest.Count);
|
|
|
|
|
|
- unionQuestions.Add(questionTagTable);
|
|
|
+ var mainQuesiton = questionTagTable;
|
|
|
+ mainQuesiton = mainQuesiton.Where(x => tagIds.Contains(x.TagId) && !ids.Contains(x.Id)).Take(actionRequest.Count - tagIds.Count);
|
|
|
|
|
|
- questionTagTable = questionTagRepostiory.UnionAll(unionQuestions.ToArray()).MergeTable();
|
|
|
+ unionQuestions.Add(mainQuesiton);
|
|
|
+
|
|
|
+ questionTagTable = questionTagRepostiory.Queryable();
|
|
|
+ questionTagTable = questionTagRepostiory.UnionAll(unionQuestions.ToArray());
|
|
|
}
|
|
|
|
|
|
var queryResult = questionTagTable.InnerJoin(questionTable, (t, q) => t.QuestionId == q.Id)
|
|
@@ -586,6 +622,20 @@ namespace Hotline.Application.Exam.Service.Practices
|
|
|
return await queryResult.ToListAsync();
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ private async Task<string> GenerateCode(string codePrefix, int length)
|
|
|
+ {
|
|
|
+ var trainPlan = await _repository.Queryable().Where(x => x.CreationTime.Date == DateTime.Now.Date).OrderByDescending(x => x.CreationTime).FirstAsync();
|
|
|
+
|
|
|
+
|
|
|
+ var code = string.Empty;
|
|
|
+ if (trainPlan != null)
|
|
|
+ {
|
|
|
+ code = trainPlan.Code;
|
|
|
+ }
|
|
|
+ code = CodeUtility.GenerateCode(codePrefix, length, code);
|
|
|
+ return code;
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
#region protect method
|