|
@@ -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
|
|
|
{
|
|
@@ -104,12 +106,12 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
|
var examQuestionDto = _mapper.Map<ExamQuestionDto>(question);
|
|
|
|
|
|
- var questionScore = await new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).GetAsync(x=>x.QuestionType == question.QuestionType && x.ExamManageId == question.ExamId);
|
|
|
+ var questionScore = await new ExamRepository<ExamQuestionScoreBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).GetAsync(x => x.QuestionType == question.QuestionType && x.ExamManageId == question.ExamId);
|
|
|
|
|
|
if (questionScore != null)
|
|
|
{
|
|
|
examQuestionDto.Score = questionScore.Score;
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
if (examQuestionDto.QuestionType.CheckSelectType())
|
|
|
{
|
|
@@ -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);
|
|
@@ -381,7 +383,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
}
|
|
|
// TODO: 删除之前选项和答案
|
|
|
- else if(userExam.ExamStatus == EExamStatus.Complete)
|
|
|
+ else if (userExam.ExamStatus == EExamStatus.Complete)
|
|
|
{
|
|
|
await ReExam(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)
|
|
|
- .InnerJoin(questionTable, (e, i, q) => i.QuestionId == q.QuestionId)
|
|
|
+ return userExamTable.InnerJoin(userExamItemTable, (e, i) => e.Id == i.UserExamId)
|
|
|
+ .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)
|
|
|
.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);
|
|
@@ -686,10 +698,37 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
}
|
|
|
|
|
|
|
|
|
- public async Task<UnExamUserPageViewResponse> GetUnExamUsers(UnExamUserReportPagedRequest unExamUserReportPagedRequest)
|
|
|
+ public async Task<UnExamUserPageViewResponse> GetUnExamUsersPaged(UnExamUserReportPagedRequest unExamUserReportPagedRequest)
|
|
|
{
|
|
|
- if(unExamUserReportPagedRequest.EndTime == null)
|
|
|
- unExamUserReportPagedRequest.ResolveEndTime();
|
|
|
+ ISugarQueryable<UnExamUserViewResponse> queryResult = GEtUnExamUserQueryable(unExamUserReportPagedRequest);
|
|
|
+
|
|
|
+ var total = await queryResult.CountAsync();
|
|
|
+
|
|
|
+ var items = unExamUserReportPagedRequest.IsPaged ?
|
|
|
+ await queryResult.ToPageListAsync(unExamUserReportPagedRequest.PageIndex, unExamUserReportPagedRequest.PageSize)
|
|
|
+ : await queryResult.ToListAsync();
|
|
|
+
|
|
|
+ return new UnExamUserPageViewResponse
|
|
|
+ {
|
|
|
+ Items = items,
|
|
|
+ Pagination = new Pagination(unExamUserReportPagedRequest.PageIndex, unExamUserReportPagedRequest.PageSize, total)
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public async Task<List<UnExamUserViewResponse>> GetUnExamUsers(UnExamUserReportPagedRequest unExamUserReportPagedRequest)
|
|
|
+ {
|
|
|
+ ISugarQueryable<UnExamUserViewResponse> queryResult = GEtUnExamUserQueryable(unExamUserReportPagedRequest);
|
|
|
+
|
|
|
+ var items = await queryResult.ToListAsync();
|
|
|
+
|
|
|
+ return items;
|
|
|
+ }
|
|
|
+
|
|
|
+ private ISugarQueryable<UnExamUserViewResponse> GEtUnExamUserQueryable(UnExamUserReportPagedRequest unExamUserReportPagedRequest)
|
|
|
+ {
|
|
|
+ if (unExamUserReportPagedRequest.EndTime == null)
|
|
|
+ unExamUserReportPagedRequest.ResolveEndTime();
|
|
|
|
|
|
var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var userRepository = new ExamRepository<User>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
@@ -707,23 +746,15 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
ExamName = e.Name,
|
|
|
OrgName = u.Organization.Name,
|
|
|
UserName = u.Name
|
|
|
- });
|
|
|
-
|
|
|
- var total = await queryResult.CountAsync();
|
|
|
- var items = await queryResult.ToPageListAsync(unExamUserReportPagedRequest.PageIndex, unExamUserReportPagedRequest.PageSize);
|
|
|
-
|
|
|
- return new UnExamUserPageViewResponse
|
|
|
- {
|
|
|
- Items = items,
|
|
|
- Pagination = new Pagination(unExamUserReportPagedRequest.PageIndex, unExamUserReportPagedRequest.PageSize, total)
|
|
|
- };
|
|
|
-
|
|
|
+ })
|
|
|
+ .MergeTable()
|
|
|
+ .OrderByPropertyNameIF(!string.IsNullOrEmpty(unExamUserReportPagedRequest.SortField), unExamUserReportPagedRequest.SortField, (OrderByType)(unExamUserReportPagedRequest.SortRule ?? 0));
|
|
|
+ return queryResult;
|
|
|
}
|
|
|
-
|
|
|
public async Task<UserExamResultPageViewResponse> GetUserExamResults(UserExamResultReportPagedRequest userExamResultReportPagedRequest)
|
|
|
{
|
|
|
- if(userExamResultReportPagedRequest.EndTime == null)
|
|
|
- userExamResultReportPagedRequest.ResolveEndTime();
|
|
|
+ if (userExamResultReportPagedRequest.EndTime == null)
|
|
|
+ userExamResultReportPagedRequest.ResolveEndTime();
|
|
|
|
|
|
var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var userRepository = new ExamRepository<User>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
@@ -736,21 +767,26 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
var queryResult = userExamTable.InnerJoin(examManageTable, (ue, e) => ue.ExamId == e.Id)
|
|
|
.InnerJoin(userTable, (ue, e, u) => ue.UserId == u.Id)
|
|
|
- .Select((ue, e, u) => new UserExamResultViewResponse
|
|
|
- {
|
|
|
- ExamName = e.Name,
|
|
|
- OrgName = u.Organization.Name,
|
|
|
- UserName = u.Name,
|
|
|
- TotalScore = e.TotalScore,
|
|
|
- CutoffScore = e.CutoffScore,
|
|
|
- Score = ue.Score ?? 0,
|
|
|
-
|
|
|
- })
|
|
|
+ .Select((ue, e, u) => new UserExamResultViewResponse
|
|
|
+ {
|
|
|
+ ExamName = e.Name,
|
|
|
+ OrgName = u.Organization.Name,
|
|
|
+ UserName = u.Name,
|
|
|
+ TotalScore = e.TotalScore,
|
|
|
+ CutoffScore = e.CutoffScore,
|
|
|
+ Score = ue.Score ?? 0,
|
|
|
+
|
|
|
+ })
|
|
|
.MergeTable()
|
|
|
- .OrderByDescending(x => x.Score);
|
|
|
-
|
|
|
+ .OrderByPropertyNameIF(!string.IsNullOrEmpty(userExamResultReportPagedRequest.SortField), userExamResultReportPagedRequest.SortField, (OrderByType)(userExamResultReportPagedRequest.SortRule ?? 0))
|
|
|
+ .OrderByDescending(x => x.Score)
|
|
|
+ ;
|
|
|
+
|
|
|
var total = await queryResult.CountAsync();
|
|
|
- var items = await queryResult.ToPageListAsync(userExamResultReportPagedRequest.PageIndex, userExamResultReportPagedRequest.PageSize);
|
|
|
+ var items = userExamResultReportPagedRequest.IsPaged ?
|
|
|
+ await queryResult.ToPageListAsync(userExamResultReportPagedRequest.PageIndex, userExamResultReportPagedRequest.PageSize)
|
|
|
+ : await queryResult.ToListAsync();
|
|
|
+ ;
|
|
|
|
|
|
return new UserExamResultPageViewResponse
|
|
|
{
|
|
@@ -835,6 +871,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 +936,24 @@ 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);
|
|
|
+ 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 testPaperItemRepository = 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 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)
|
|
|
- .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();
|
|
|
|
|
|
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)
|
|
|
{
|
|
@@ -937,6 +967,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);
|
|
@@ -1308,7 +1364,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
Score = u.Score ?? 0,
|
|
|
Status = u.Status,
|
|
|
SortIndex = u.SortIndex,
|
|
|
- ExamStatus = u.ExamStatus,
|
|
|
+ ExamStatus = u.ExamStatus == EExamStatus.Absent? EExamStatus.Complete: u.ExamStatus,
|
|
|
IsSuccess = u.IsCheck ? u.IsSuccess : null,
|
|
|
EndTime = e.EndTime,
|
|
|
StartTime = e.StartTime,
|
|
@@ -1317,41 +1373,28 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
ExamId = e.Id,
|
|
|
IsCheck = u.IsCheck,
|
|
|
IsReExam = u.IsReExam,
|
|
|
- CanReExam = SqlFunc.Subqueryable<ExamUserExamItem>().Where(x=>x.UserExamId == u.Id).Count()< e.Count
|
|
|
+ CanReExam = SqlFunc.Subqueryable<ExamUserExamItem>().Where(x => x.UserExamId == u.Id).Count() < e.Count
|
|
|
});
|
|
|
return queryable;
|
|
|
}
|
|
|
|
|
|
public async Task<List<ViewExamQuestionDto>> View(string id)
|
|
|
{
|
|
|
-
|
|
|
- List<ViewExamQuestionDto> viewExamQuestionDtos = await GetViewExamQuestion(id,null);
|
|
|
|
|
|
- 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);
|
|
|
+ List<ViewExamQuestionDto> viewExamQuestionDtos = await GetViewExamQuestion(id, null);
|
|
|
|
|
|
- viewExamQuestionDtos.ForEach(item =>
|
|
|
+ var examQuestionIds = viewExamQuestionDtos.Select(x => x.ExamQuestionId).ToList();
|
|
|
+ var questionIds = viewExamQuestionDtos.Select(x => x.QuestionId).ToList();
|
|
|
+ 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())
|
|
|
- {
|
|
|
- var questionAnswer = questionAnswers.FirstOrDefault(x => x.QuestionId == item.QuestionId);
|
|
|
- item.Answer = questionAnswer?.Answer ?? string.Empty;
|
|
|
- item.CorrectAnswer = questionAnswer?.CorrectAnswer ?? string.Empty;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.CorrectAnswer = string.Join(",", item.QuestionOptions.Where(x => x.IsAnswer).Select(x => x.Label));
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
+ 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;
|
|
|
|
|
@@ -1363,41 +1406,44 @@ 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, userExamIds);
|
|
|
+ List<QuestionKnowladgeDto> questionKnowladges = await GetQuestionKnowladges(examQuestionIds);
|
|
|
+ List<QuestionSourcewareDto> sourcewares = await GetSourcewares(examQuestionIds);
|
|
|
+
|
|
|
+ ResolveExamQuestions(viewExamQuestionDtos, questionOptions, questionKnowladges, sourcewares);
|
|
|
|
|
|
- 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);
|
|
|
+ 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();
|
|
|
- if (!item.QuestionType.CheckSelectType())
|
|
|
+ item.QuestionKnowladgeDtos = questionKnowladges.Where(x => x.QuestionId == item.ExamQuestionId).ToList();
|
|
|
+ item.QuestionSourcewareDtos = sourcewares.Where(x => x.QuestionId == item.ExamQuestionId).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
|
|
|
- {
|
|
|
- item.QuestionOptions = questionOptions.Where(x => x.QuestionId == item.QuestionId).ToList();
|
|
|
- item.CorrectAnswer = string.Join(",", item.QuestionOptions.Where(x => x.IsAnswer).Select(x => x.Label));
|
|
|
+ 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)
|
|
|
+ private async Task<List<QuestionSourcewareDto>> GetSourcewares(List<string> questionIds)
|
|
|
{
|
|
|
var questionSourcewareTable = new ExamRepository<ExamQuestionSourcewareBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
var sourcewareTable = new ExamRepository<ExamSourceware>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
|
|
|
- var querable = questionSourcewareTable.InnerJoin<ExamQuestionSourceware>((qsb,qs)=>qsb.SourcewareId == qs.Id).InnerJoin(sourcewareTable, (qsb,qs, s) => qs.SourcewareId == s.Id).Select((qsb, qs, s) => new QuestionSourcewareDto
|
|
|
+ var querable = questionSourcewareTable.InnerJoin<ExamQuestionSourceware>((qsb, qs) => qsb.SourcewareId == qs.Id).InnerJoin(sourcewareTable, (qsb, qs, s) => qs.SourcewareId == s.Id).Select((qsb, qs, s) => new QuestionSourcewareDto
|
|
|
{
|
|
|
Id = qs.Id,
|
|
|
Name = s.Name,
|
|
@@ -1409,27 +1455,28 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
return await querable.ToListAsync();
|
|
|
}
|
|
|
|
|
|
- private async Task<List<QuestionKnowladgeDto>> GetQuestionKnowladges(List<string> questionIds)
|
|
|
+ private async Task<List<QuestionKnowladgeDto>> GetQuestionKnowladges(List<string> questionIds)
|
|
|
{
|
|
|
var questionKnowladgeTable = new ExamRepository<ExamQuestionKnowladgeBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
-
|
|
|
+
|
|
|
|
|
|
return await questionKnowladgeTable.Where(x => questionIds.Contains(x.ExamQuestionId))
|
|
|
- .InnerJoin<ExamQuestionKnowladge>((kb,k)=>kb.KnowladgeId == k.Id).Select((kb, k) => new QuestionKnowladgeDto
|
|
|
- {
|
|
|
- Id = kb.Id,
|
|
|
- QuestionId = kb.ExamQuestionId,
|
|
|
- KnowladgeId = k.KnowladgeId,
|
|
|
- Title = kb.Title
|
|
|
- }).ToListAsync();
|
|
|
+ .InnerJoin<ExamQuestionKnowladge>((kb, k) => kb.KnowladgeId == k.Id).Select((kb, k) => new QuestionKnowladgeDto
|
|
|
+ {
|
|
|
+ Id = kb.Id,
|
|
|
+ QuestionId = kb.ExamQuestionId,
|
|
|
+ KnowladgeId = k.KnowladgeId,
|
|
|
+ Title = kb.Title
|
|
|
+ }).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))
|
|
|
+ var querable = selectQuestionOptions
|
|
|
.LeftJoin(userExamItemOptionTable, (op, uio) => op.Id == uio.QuestionOptionId)
|
|
|
.Select((op, uio) => new ViewQuestionOptionDto
|
|
|
{
|
|
@@ -1439,13 +1486,13 @@ 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();
|
|
|
}
|
|
|
|
|
|
- private async Task<List<ViewQuestionAnswerDto>> GetQuestionAnswers(string id, List<string> questionIds)
|
|
|
+ private async Task<List<ViewQuestionAnswerDto>> GetQuestionAnswers(string id, List<string> questionIds)
|
|
|
{
|
|
|
var userExamTable = _repository.Queryable().Where(x => x.Id == id);
|
|
|
var userExamItemTable = _userExamItemRepository.Queryable();
|
|
@@ -1454,11 +1501,11 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var questionAnswerTable = new ExamRepository<ExamQuestionAnswerBak>(_uow, _dataPermissionFilterBuilder, _serviceProvider).Queryable();
|
|
|
|
|
|
var querable = examAnswerTable
|
|
|
- .InnerJoin(userExamItemTable, (a, ui) => ui.Id == a.UserExamItemId && ui.UserExamId == id)
|
|
|
- .LeftJoin(questionAnswerTable, (a, ui, qab) => qab.QuestionId == ui.QuestionId )
|
|
|
- .LeftJoin<ExamQuestionAnswer>((a, ui, qab ,qa) => qab.QuestionAnswerId == qa.Id )
|
|
|
- .LeftJoin(questionTable, (a, ui, qab, qa,q)=>qab.QuestionId == q.QuestionId && questionIds.Contains(q.Id))
|
|
|
- .Select((a, ui, qab, qa,q) => new ViewQuestionAnswerDto
|
|
|
+ .InnerJoin(userExamItemTable, (a, ui) => ui.Id == a.UserExamItemId && ui.UserExamId == id)
|
|
|
+ .LeftJoin(questionAnswerTable, (a, ui, qab) => qab.QuestionId == ui.QuestionId)
|
|
|
+ .LeftJoin<ExamQuestionAnswer>((a, ui, qab, qa) => qab.QuestionAnswerId == qa.Id)
|
|
|
+ .LeftJoin(questionTable, (a, ui, qab, qa, q) => qab.QuestionId == q.QuestionId && questionIds.Contains(q.Id))
|
|
|
+ .Select((a, ui, qab, qa, q) => new ViewQuestionAnswerDto
|
|
|
{
|
|
|
Answer = a.Answer,
|
|
|
CorrectAnswer = qa.Answer != null ? qa.Answer : string.Empty,
|
|
@@ -1468,30 +1515,35 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
return await querable.ToListAsync();
|
|
|
}
|
|
|
|
|
|
- private async Task<List<ViewExamQuestionDto>> GetViewExamQuestion(string id,string questionId)
|
|
|
+ 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().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.Empty : g.FirstOrDefault()?.CorrectAnswer
|
|
|
+ }).ToList();
|
|
|
+
|
|
|
+ return viewExamQuestion;
|
|
|
}
|
|
|
#endregion
|
|
|
|