ExamEdit&Check
This commit is contained in:
92
TechHelper.Client/Exam/ExamStruct.cs
Normal file
92
TechHelper.Client/Exam/ExamStruct.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
using Entities.DTO;
|
||||
|
||||
namespace TechHelper.Client.Exam
|
||||
{
|
||||
public class ExamStruct
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public List<QuestionItem> Questions { get; set; } = new List<QuestionItem>();
|
||||
|
||||
|
||||
public class QuestionItem
|
||||
{
|
||||
public string Sequence { get; set; } = string.Empty;
|
||||
public string QuestionText { get; set; } = string.Empty;
|
||||
public float Score { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class Student
|
||||
{
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Name { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class QuestionAnswerStatus
|
||||
{
|
||||
public string QuestionSequence { get; set; } = string.Empty; // 题目序号,例如 "1.1"
|
||||
public string QuestionText { get; set; } = string.Empty; // 题目文本
|
||||
public float QuestionScore { get; set; } // 题目分值
|
||||
public Dictionary<Guid, bool> StudentCorrectStatus { get; set; } = new Dictionary<Guid, bool>();
|
||||
// Key: Student.Id, Value: true 表示正确,false 表示错误
|
||||
}
|
||||
|
||||
public class QuestionRowData
|
||||
{
|
||||
public ExamStruct.QuestionItem QuestionItem { get; set; } // 原始题目信息
|
||||
public Dictionary<Guid, bool> StudentAnswers { get; set; } = new Dictionary<Guid, bool>();
|
||||
}
|
||||
|
||||
|
||||
public static class ExamStructExtensions
|
||||
{
|
||||
public static ExamStruct GetStruct(this ExamDto dto)
|
||||
{
|
||||
if (dto == null)
|
||||
{
|
||||
return new ExamStruct { Title = "无效试卷", Questions = new List<ExamStruct.QuestionItem>() };
|
||||
}
|
||||
|
||||
var examStruct = new ExamStruct
|
||||
{
|
||||
Title = dto.AssignmentTitle
|
||||
};
|
||||
|
||||
GetSeqRecursive(dto.QuestionGroups, null, examStruct.Questions);
|
||||
|
||||
return examStruct;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归方法,用于生成所有题目和子题目的完整序号。
|
||||
/// </summary>
|
||||
/// <param name="currentGroup">当前正在处理的题目组。</param>
|
||||
/// <param name="parentSequence">当前题目组的父级序号(例如:"1", "2.1")。如果为空,则表示顶级题目组。</param>
|
||||
/// <param name="allQuestions">用于收集所有生成题目项的列表。</param>
|
||||
private static void GetSeqRecursive(
|
||||
QuestionGroupDto currentGroup,
|
||||
string? parentSequence,
|
||||
List<ExamStruct.QuestionItem> allQuestions)
|
||||
{
|
||||
string currentGroupSequence = parentSequence != null
|
||||
? $"{parentSequence}.{currentGroup.Index}"
|
||||
: currentGroup.Index.ToString();
|
||||
|
||||
foreach (var subQuestion in currentGroup.SubQuestions)
|
||||
{
|
||||
string fullSequence = $"{currentGroupSequence}.{subQuestion.Index}";
|
||||
allQuestions.Add(new ExamStruct.QuestionItem
|
||||
{
|
||||
Sequence = fullSequence,
|
||||
QuestionText = subQuestion.Stem ?? string.Empty,
|
||||
Score = subQuestion.Score
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var subGroup in currentGroup.SubQuestionGroups)
|
||||
{
|
||||
GetSeqRecursive(subGroup, currentGroupSequence, allQuestions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user