|
@@ -46,6 +46,8 @@ using Hotline.Exams.Questions;
|
|
|
using Hotline.Exams.Sourcewares;
|
|
|
using Hotline.Share.Dtos.Questions;
|
|
|
using DocumentFormat.OpenXml.Office2010.Excel;
|
|
|
+using System.Linq.Expressions;
|
|
|
+using Microsoft.EntityFrameworkCore.Query.SqlExpressions;
|
|
|
|
|
|
namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
@@ -359,7 +361,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
IsJoin = false
|
|
|
};
|
|
|
|
|
|
- if (userExam.StartTime == null || userExam.ExamStatus == EExamStatus.Complete)
|
|
|
+ if (userExam.ExamStatus == EExamStatus.NoStart || userExam.ExamStatus == EExamStatus.Complete)
|
|
|
userExam.StartTime = DateTime.Now;
|
|
|
|
|
|
var startExamViewResponse = await CheckExamValid(userExam, cancellationToken);
|
|
@@ -618,6 +620,35 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
public async Task<List<GradingExamQuestionDto>> GetGradingExamQuestion(GradingExamRequest gradingExamRequest)
|
|
|
{
|
|
|
var expression = gradingExamRequest.GetExpression();
|
|
|
+
|
|
|
+ ISugarQueryable<GradingExamQuestionTempDto> queryable = GetViewExamQuestionTempDtos(expression);
|
|
|
+
|
|
|
+ queryable =
|
|
|
+ queryable.MergeTable().Where((q) => !(q.QuestionType == EQuestionType.Single || q.QuestionType == EQuestionType.Multi || q.QuestionType == EQuestionType.Judge));
|
|
|
+
|
|
|
+ var queryResult = await queryable.ToListAsync();
|
|
|
+
|
|
|
+ var gradingExamQuestionDtos = queryResult.GroupBy(x => new
|
|
|
+ {
|
|
|
+ Id = x.Id,
|
|
|
+ QuestionType = x.QuestionType
|
|
|
+ }).Select(g => new GradingExamQuestionDto
|
|
|
+ {
|
|
|
+ Answer = g.FirstOrDefault().Answer,
|
|
|
+ QuestionType = g.Key.QuestionType,
|
|
|
+ Id = g.Key.Id,
|
|
|
+ QuestionScore = g.FirstOrDefault().QuestionScore,
|
|
|
+ Score = 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
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ return gradingExamQuestionDtos;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ISugarQueryable<GradingExamQuestionTempDto> GetViewExamQuestionTempDtos(Expression<Func<ExamUserExam,bool>> expression)
|
|
|
+ {
|
|
|
+
|
|
|
var userExamTable = _repository.Queryable().Where(expression);
|
|
|
|
|
|
var questionScoreRepository = new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
@@ -630,14 +661,13 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var testPaperItemAnswerTable = new ExamRepository<ExamQuestionAnswerBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
var questionScoreTable = questionScoreRepository.Queryable();
|
|
|
|
|
|
- var queryable = userExamTable.InnerJoin(userExamItemTable, (e, i) => e.Id == i.UserExamId)
|
|
|
+ return userExamTable.InnerJoin(userExamItemTable, (e, i) => e.Id == i.UserExamId)
|
|
|
.InnerJoin(questionTable, (e, i, q) => i.QuestionId == q.QuestionId)
|
|
|
.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)
|
|
|
.LeftJoin(testPaperItemAnswerTable, (e, i, q, o, qo, a, ta) => ta.QuestionId == q.QuestionId)
|
|
|
.InnerJoin(questionScoreTable, (e, i, q, o, qo, a, ta, s) => q.QuestionType == s.QuestionType && e.ExamId == s.ExamManageId)
|
|
|
- .Where((e, i, q, o, qo, a, ta, s) => !(q.QuestionType == EQuestionType.Single || q.QuestionType == EQuestionType.Multi || q.QuestionType == EQuestionType.Judge))
|
|
|
.Select(
|
|
|
(e, i, q, o, qo, a, ta, s) => new GradingExamQuestionTempDto
|
|
|
{
|
|
@@ -647,6 +677,8 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
Answer = a.Id != null ? a.Answer : string.Empty,
|
|
|
Title = q.Title,
|
|
|
QuestionOptionId = o.Id,
|
|
|
+ QuestionId = q.QuestionId,
|
|
|
+ ExamQuestionId = q.Id,
|
|
|
UserExamItemId = i.Id,
|
|
|
Content = qo.Content,
|
|
|
Label = qo.Label,
|
|
@@ -656,28 +688,8 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
Score = i.Score
|
|
|
}
|
|
|
);
|
|
|
-
|
|
|
- var queryResult = await queryable.ToListAsync();
|
|
|
-
|
|
|
- var gradingExamQuestionDtos = queryResult.GroupBy(x => new
|
|
|
- {
|
|
|
- Id = x.Id,
|
|
|
- QuestionType = x.QuestionType
|
|
|
- }).Select(g => new GradingExamQuestionDto
|
|
|
- {
|
|
|
- Answer = g.FirstOrDefault().Answer,
|
|
|
- QuestionType = g.Key.QuestionType,
|
|
|
- Id = g.Key.Id,
|
|
|
- QuestionScore = g.FirstOrDefault().QuestionScore,
|
|
|
- Score = 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
|
|
|
- }).ToList();
|
|
|
-
|
|
|
- return gradingExamQuestionDtos;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public async Task<GradingExamQuestionDto> ViewGradingExamQuestion(ViewGradingExamRequest viewGradingExamRequest)
|
|
|
{
|
|
|
var gradingExtamItemDto = _mapper.Map<ViewGradingExamRequest, GradingExamItemDto>(viewGradingExamRequest);
|
|
@@ -835,6 +847,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
QuestionId = u.QuestionId,
|
|
|
QuestionType = q.QuestionType,
|
|
|
UserExamId = u.UserExamId,
|
|
|
+ Id = u.Id
|
|
|
}).Distinct().ToListAsync();
|
|
|
await CalcuteExamItemScore(_userExamItemRepository, userExamItemsInCheck, cancellationToken);
|
|
|
|
|
@@ -899,31 +912,36 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var userExamIds = addUserExamItemDtos.Select(x => x.UserExamId).ToList();
|
|
|
var questionTypes = addUserExamItemDtos.Select(x => x.QuestionType).ToList();
|
|
|
|
|
|
- var testPaperItemOptionsRepository = new ExamRepository<ExamQuestionOptionsBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var examQuestionOptionsRepository = new ExamRepository<ExamQuestionOptionsBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var userExamItemOptionRepository = new ExamRepository<ExamUserExamItemOptions>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var testPaperItemRepository = new ExamRepository<Exams.ExamManages.ExamQuestionBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var questionRepository = new ExamRepository<Exams.ExamManages.ExamQuestionBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var examQuestionScoreRepository = new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var testPaperOptionsTable = testPaperItemOptionsRepository.Queryable().Where(x => questionIds.Contains(x.QuestionId) && x.IsAnswer);
|
|
|
- var testPaperItemTable = testPaperItemRepository.Queryable().Where(x => x.QuestionType == EQuestionType.Single || x.QuestionType == EQuestionType.Multi || x.QuestionType == EQuestionType.Judge);
|
|
|
+ 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 testPaperOptionIds = await testPaperOptionsTable.InnerJoin(testPaperItemTable, (t, i) => t.ExamQuestionId == i.Id)
|
|
|
+ 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) => t.Id).ToListAsync();
|
|
|
+ .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();
|
|
|
var userExamItemOptions = await userExamItemOptionRepository.Queryable().Where(x => userExamItemIds.Contains(x.UserExamItemId)).ToListAsync();
|
|
|
var examQuesiontScores = await examQuestionScoreRepository.Queryable().Where(x => questionTypes.Contains(x.QuestionType))
|
|
|
- .InnerJoin(userExamTable, (e, u) => e.Id == u.ExamId)
|
|
|
+ .InnerJoin(userExamTable, (e, u) => e.ExamManageId == u.ExamId)
|
|
|
.Select((e, u) => e).ToListAsync();
|
|
|
|
|
|
|
|
|
foreach (var addUserExamItemDto in addUserExamItemDtos)
|
|
|
{
|
|
|
- var isCorrect = userExamItemOptions.Select(x => x.QuestionOptionId).OrderBy(x => x).SequenceEqual(testPaperOptionIds.OrderBy(x => x));
|
|
|
+ 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 userExamItem = userExamItems.FirstOrDefault(x => x.QuestionId == addUserExamItemDto.QuestionId);
|
|
|
if (userExamItem != null)
|
|
|
{
|
|
@@ -1329,7 +1347,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
var questionIds = viewExamQuestionDtos.Select(x => x.QuestionId).ToList();
|
|
|
|
|
|
- List<ViewQuestionAnswerDto> questionAnswers = await GetQuestionAnswers(id, questionIds);
|
|
|
+ //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);
|
|
@@ -1338,18 +1356,10 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
|
item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- if (!item.QuestionType.CheckSelectType())
|
|
|
- {
|
|
|
- var questionAnswer = questionAnswers.FirstOrDefault(x => x.QuestionId == item.QuestionId);
|
|
|
- item.Answer = questionAnswer?.Answer ?? string.Empty;
|
|
|
- item.CorrectAnswer = questionAnswer?.CorrectAnswer ?? string.Empty;
|
|
|
- }
|
|
|
- else
|
|
|
+ if (item.QuestionType.CheckSelectType())
|
|
|
{
|
|
|
item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.CorrectAnswer = string.Join(",", item.QuestionOptions.Where(x => x.IsAnswer).Select(x => x.Label));
|
|
|
}
|
|
|
-
|
|
|
});
|
|
|
|
|
|
|
|
@@ -1365,7 +1375,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
var questionIds = viewExamQuestionDtos.Select(x => x.QuestionId).ToList();
|
|
|
|
|
|
- List<ViewQuestionAnswerDto> questionAnswers = await GetQuestionAnswers(id, questionIds);
|
|
|
+ //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);
|
|
@@ -1374,16 +1384,9 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
|
item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- if (!item.QuestionType.CheckSelectType())
|
|
|
- {
|
|
|
- var questionAnswer = questionAnswers.FirstOrDefault(x => x.QuestionId == item.QuestionId);
|
|
|
- item.Answer = questionAnswer?.Answer ?? string.Empty;
|
|
|
- item.CorrectAnswer = questionAnswer?.CorrectAnswer ?? string.Empty;
|
|
|
- }
|
|
|
- else
|
|
|
+ if (item.QuestionType.CheckSelectType())
|
|
|
{
|
|
|
item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.CorrectAnswer = string.Join(",", item.QuestionOptions.Where(x => x.IsAnswer).Select(x => x.Label));
|
|
|
}
|
|
|
|
|
|
});
|
|
@@ -1430,7 +1433,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
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)
|
|
|
+ .LeftJoin(userExamItemOptionTable, (op, uio) => op.Id == uio.QuestionOptionId )
|
|
|
.Select((op, uio) => new ViewQuestionOptionDto
|
|
|
{
|
|
|
Content = op.Content,
|
|
@@ -1470,28 +1473,32 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
private async Task<List<ViewExamQuestionDto>> GetViewExamQuestion(string id,string questionId)
|
|
|
{
|
|
|
- var userExamTable = _repository.Queryable().Where(x => x.Id == id);
|
|
|
- var userExamItemTable = _userExamItemRepository.Queryable();
|
|
|
- var examManageTable = _examManageRepository.Queryable();
|
|
|
- var questionTable = new ExamRepository<ExamQuestionBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable().WhereIF(!string.IsNullOrEmpty(questionId), x => x.QuestionId == questionId);
|
|
|
- var questionScoreTable = new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
+ var expression = ExpressionableUtility.CreateExpression<ExamUserExam>()
|
|
|
+ .And(x => x.Id == id).ToExpression();
|
|
|
|
|
|
+ ISugarQueryable<GradingExamQuestionTempDto> queryable = GetViewExamQuestionTempDtos(expression);
|
|
|
|
|
|
- var querable = userExamItemTable.InnerJoin(userExamTable, (ui, u) => ui.UserExamId == u.Id)
|
|
|
- .InnerJoin(questionTable, (ui, u, q) => ui.QuestionId == q.QuestionId && u.ExamId == q.ExamId)
|
|
|
- .InnerJoin(examManageTable, (ui, u, q, e) => u.ExamId == e.Id)
|
|
|
- .InnerJoin(questionScoreTable, (ui, u, q, e, s) => q.QuestionType == s.QuestionType && s.ExamManageId == e.Id)
|
|
|
- .Select((ui, u, q, e, s) => new ViewExamQuestionDto
|
|
|
- {
|
|
|
- Id = ui.Id,
|
|
|
- Score = s.Score,
|
|
|
- RealScore = ui.Score,
|
|
|
- Title = q.Title,
|
|
|
- QuestionType = q.QuestionType,
|
|
|
- QuestionId = q.Id,
|
|
|
- }).MergeTable().OrderBy(x=>x.QuestionType).OrderBy(x=>x.Id);
|
|
|
-
|
|
|
- return await querable.Distinct().ToListAsync();
|
|
|
+ queryable = queryable.MergeTable().WhereIF(!string.IsNullOrEmpty(questionId), x => x.QuestionId == questionId);
|
|
|
+
|
|
|
+ var queryResult = await queryable.ToListAsync();
|
|
|
+
|
|
|
+ var viewExamQuestion = queryResult.GroupBy(x => new
|
|
|
+ {
|
|
|
+ Id = x.Id,
|
|
|
+ QuestionType = x.QuestionType
|
|
|
+ }).Select(g => new ViewExamQuestionDto
|
|
|
+ {
|
|
|
+ Answer = g.FirstOrDefault().Answer,
|
|
|
+ QuestionType = g.Key.QuestionType,
|
|
|
+ QuestionId= 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
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ return viewExamQuestion;
|
|
|
}
|
|
|
#endregion
|
|
|
|