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.
 
 
 

90 lines
4.1 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)
{
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;
var detailGroups = details.GroupBy(m => m.QuestionId)
.Select(m => new
{
m.FirstOrDefault()?.QuestionId,
List = m.OrderBy(x => x.TaxisNo).ToList()
})
.ToList();
detailGroups.ForEach(group =>
{
var question = questions.FirstOrDefault(x => x.Id == group.QuestionId);
var detail = details.Where(x => x.QuestionId == group.QuestionId).First();
detail.IsCorrect = false;
detail.Score = 0;
switch (question.QuestionType)
{
case "Completion":
var completionAnswers = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList();
var contents = group.List.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)
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
detail.Score = exampaperQuestion.Score;
detail.IsCorrect = true;
}
}
break;
case "ShortAnswer":
if (!string.IsNullOrWhiteSpace(group.List.First().AnswerContent))
{
var completionAnswers1 = answers.OrderBy(x => x.TaxisNo).Where(x => x.QuestionId == group.QuestionId).ToList();
var content = group.List.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)
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
detail.Score = exampaperQuestion.Score;
detail.IsCorrect = true;
}
}
break;
default:
var questionAnswerIds = group.List.Where(x => x.QuestionId != null).Select(m => m.QuestionAnswerId).ToList();
if (questionAnswerIds.Count == answers.Where(x => questionAnswerIds.Contains(x.Id)).Count())
{
var exampaperQuestion = exampaperQuestions.FirstOrDefault(x => x.QuestionId == group.QuestionId);
score += exampaperQuestion.Score;
detail.Score = exampaperQuestion.Score;
detail.IsCorrect = true;
}
break;
}
});
record.Score = score;
}
}