|
|
|
@ -1377,107 +1377,13 @@ public class Ghre_ExamServices : BaseServices<Ghre_Exam, Ghre_ExamDto, InsertGhr |
|
|
|
|
public async Task<ServiceResult> SystemMark(long id) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
var record = await _ghre_ExamRecordServices.QuerySingleDto(x => x.ExamId == id || x.Id == id); |
|
|
|
|
var record = await Db.Queryable<Ghre_ExamRecord>().FirstAsync(x => 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); |
|
|
|
|
var details = await Db.Queryable<Ghre_ExamRecordDetail>().Where(x => x.ExamRecordId == record.Id).ToListAsync(); |
|
|
|
|
await ExamHelper.SystemMarkAsync(Db, record, details); |
|
|
|
|
|
|
|
|
|
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(); |
|
|
|
|
} |
|
|
|
|