|
@@ -39,6 +39,9 @@ using Hotline.Repository.SqlSugar.Exam.Interfaces.Questions;
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
using Hotline.Tools;
|
|
|
using Hotline.Users;
|
|
|
+using System.Buffers;
|
|
|
+using Exam.Repository.Sqlsugar.Repositories.TestPapers;
|
|
|
+using Hotline.Repository.SqlSugar.Exam.Interfaces.Exams;
|
|
|
|
|
|
namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
{
|
|
@@ -54,10 +57,16 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
private readonly ITestPaperItemOptionsRepository _testPaperItemOptionsRepository;
|
|
|
private readonly ITestPaperItemSourcewareRepository _testPaperItemSourcewareRepository;
|
|
|
private readonly ITestPaperItemKnowladgeRepository _testPaperItemKnowladgeRepository;
|
|
|
+ private readonly IExamQuestionRepository _examQuestionRepository;
|
|
|
+ private readonly IExamQuestionAnswerRepository _examQuestionAnswerRepository;
|
|
|
+ private readonly IExamQuestionOptionsRepository _examQuestionOptionsRepository;
|
|
|
+ private readonly IExamQuestionSourcewareRepository _examQuestionSourcewareRepository;
|
|
|
+ private readonly IExamQuestionKnowladgeRepository _examQuestionKnowladgeRepository;
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
private readonly IMapper _mapper;
|
|
|
private readonly ISessionContext _sessionContext;
|
|
|
private TestPaperProxy _testPaperProxy;
|
|
|
+ private ExamManageProxy _examManageProxy;
|
|
|
private AddExamManageDto _addExamManageDto;
|
|
|
|
|
|
public ExamManageService(IExamManageRepository repository,
|
|
@@ -69,6 +78,11 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
ITestPaperItemOptionsRepository testPaperItemOptionsRepository,
|
|
|
ITestPaperItemSourcewareRepository testPaperItemSourcewareRepository,
|
|
|
ITestPaperItemKnowladgeRepository testPaperItemKnowladgeRepository,
|
|
|
+ IExamQuestionRepository examQuestionRepository,
|
|
|
+ IExamQuestionAnswerRepository examQuestionAnswerRepository,
|
|
|
+ IExamQuestionOptionsRepository examQuestionOptionsRepository,
|
|
|
+ IExamQuestionSourcewareRepository examQuestionSourcewareRepository,
|
|
|
+ IExamQuestionKnowladgeRepository examQuestionKnowladgeRepository,
|
|
|
IDataPermissionFilterBuilder dataPermissionFilterBuilder, IServiceProvider serviceProvider,
|
|
|
IMapper mapper, ISessionContext sessionContext) : base(repository, mapper, sessionContext)
|
|
|
{
|
|
@@ -82,6 +96,11 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
this._testPaperItemOptionsRepository = testPaperItemOptionsRepository;
|
|
|
this._testPaperItemSourcewareRepository = testPaperItemSourcewareRepository;
|
|
|
this._testPaperItemKnowladgeRepository = testPaperItemKnowladgeRepository;
|
|
|
+ this._examQuestionRepository = examQuestionRepository;
|
|
|
+ this._examQuestionAnswerRepository = examQuestionAnswerRepository;
|
|
|
+ this._examQuestionOptionsRepository = examQuestionOptionsRepository;
|
|
|
+ this._examQuestionSourcewareRepository = examQuestionSourcewareRepository;
|
|
|
+ this._examQuestionKnowladgeRepository = examQuestionKnowladgeRepository;
|
|
|
_serviceProvider = serviceProvider;
|
|
|
this._mapper = mapper;
|
|
|
this._sessionContext = sessionContext;
|
|
@@ -147,6 +166,11 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
await base.Complete(base.Entity, OperationConstant.Create);
|
|
|
|
|
|
+ await GenerateExamQuestion(new GenerateExamTestPaperRequest {
|
|
|
+ TestPaperId = actionRequest.TestPaperId ,
|
|
|
+ ExamManageId = id
|
|
|
+ }, cancellationToken);
|
|
|
+
|
|
|
return id;
|
|
|
}
|
|
|
|
|
@@ -160,13 +184,50 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
ResolveQuestionId(actionRequest, actionRequest.Id);
|
|
|
|
|
|
- _addExamManageDto = _mapper.Map<AddExamManageDto>(actionRequest);
|
|
|
+ MapAddUpdateExamManage(actionRequest);
|
|
|
|
|
|
base.Entity.ExamQuestionScores = await ModifyExamQuestionScores(actionRequest, cancellationToken);
|
|
|
|
|
|
base.Entity.UserExams = await ModifyUserExam(actionRequest, cancellationToken);
|
|
|
|
|
|
await base.Complete(base.Entity, OperationConstant.Update);
|
|
|
+
|
|
|
+ await GenerateExamQuestion(new GenerateExamTestPaperRequest {
|
|
|
+ TestPaperId = actionRequest.TestPaperId,
|
|
|
+ ExamManageId = actionRequest.Id
|
|
|
+ }, cancellationToken);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void MapAddUpdateExamManage(UpdateExamManageDto actionRequest)
|
|
|
+ {
|
|
|
+
|
|
|
+ _addExamManageDto = _mapper.Map<AddExamManageDto>(actionRequest);
|
|
|
+
|
|
|
+ _addExamManageDto.UserExamDtos = new List<AddUserExamDto>();
|
|
|
+
|
|
|
+ _addExamManageDto.ExamQuestionScoreDtos = new List<AddExamQuestionScoreDto>();
|
|
|
+
|
|
|
+ actionRequest.UserExamDtos.ForEach(x =>
|
|
|
+ {
|
|
|
+ x.OperationStatus = x.Id != null ? EEOperationStatus.Update : EEOperationStatus.Update;
|
|
|
+
|
|
|
+ if(x.OperationStatus== EEOperationStatus.Add)
|
|
|
+ {
|
|
|
+ _addExamManageDto.UserExamDtos.Add(_mapper.Map<AddUserExamDto>(x));
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ actionRequest.ExamQuestionScoreDtos.ForEach(x =>
|
|
|
+ {
|
|
|
+ x.OperationStatus = x.Id != null ? EEOperationStatus.Update : EEOperationStatus.Add;
|
|
|
+
|
|
|
+ if (x.OperationStatus == EEOperationStatus.Add)
|
|
|
+ {
|
|
|
+ _addExamManageDto.ExamQuestionScoreDtos.Add(_mapper.Map<AddExamQuestionScoreDto>(x));
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public override async Task DeleteAsync(EntityQueryRequest entityQueryRequest, CancellationToken cancellationToken)
|
|
@@ -210,38 +271,59 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
_sessionContext
|
|
|
);
|
|
|
|
|
|
+ await _testPaperProxy.DeleteTestPaperItems(generateExamTestPaperRequest.TestPaperId, cancellationToken);
|
|
|
+
|
|
|
await _testPaperProxy.GenerateQuestion(questions, generateExamTestPaperRequest.TestPaperId, cancellationToken);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async Task<List<Question>> GetQuestions(List<TagQuestion> tagQuestionCounts)
|
|
|
+ public async Task GenerateExamQuestion(GenerateExamTestPaperRequest generateExamTestPaperRequest, CancellationToken cancellationToken)
|
|
|
{
|
|
|
- var questionRepository = new ExamRepository<Question>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
- var questionTagRepository = new ExamRepository<QuestionTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
-
|
|
|
- var questionTable = questionRepository.Queryable();
|
|
|
- var questionTagTable = questionTagRepository.Queryable();
|
|
|
-
|
|
|
- if (tagQuestionCounts != null)
|
|
|
+ var expression = generateExamTestPaperRequest.GetExpression();
|
|
|
+ var examManages = await _repository.Queryable().Where(expression).ToListAsync();
|
|
|
+ var examManage = examManages.FirstOrDefault();
|
|
|
+ if (examManage != null)
|
|
|
{
|
|
|
- var questionQuerables = new List<ISugarQueryable<Question>>();
|
|
|
- tagQuestionCounts.ForEach(item =>
|
|
|
+ var questions = new List<Question>();
|
|
|
+ if (examManage.Mode == Share.Enums.Exams.EExamMode.Random)
|
|
|
{
|
|
|
- ISugarQueryable<Question> queryable = questionTable.InnerJoin(questionTagTable, (q, t) => t.Id == t.QuestionId)
|
|
|
- .Where((q, t) => q.QuestionType == item.QuestionType && t.TagId == item.TagId).Take(item.Count).Select((q, t)=>q);
|
|
|
-
|
|
|
- questionQuerables.Add(queryable);
|
|
|
- });
|
|
|
+ var tagQuestionCounts = await GetTagQuestions(examManage);
|
|
|
+ questions = await GetQuestions(tagQuestionCounts);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ questions = await GetQuestions(examManage);
|
|
|
+ }
|
|
|
+
|
|
|
+ _examManageProxy = new ExamManageProxy(_repository,
|
|
|
+ _examQuestionRepository,
|
|
|
+ _examQuestionAnswerRepository,
|
|
|
+ _examQuestionOptionsRepository,
|
|
|
+ _examQuestionSourcewareRepository,
|
|
|
+ _examQuestionKnowladgeRepository,
|
|
|
+ _dataPermissionFilterBuilder,
|
|
|
+ _serviceProvider,
|
|
|
+ _mapper,
|
|
|
+ _sessionContext
|
|
|
+ );
|
|
|
|
|
|
- var queryResult = questionRepository.UnionAll(questionQuerables.ToArray());
|
|
|
+ await _examManageProxy.DeleteExamQuestions(generateExamTestPaperRequest.TestPaperId, cancellationToken);
|
|
|
|
|
|
- return await queryResult.ToListAsync();
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- return null;
|
|
|
+ await _examManageProxy.GenerateQuestion(questions, generateExamTestPaperRequest.TestPaperId, cancellationToken);
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ private async Task<List<Question>> GetQuestions(ExamManage examManage)
|
|
|
+ {
|
|
|
+ var questionRepository = new ExamRepository<Question>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+
|
|
|
+ var questionTable = questionRepository.Queryable();
|
|
|
+ var testPaperItemTable = _testPaperItemRepository.Queryable().Where(x => x.TestPaperId == examManage.TestPaperId);
|
|
|
+
|
|
|
+ var questions = questionTable.InnerJoin(testPaperItemTable, (q, t) => q.Id == t.QuestionId)
|
|
|
+ .Select((q, t) => q);
|
|
|
|
|
|
+ return await questions.ToListAsync();
|
|
|
}
|
|
|
|
|
|
private async Task<List<TagQuestion>> GetTagQuestions(ExamManage examManage)
|
|
@@ -250,6 +332,7 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
var ruleTagRepository = new ExamRepository<RuleTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
var tagQuestionRepository = new ExamRepository<TagQuestion>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
|
|
|
+
|
|
|
var extractRuleTable = extractRuleRepository.Queryable().Where(x=>x.Id == examManage.ExtractRuleId && x.RuleType == examManage.ExamType);
|
|
|
var ruleTagTable = ruleTagRepository.Queryable();
|
|
|
var tagQuestionTable = tagQuestionRepository.Queryable();
|
|
@@ -336,7 +419,9 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
userExams.ForEach(item =>
|
|
|
{
|
|
|
var userExamDto = userExamDtos.FirstOrDefault(x => x.Id == item.Id);
|
|
|
- _mapper.Map<UpdateUserExamDto, UserExam>(userExamDto, item);
|
|
|
+
|
|
|
+ if (userExamDto != null)
|
|
|
+ _mapper.Map<UpdateUserExamDto, UserExam>(userExamDto, item);
|
|
|
});
|
|
|
|
|
|
userExams.ToUpdate(_sessionContext);
|
|
@@ -356,7 +441,14 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
|
|
|
var examQuestionScores = all.Where(x => ids.Contains(x.Id)).ToList();
|
|
|
|
|
|
- examQuestionScores = _mapper.Map<List<UpdateExamQuestionScoreDto>, List<ExamQuestionScore>>(examQuestionScoreDtos, examQuestionScores);
|
|
|
+ //examQuestionScores = _mapper.Map<List<UpdateExamQuestionScoreDto>, List<ExamQuestionScore>>(examQuestionScoreDtos, examQuestionScores);
|
|
|
+
|
|
|
+ examQuestionScores.ForEach(item =>
|
|
|
+ {
|
|
|
+ var examQuestionScoreDto = examQuestionScoreDtos.FirstOrDefault(x => x.Id == item.Id);
|
|
|
+ if (examQuestionScoreDto != null)
|
|
|
+ item = _mapper.Map<UpdateExamQuestionScoreDto, ExamQuestionScore>(examQuestionScoreDto, item);
|
|
|
+ });
|
|
|
|
|
|
examQuestionScores.ToUpdate(_sessionContext);
|
|
|
|
|
@@ -504,6 +596,37 @@ namespace Hotline.Application.Exam.Service.ExamManages
|
|
|
});
|
|
|
return queryable;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ private async Task<List<Question>> GetQuestions(List<TagQuestion> tagQuestionCounts)
|
|
|
+ {
|
|
|
+ var questionRepository = new ExamRepository<Question>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+ var questionTagRepository = new ExamRepository<QuestionTag>(_repository.UOW, _dataPermissionFilterBuilder, _serviceProvider);
|
|
|
+
|
|
|
+ var questionTable = questionRepository.Queryable();
|
|
|
+ var questionTagTable = questionTagRepository.Queryable();
|
|
|
+
|
|
|
+ if (tagQuestionCounts != null && tagQuestionCounts.Any())
|
|
|
+ {
|
|
|
+ var questionQuerables = new List<ISugarQueryable<Question>>();
|
|
|
+ tagQuestionCounts.ForEach(item =>
|
|
|
+ {
|
|
|
+ ISugarQueryable<Question> queryable = questionTable.InnerJoin(questionTagTable, (q, t) => t.Id == t.QuestionId)
|
|
|
+ .Where((q, t) => q.QuestionType == item.QuestionType && t.TagId == item.TagId).Take(item.Count).Select((q, t) => q);
|
|
|
+
|
|
|
+ questionQuerables.Add(queryable);
|
|
|
+ });
|
|
|
+
|
|
|
+ var queryResult = questionRepository.UnionAll(questionQuerables.ToArray());
|
|
|
+
|
|
|
+ return await queryResult.ToListAsync();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
#endregion
|
|
|
}
|
|
|
}
|