|
|
|
@ -31,6 +31,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
private readonly IGhre_ExamRecordServices _ghre_ExamRecordServices; |
|
|
|
|
private readonly IGhre_ExamMessageLogServices _ghre_ExamMessageLogServices; |
|
|
|
|
private readonly IGhre_ExamPaperServices _ghre_ExamPaperServices; |
|
|
|
|
private readonly IGhre_ExamPaperQuestionServices _ghre_ExamPaperQuestionServices; |
|
|
|
|
private readonly IGhre_ExamRecordDetailServices _ghre_ExamRecordDetailServices; |
|
|
|
|
private readonly IGhre_QuestionServices _ghre_QuestionServices; |
|
|
|
|
private readonly IGhre_QuestionAnswerServices _ghre_QuestionAnswerServices; |
|
|
|
|
public Ghre_ExamServices(ICaching caching, |
|
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
|
IGhre_CourseSceneServices ghre_CourseSceneServices, |
|
|
|
@ -39,6 +43,10 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
IGhre_ExamRecordServices ghre_ExamRecordServices, |
|
|
|
|
IGhre_ExamMessageLogServices ghre_ExamMessageLogServices, |
|
|
|
|
IGhre_ExamPaperServices ghre_ExamPaperServices, |
|
|
|
|
IGhre_ExamPaperQuestionServices ghre_ExamPaperQuestionServices, |
|
|
|
|
IGhre_ExamRecordDetailServices ghre_ExamRecordDetailServices, |
|
|
|
|
IGhre_QuestionServices ghre_QuestionServices, |
|
|
|
|
IGhre_QuestionAnswerServices ghre_QuestionAnswerServices, |
|
|
|
|
IBaseRepository<Ghre_Exam> dal) |
|
|
|
|
{ |
|
|
|
|
this._dal = dal; |
|
|
|
@ -50,7 +58,11 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
_ghre_ExamStaffServices = ghre_ExamStaffServices; |
|
|
|
|
_ghre_ExamRecordServices = ghre_ExamRecordServices; |
|
|
|
|
_ghre_ExamMessageLogServices = ghre_ExamMessageLogServices; |
|
|
|
|
_ghre_QuestionServices = ghre_QuestionServices; |
|
|
|
|
_ghre_QuestionAnswerServices = ghre_QuestionAnswerServices; |
|
|
|
|
_ghre_ExamPaperServices = ghre_ExamPaperServices; |
|
|
|
|
_ghre_ExamPaperQuestionServices = ghre_ExamPaperQuestionServices; |
|
|
|
|
_ghre_ExamRecordDetailServices = ghre_ExamRecordDetailServices; |
|
|
|
|
} |
|
|
|
|
public async Task<dynamic> GetModuleInfo(ModuleParam param) |
|
|
|
|
{ |
|
|
|
@ -1255,4 +1267,115 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
return ServiceResult.OprateSuccess("提交成功!"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> SystemMark(long id) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var record = await _ghre_ExamRecordServices.QuerySingleDto(x => x.ExamId == id || x.Id == id); |
|
|
|
|
var examPaper = await _ghre_ExamPaperServices.QuerySingleDto(x => x.Id == record.ExamPaperId && x.ScoreMethod == "System"); |
|
|
|
|
if (examPaper != null) |
|
|
|
|
{ |
|
|
|
|
var details = await _ghre_ExamRecordDetailServices.QueryDto(x => x.ExamRecordId == record.Id); |
|
|
|
|
|
|
|
|
|
details.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrWhiteSpace(x.QuestionAnswerId)) |
|
|
|
|
x.QuestionAnswerIds = JsonConvert.DeserializeObject<List<long>>(x.QuestionAnswerId); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var questionIds = details.Where(x => x.QuestionId != null).SelectMany(m => |
|
|
|
|
{ |
|
|
|
|
return m.QuestionAnswerIds.Select((x, i) => |
|
|
|
|
{ |
|
|
|
|
return x; |
|
|
|
|
}); |
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
var exampaperQuestions = await _ghre_ExamPaperQuestionServices.Query(x => x.ExamPaperId == record.ExamPaperId); |
|
|
|
|
var questions = await _ghre_QuestionServices.Query(x => questionIds.Contains(x.Id)); |
|
|
|
|
var answers = await _ghre_QuestionAnswerServices.Query(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value) && x.IsCorrect == true); |
|
|
|
|
decimal? score = 0; |
|
|
|
|
|
|
|
|
|
var detailGroups = details.GroupBy(m => m.QuestionId) |
|
|
|
|
.Select(m => new |
|
|
|
|
{ |
|
|
|
|
m.FirstOrDefault()?.QuestionId, |
|
|
|
|
List = m.ToList() |
|
|
|
|
}) |
|
|
|
|
.ToList(); |
|
|
|
|
|
|
|
|
|
detailGroups.ForEach(group => |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var question = questions.FirstOrDefault(x => x.Id == group.QuestionId); |
|
|
|
|
if (question.QuestionType != "Completion" && question.QuestionType != "ShortAnswer") |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var questionAnswerIds = group.List.Where(x => x.QuestionId != null).SelectMany(m => |
|
|
|
|
{ |
|
|
|
|
return m.QuestionAnswerIds.Select((x, i) => |
|
|
|
|
{ |
|
|
|
|
return x; |
|
|
|
|
}); |
|
|
|
|
}).ToList(); |
|
|
|
|
|
|
|
|
|
if (questionAnswerIds.Count == answers.Where(x => questionAnswerIds.Contains(x.Id)).Count()) |
|
|
|
|
{ |
|
|
|
|
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId); |
|
|
|
|
score += exampaperQuestion.Score; |
|
|
|
|
var detail = details.Where(x => x.QuestionId == group.QuestionId).First(); |
|
|
|
|
detail.Score = exampaperQuestion.Score; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (question.QuestionType == "Completion")// 填空题 |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrWhiteSpace(group.List.First().AnswerContent)) |
|
|
|
|
{ |
|
|
|
|
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList(); |
|
|
|
|
var contents = JsonConvert.DeserializeObject<List<string>>(group.List.First().AnswerContent); |
|
|
|
|
var count = completionAnswers.Count; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < completionAnswers.Count; i++) |
|
|
|
|
if (completionAnswers[i].AnswerContent == contents[i]) |
|
|
|
|
count--; |
|
|
|
|
|
|
|
|
|
if (count == 0) |
|
|
|
|
{ |
|
|
|
|
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId); |
|
|
|
|
score += exampaperQuestion.Score; |
|
|
|
|
var detail = details.Where(x => x.QuestionId == group.QuestionId).First(); |
|
|
|
|
detail.Score = exampaperQuestion.Score; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else if (question.QuestionType == "ShortAnswer")//简单题 |
|
|
|
|
{ |
|
|
|
|
if (!string.IsNullOrWhiteSpace(group.List.First().AnswerContent)) |
|
|
|
|
{ |
|
|
|
|
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList(); |
|
|
|
|
var content = group.List.First().AnswerContent; |
|
|
|
|
var count = completionAnswers.Count; |
|
|
|
|
|
|
|
|
|
for (int i = 0; i < completionAnswers.Count; i++) |
|
|
|
|
if (content.IndexOf(completionAnswers[i].AnswerContent) > -1) |
|
|
|
|
count--; |
|
|
|
|
|
|
|
|
|
if (count == 0) |
|
|
|
|
{ |
|
|
|
|
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId); |
|
|
|
|
score += exampaperQuestion.Score; |
|
|
|
|
var detail = details.Where(x => x.QuestionId == group.QuestionId).First(); |
|
|
|
|
detail.Score = exampaperQuestion.Score; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
record.Score = score; |
|
|
|
|
await Db.Updateable(details).UpdateColumns(it => new { it.Score }).ExecuteCommandAsync(); |
|
|
|
|
await Db.Updateable(record).UpdateColumns(it => new { it.Score }).ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ServiceResult.OprateSuccess("提交成功!"); |
|
|
|
|
} |
|
|
|
|
} |