|
@@ -662,7 +662,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var questionScoreTable = questionScoreRepository.Queryable();
|
|
|
|
|
|
return userExamTable.InnerJoin(userExamItemTable, (e, i) => e.Id == i.UserExamId)
|
|
|
- .InnerJoin(questionTable, (e, i, q) => i.QuestionId == q.QuestionId)
|
|
|
+ .InnerJoin(questionTable, (e, i, q) => i.QuestionId == q.QuestionId && q.ExamId == e.ExamId )
|
|
|
.LeftJoin(userExamItemOptionTable, (e, i, q, o) => i.Id == o.UserExamItemId)
|
|
|
.LeftJoin(quesitonOptionTable, (e, i, q, o, qo) => o.QuestionOptionId == qo.Id)
|
|
|
.LeftJoin(examAnswerTable, (e, i, q, o, qo, a) => i.Id == a.UserExamItemId)
|
|
@@ -912,23 +912,11 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var userExamIds = addUserExamItemDtos.Select(x => x.UserExamId).ToList();
|
|
|
var questionTypes = addUserExamItemDtos.Select(x => x.QuestionType).ToList();
|
|
|
|
|
|
- var examQuestionOptionsRepository = new ExamRepository<ExamQuestionOptionsBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ List<ExamQuestionOptionsBak> examQuestionOptions = await GetQuestionOptionBaks(questionIds, userExamIds,true).ToListAsync();
|
|
|
+
|
|
|
var userExamItemOptionRepository = new ExamRepository<ExamUserExamItemOptions>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var questionRepository = new ExamRepository<Exams.ExamManages.ExamQuestionBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var examQuestionScoreRepository = new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var examQuestionOptionsTable = examQuestionOptionsRepository.Queryable().Where(x => questionIds.Contains(x.QuestionId) && x.IsAnswer);
|
|
|
- var questionTable = questionRepository.Queryable().Where(x => x.QuestionType == EQuestionType.Single || x.QuestionType == EQuestionType.Multi || x.QuestionType == EQuestionType.Judge);
|
|
|
var userExamTable = _repository.Queryable().Where(x => userExamIds.Contains(x.Id));
|
|
|
- var examManageTable = examManageRepository.Queryable();
|
|
|
- var examQuestionOptions = await examQuestionOptionsTable.InnerJoin(questionTable, (t, i) => t.ExamQuestionId == i.Id)
|
|
|
- .InnerJoin(examManageTable, (t, i, e) => i.ExamId == e.Id)
|
|
|
- .InnerJoin(userExamTable, (t, i, e, u) => e.Id == u.ExamId)
|
|
|
- .Select((t, i, e, u) => new ExamQuestionOptions
|
|
|
- {
|
|
|
- Id = t.Id,
|
|
|
- QuestionId = t.QuestionId
|
|
|
- }).ToListAsync();
|
|
|
|
|
|
var userExamItems = await userExamItemRepository.Queryable().Where(x => userExamIds.Contains(x.UserExamId)).ToListAsync();
|
|
|
var userExamItemIds = userExamItems.Select(x => x.Id).ToList();
|
|
@@ -941,7 +929,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
foreach (var addUserExamItemDto in addUserExamItemDtos)
|
|
|
{
|
|
|
var examQuestionOptionIds = examQuestionOptions.Where(x => x.QuestionId == addUserExamItemDto.QuestionId).Select(x => x.Id).ToList();
|
|
|
- var isCorrect = userExamItemOptions.Where(x=>x.UserExamItemId == addUserExamItemDto.Id).Select(x => x.QuestionOptionId).OrderBy(x => x).SequenceEqual(examQuestionOptionIds.OrderBy(x => x));
|
|
|
+ var isCorrect = userExamItemOptions.Where(x => x.UserExamItemId == addUserExamItemDto.Id).Select(x => x.QuestionOptionId).OrderBy(x => x).SequenceEqual(examQuestionOptionIds.OrderBy(x => x));
|
|
|
var userExamItem = userExamItems.FirstOrDefault(x => x.QuestionId == addUserExamItemDto.QuestionId);
|
|
|
if (userExamItem != null)
|
|
|
{
|
|
@@ -955,6 +943,32 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
await userExamItemRepository.UpdateWithValidateAsync(userExamItems, cancellationToken);
|
|
|
}
|
|
|
|
|
|
+ private ISugarQueryable<ExamQuestionOptionsBak> GetQuestionOptionBaks(List<string> questionIds, List<string> userExamIds,bool isFilterAnswer)
|
|
|
+ {
|
|
|
+ var questionRepository = new ExamRepository<Exams.ExamManages.ExamQuestionBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var questionTable = questionRepository.Queryable().Where(x => x.QuestionType == EQuestionType.Single || x.QuestionType == EQuestionType.Multi || x.QuestionType == EQuestionType.Judge);
|
|
|
+ var userExamTable = _repository.Queryable().Where(x => userExamIds.Contains(x.Id));
|
|
|
+ var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var examManageTable = examManageRepository.Queryable();
|
|
|
+ var examQuestionOptionsRepository = new ExamRepository<ExamQuestionOptionsBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var examQuestionOptionsTable = examQuestionOptionsRepository.Queryable()
|
|
|
+ .Where(x => questionIds.Contains(x.QuestionId))
|
|
|
+ .WhereIF(isFilterAnswer,x=>x.IsAnswer);
|
|
|
+ var examQuestionOptions = examQuestionOptionsTable.InnerJoin(questionTable, (t, i) => t.ExamQuestionId == i.Id)
|
|
|
+ .InnerJoin(examManageTable, (t, i, e) => i.ExamId == e.Id)
|
|
|
+ .InnerJoin(userExamTable, (t, i, e, u) => e.Id == u.ExamId)
|
|
|
+ .Select((t, i, e, u) => new ExamQuestionOptionsBak
|
|
|
+ {
|
|
|
+ Id = t.Id,
|
|
|
+ Content = t.Content,
|
|
|
+ IsAnswer = t.IsAnswer,
|
|
|
+ Label = t.Label,
|
|
|
+ ExamQuestionId = t.ExamQuestionId,
|
|
|
+ QuestionId = t.QuestionId
|
|
|
+ });
|
|
|
+ return examQuestionOptions;
|
|
|
+ }
|
|
|
+
|
|
|
private async Task CalcuteTotalScore(IUserExamItemRepository userExamItemRepository, string userExamId, CancellationToken cancellationToken)
|
|
|
{
|
|
|
var userExam = await _repository.GetAsync(x => x.Id == userExamId);
|
|
@@ -1345,23 +1359,18 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
List<ViewExamQuestionDto> viewExamQuestionDtos = await GetViewExamQuestion(id,null);
|
|
|
|
|
|
+ var examQuestionIds = viewExamQuestionDtos.Select(x => x.ExamQuestionId).ToList();
|
|
|
var questionIds = viewExamQuestionDtos.Select(x => x.QuestionId).ToList();
|
|
|
-
|
|
|
- //List<ViewQuestionAnswerDto> questionAnswers = await GetQuestionAnswers(id, questionIds);
|
|
|
- List<ViewQuestionOptionDto> questionOptions = await GetQuestionOptions( questionIds);
|
|
|
- List<QuestionKnowladgeDto> questionKnowladges = await GetQuestionKnowladges( questionIds);
|
|
|
- List<QuestionSourcewareDto> sourcewares = await GetSourcewares(questionIds);
|
|
|
-
|
|
|
- viewExamQuestionDtos.ForEach(item =>
|
|
|
+ var userExamIds = new List<string>
|
|
|
{
|
|
|
- item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- if (item.QuestionType.CheckSelectType())
|
|
|
- {
|
|
|
- item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- }
|
|
|
- });
|
|
|
+ id
|
|
|
+ };
|
|
|
+ //List<ViewQuestionAnswerDto> questionAnswers = await GetQuestionAnswers(id, questionIds);
|
|
|
+ List<ViewQuestionOptionDto> questionOptions = await GetQuestionOptions(questionIds, userExamIds);
|
|
|
+ List<QuestionKnowladgeDto> questionKnowladges = await GetQuestionKnowladges(examQuestionIds);
|
|
|
+ List<QuestionSourcewareDto> sourcewares = await GetSourcewares(examQuestionIds);
|
|
|
|
|
|
+ ResolveExamQuestions(viewExamQuestionDtos, questionOptions, questionKnowladges, sourcewares);
|
|
|
|
|
|
return viewExamQuestionDtos;
|
|
|
|
|
@@ -1373,26 +1382,36 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
|
List<ViewExamQuestionDto> viewExamQuestionDtos = await GetViewExamQuestion(id, questionId);
|
|
|
|
|
|
+ var examQuestionIds = viewExamQuestionDtos.Select(x => x.ExamQuestionId).ToList();
|
|
|
var questionIds = viewExamQuestionDtos.Select(x => x.QuestionId).ToList();
|
|
|
-
|
|
|
+ var userExamIds = new List<string>
|
|
|
+ {
|
|
|
+ id
|
|
|
+ };
|
|
|
//List<ViewQuestionAnswerDto> questionAnswers = await GetQuestionAnswers(id, questionIds);
|
|
|
- List<ViewQuestionOptionDto> questionOptions = await GetQuestionOptions(questionIds);
|
|
|
- List<QuestionKnowladgeDto> questionKnowladges = await GetQuestionKnowladges(questionIds);
|
|
|
- List<QuestionSourcewareDto> sourcewares = await GetSourcewares(questionIds);
|
|
|
+ List<ViewQuestionOptionDto> questionOptions = await GetQuestionOptions(questionIds, userExamIds);
|
|
|
+ List<QuestionKnowladgeDto> questionKnowladges = await GetQuestionKnowladges(examQuestionIds);
|
|
|
+ List<QuestionSourcewareDto> sourcewares = await GetSourcewares(examQuestionIds);
|
|
|
+
|
|
|
+ ResolveExamQuestions(viewExamQuestionDtos, questionOptions, questionKnowladges, sourcewares);
|
|
|
+
|
|
|
+ return viewExamQuestionDtos.FirstOrDefault();
|
|
|
+ }
|
|
|
|
|
|
+ private static void ResolveExamQuestions(List<ViewExamQuestionDto> viewExamQuestionDtos, List<ViewQuestionOptionDto> questionOptions, List<QuestionKnowladgeDto> questionKnowladges, List<QuestionSourcewareDto> sourcewares)
|
|
|
+ {
|
|
|
viewExamQuestionDtos.ForEach(item =>
|
|
|
{
|
|
|
- item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
+ item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.ExamQuestionId).ToList();
|
|
|
+ item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.ExamQuestionId).ToList();
|
|
|
if (item.QuestionType.CheckSelectType())
|
|
|
{
|
|
|
- item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
+ item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.ExamQuestionId).ToList();
|
|
|
+
|
|
|
+ item.CorrectAnswer = string.Join(",", item.QuestionOptions.Where(m => m.IsAnswer).Select(m => m.Label).ToArray());
|
|
|
}
|
|
|
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
- return viewExamQuestionDtos.FirstOrDefault();
|
|
|
}
|
|
|
|
|
|
private async Task<List<QuestionSourcewareDto>> GetSourcewares(List<string> questionIds)
|
|
@@ -1427,13 +1446,14 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
}).ToListAsync();
|
|
|
}
|
|
|
|
|
|
- private async Task<List<ViewQuestionOptionDto>> GetQuestionOptions(List<string> questionIds)
|
|
|
+ private async Task<List<ViewQuestionOptionDto>> GetQuestionOptions(List<string> questionIds,List<string> userExamIds)
|
|
|
{
|
|
|
+ var selectQuestionOptions = GetQuestionOptionBaks(questionIds, userExamIds,false).MergeTable();
|
|
|
+
|
|
|
var userExamItemOptionTable = _userExamItemOptionRepository.Queryable();
|
|
|
- var questionOptionTable = new ExamRepository<ExamQuestionOptionsBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
|
|
|
- var querable = questionOptionTable.Where(x => questionIds.Contains(x.ExamQuestionId))
|
|
|
- .LeftJoin(userExamItemOptionTable, (op, uio) => op.Id == uio.QuestionOptionId )
|
|
|
+ var querable = selectQuestionOptions
|
|
|
+ .LeftJoin(userExamItemOptionTable, (op, uio) => op.Id == uio.QuestionOptionId)
|
|
|
.Select((op, uio) => new ViewQuestionOptionDto
|
|
|
{
|
|
|
Content = op.Content,
|
|
@@ -1442,7 +1462,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
Label = op.Label,
|
|
|
QuestionId = op.ExamQuestionId,
|
|
|
IsSelected = uio.Id != null
|
|
|
- }).MergeTable().OrderBy(x=>x.Label);
|
|
|
+ }).MergeTable().OrderBy(x => x.Label);
|
|
|
|
|
|
return await querable.Distinct()
|
|
|
.ToListAsync();
|
|
@@ -1490,12 +1510,13 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
|
Answer = g.FirstOrDefault().Answer,
|
|
|
QuestionType = g.Key.QuestionType,
|
|
|
- QuestionId= g.FirstOrDefault().ExamQuestionId,
|
|
|
+ QuestionId= g.FirstOrDefault().QuestionId,
|
|
|
+ ExamQuestionId = g.FirstOrDefault().ExamQuestionId,
|
|
|
Id = g.Key.Id,
|
|
|
Score = g.FirstOrDefault().QuestionScore,
|
|
|
RealScore = g.FirstOrDefault().Score,
|
|
|
Title = g.FirstOrDefault().Title,
|
|
|
- CorrectAnswer = g.Key.QuestionType.CheckSelectType() ? string.Join(",", g.Where(i => i.IsAnswer).Select(n => n.Label).Distinct()) : g.FirstOrDefault()?.CorrectAnswer
|
|
|
+ CorrectAnswer = g.Key.QuestionType.CheckSelectType() ? string.Empty : g.FirstOrDefault()?.CorrectAnswer
|
|
|
}).ToList();
|
|
|
|
|
|
return viewExamQuestion;
|