using Entities.DTO; namespace TechHelper.Client.Exam { public class AssignmentCheckData { public string Title { get; set; } public Guid AssignmentId { get; set; } public Guid StudentId { get; set; } public List Questions { get; set; } = new List(); } public class AssignmentCheckQuestion { public string Sequence { get; set; } = string.Empty; public AssignmentQuestionDto AssignmentQuestionDto { get; set; } = new AssignmentQuestionDto(); 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 StudentCorrectStatus { get; set; } = new Dictionary(); // Key: Student.Id, Value: true 表示正确,false 表示错误 } public class QuestionRowData { public AssignmentCheckQuestion QuestionItem { get; set; } // 原始题目信息 public Dictionary StudentAnswers { get; set; } = new Dictionary(); } public static class ExamStructExtensions { public static AssignmentCheckData GetStruct(this AssignmentDto dto) { if (dto == null) { return new AssignmentCheckData { Title = "无效试卷", Questions = new List() }; } var examStruct = new AssignmentCheckData { Title = dto.Title }; GetSeqRecursive(dto.ExamStruct, null, examStruct.Questions); return examStruct; } /// /// 递归方法,用于生成所有题目和子题目的完整序号。 /// /// 当前正在处理的题目组。 /// 当前题目组的父级序号(例如:"1", "2.1")。如果为空,则表示顶级题目组。 /// 用于收集所有生成题目项的列表。 private static void GetSeqRecursive( AssignmentQuestionDto currentGroup, string? parentSequence, List allQuestions) { string currentGroupSequence = parentSequence != null ? $"{parentSequence}.{currentGroup.Index}" : currentGroup.Index.ToString(); foreach (var subGroup in currentGroup.ChildrenAssignmentQuestion) { GetSeqRecursive(subGroup, currentGroupSequence, allQuestions); } if (!string.IsNullOrEmpty(currentGroup.Sequence)) { allQuestions.Add(new AssignmentCheckQuestion { AssignmentQuestionDto = currentGroup, //Sequence = currentGroupSequence, Sequence = currentGroup.Sequence, Score = currentGroup.Score, }); } } } }