You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
3.8 KiB
81 lines
3.8 KiB
using SqlSugar;
|
|
using Tiobon.Core.Model.Models;
|
|
|
|
namespace Tiobon.Core.Common.Helper;
|
|
|
|
public class ExamHelper
|
|
{
|
|
public static async Task SystemMarkAsync(ISqlSugarClient Db, Ghre_ExamRecord record, List<Ghre_ExamRecordDetail> details, List<Ghre_ExamRecordAnswer> recordAnswers)
|
|
{
|
|
var questionIds = details.Where(x => x.QuestionId != null).Select(m => m.QuestionId).Distinct().ToList();
|
|
|
|
var exampaperQuestions = await Db.Queryable<Ghre_ExamPaperQuestion>().Where(x => x.ExamPaperId == record.ExamPaperId).ToListAsync();
|
|
var questions = await Db.Queryable<Ghre_Question>().Where(x => questionIds.Contains(x.Id)).ToListAsync();
|
|
var answers = await Db.Queryable<Ghre_QuestionAnswer>()
|
|
.Where(x => x.QuestionId != null && questionIds.Contains(x.QuestionId.Value) && x.IsCorrect == true)
|
|
.ToListAsync();
|
|
decimal? score = 0;
|
|
|
|
details.ForEach(detail =>
|
|
{
|
|
var question = questions.FirstOrDefault(x => x.Id == detail.QuestionId);
|
|
detail.IsCorrect = false;
|
|
detail.Score = 0;
|
|
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == detail.QuestionId);
|
|
|
|
switch (question.QuestionType)
|
|
{
|
|
case "Completion":
|
|
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == detail.QuestionId).ToList();
|
|
var contents = recordAnswers.Where(x => x.ExamRecordDetailId == detail.Id).Select(x => x.AnswerContent).ToList();
|
|
var count = completionAnswers.Count;
|
|
if (contents.Count == count)
|
|
{
|
|
for (int i = 0; i < completionAnswers.Count; i++)
|
|
if (completionAnswers[i].AnswerContent == contents[i])
|
|
count--;
|
|
|
|
if (count == 0)
|
|
{
|
|
score += exampaperQuestion?.Score;
|
|
detail.Score = exampaperQuestion?.Score;
|
|
detail.IsCorrect = true;
|
|
}
|
|
}
|
|
break;
|
|
case "ShortAnswer":
|
|
if (recordAnswers.Where(x => x.ExamRecordDetailId == detail.Id).Any())
|
|
{
|
|
var completionAnswers1 = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == detail.QuestionId).ToList();
|
|
var content = recordAnswers.Where(x => x.ExamRecordDetailId == detail.Id).First().AnswerContent;
|
|
var count1 = completionAnswers1.Count;
|
|
|
|
for (int i = 0; i < completionAnswers1.Count; i++)
|
|
if (content.IndexOf(completionAnswers1[i].AnswerContent) > -1)
|
|
count1--;
|
|
|
|
if (count1 == 0)
|
|
{
|
|
score += exampaperQuestion?.Score;
|
|
detail.Score = exampaperQuestion?.Score;
|
|
detail.IsCorrect = true;
|
|
}
|
|
}
|
|
|
|
break;
|
|
default:
|
|
var questionAnswerIds = recordAnswers.Where(x => x.ExamRecordDetailId == detail.Id && x.QuestionAnswerId != null).Select(m => m.QuestionAnswerId).ToList();
|
|
|
|
if (questionAnswerIds.Count == answers.Where(x => x.QuestionId == detail.QuestionId).Count())
|
|
{
|
|
score += exampaperQuestion?.Score;
|
|
detail.Score = exampaperQuestion?.Score;
|
|
detail.IsCorrect = true;
|
|
}
|
|
break;
|
|
}
|
|
});
|
|
record.Score = score;
|
|
|
|
}
|
|
}
|
|
|