Files
TechHelper/TechHelper.Client/Exam/AssignmentCheckData.cs
SpecialX a21ca80782 1
2025-06-27 19:03:10 +08:00

95 lines
2.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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<AssignmentCheckQuestion> Questions { get; set; } = new List<AssignmentCheckQuestion>();
}
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<Guid, bool> StudentCorrectStatus { get; set; } = new Dictionary<Guid, bool>();
// Key: Student.Id, Value: true 表示正确false 表示错误
}
public class QuestionRowData
{
public AssignmentCheckQuestion QuestionItem { get; set; } // 原始题目信息
public Dictionary<Guid, bool> StudentAnswers { get; set; } = new Dictionary<Guid, bool>();
}
public static class ExamStructExtensions
{
public static AssignmentCheckData GetStruct(this AssignmentDto dto)
{
if (dto == null)
{
return new AssignmentCheckData { Title = "无效试卷", Questions = new List<AssignmentCheckQuestion>() };
}
var examStruct = new AssignmentCheckData
{
Title = dto.Title
};
GetSeqRecursive(dto.ExamStruct, 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(
AssignmentQuestionDto currentGroup,
string? parentSequence,
List<AssignmentCheckQuestion> 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,
});
}
}
}
}