|
@@ -41,6 +41,7 @@ using System.Threading;
|
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
|
using DocumentFormat.OpenXml.Office2013.Excel;
|
|
using Hotline.Share.Enums.Exams;
|
|
using Hotline.Share.Enums.Exams;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
using DocumentFormat.OpenXml.Wordprocessing;
|
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Repositories.ExamManages;
|
|
|
|
|
|
namespace Hotline.Application.Exam.Service.ExamManages
|
|
namespace Hotline.Application.Exam.Service.ExamManages
|
|
{
|
|
{
|
|
@@ -720,10 +721,37 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
if (userExamItems != null && userExamItemIds.Any())
|
|
if (userExamItems != null && userExamItemIds.Any())
|
|
{
|
|
{
|
|
- userExamItems = _mapper.Map<List<GradingExamItemDto>, List<ExamUserExamItem>>(batchGradingExamItemDto.Items, userExamItems);
|
|
|
|
|
|
+ var updateUserExamItems = new List<ExamUserExamItem>();
|
|
|
|
+ userExamItems.ForEach(x =>
|
|
|
|
+ {
|
|
|
|
+ var gradingExamItemDto = batchGradingExamItemDto.Items.Find(m => m.UserExamItemId == x.Id);
|
|
|
|
+
|
|
|
|
+ var updateUserExamItem = _mapper.Map<GradingExamItemDto, ExamUserExamItem>(gradingExamItemDto,x);
|
|
|
|
+
|
|
|
|
+ updateUserExamItems.Add(updateUserExamItem);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ updateUserExamItems.ToUpdate(_sessionContext);
|
|
|
|
+
|
|
|
|
+ await _userExamItemRepository.UpdateWithValidateAsync(updateUserExamItems, cancellationToken);
|
|
|
|
+
|
|
|
|
+ var userExamId = userExamItems.FirstOrDefault()?.UserExamId;
|
|
|
|
+ // 计算本次考试得分
|
|
|
|
+ var userExamItemsInCheck = await _userExamItemRepository.Queryable().Where(x => x.UserExamId == userExamId).ToListAsync();
|
|
|
|
+ var updateExamItemDTOs = new List<UpdateUserExamItemDto>();
|
|
|
|
+ userExamItemsInCheck.ForEach(x =>
|
|
|
|
+ {
|
|
|
|
+ var updateUserExamItem = _mapper.Map<ExamUserExamItem, UpdateUserExamItemDto>(x);
|
|
|
|
+
|
|
|
|
+ updateExamItemDTOs.Add(updateUserExamItem);
|
|
|
|
+ });
|
|
|
|
+ await CalcuteExamItemScore(_userExamItemRepository, updateExamItemDTOs,cancellationToken);
|
|
|
|
+
|
|
|
|
+ await CalcuteTotalScore(_userExamItemRepository, userExamId, cancellationToken);
|
|
|
|
|
|
- await _userExamItemRepository.UpdateWithValidateAsync(userExamItems, cancellationToken);
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
public async Task<List<ExamUserViewResponse>> GetUserListAsync(ExamUserQueryRequest examUserQueryRequest)
|
|
public async Task<List<ExamUserViewResponse>> GetUserListAsync(ExamUserQueryRequest examUserQueryRequest)
|
|
@@ -774,6 +802,80 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
await userExamRepository.UpdateWithValidateAsync(userExamItem, cancellationToken);
|
|
await userExamRepository.UpdateWithValidateAsync(userExamItem, cancellationToken);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private async Task CalcuteExamItemScore(IUserExamItemRepository userExamItemRepository, List<UpdateUserExamItemDto> addUserExamItemDtos, CancellationToken cancellationToken)
|
|
|
|
+ {
|
|
|
|
+ var questionIds = addUserExamItemDtos.Select(x => x.QuestionId).ToList();
|
|
|
|
+ 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 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)
|
|
|
|
+ .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 userExamItem = userExamItems.FirstOrDefault(x => x.QuestionId == addUserExamItemDto.QuestionId);
|
|
|
|
+ if (userExamItem != null)
|
|
|
|
+ {
|
|
|
|
+ userExamItem.IsCheck = true;
|
|
|
|
+ userExamItem.Score = isCorrect ? examQuesiontScores.FirstOrDefault(x => x.QuestionType == addUserExamItemDto.QuestionType)?.Score : 0;
|
|
|
|
+ userExamItem.ToUpdate(_sessionContext);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ await userExamItemRepository.UpdateWithValidateAsync(userExamItems, cancellationToken);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private async Task CalcuteTotalScore(IUserExamItemRepository userExamItemRepository, string userExamId, CancellationToken cancellationToken)
|
|
|
|
+ {
|
|
|
|
+ var userExam = await _repository.GetAsync(x => x.Id == userExamId);
|
|
|
|
+
|
|
|
|
+ if (userExam != null)
|
|
|
|
+ {
|
|
|
|
+ var userExamItems = await userExamItemRepository.Queryable().Where(x => x.UserExamId == userExamId).ToListAsync();
|
|
|
|
+ var examManageRepository = new ExamRepository<ExamManage>(_uow, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
|
+ var examManage = await examManageRepository.GetAsync(x => x.Id == userExam.ExamId);
|
|
|
|
+
|
|
|
|
+ var totalScore = userExamItems.Sum(x => x.Score);
|
|
|
|
+
|
|
|
|
+ userExam.Score = totalScore;
|
|
|
|
+
|
|
|
|
+ userExam.IsCheck = true;
|
|
|
|
+
|
|
|
|
+ userExam.ExamStatus = EExamStatus.Complete;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ if (examManage != null)
|
|
|
|
+ {
|
|
|
|
+ userExam.IsSuccess = userExam.Score > examManage.CutoffScore;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ userExam.ToUpdate(_sessionContext);
|
|
|
|
+
|
|
|
|
+ await _repository.UpdateWithValidateAsync(userExam,cancellationToken);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
private async Task AddExamAsync(IRepository<ExamUserExamItem> userExamItemRepository, AddUserExamItemDto addUserExamItemDto, CancellationToken cancellationToken)
|
|
private async Task AddExamAsync(IRepository<ExamUserExamItem> userExamItemRepository, AddUserExamItemDto addUserExamItemDto, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
var userExamItem = await AddUserExamItem(addUserExamItemDto, cancellationToken);
|
|
var userExamItem = await AddUserExamItem(addUserExamItemDto, cancellationToken);
|