This commit is contained in:
SpecialX
2025-06-27 19:03:10 +08:00
parent 14fbe6397a
commit a21ca80782
57 changed files with 3872 additions and 611 deletions

View File

@@ -2,18 +2,20 @@
namespace TechHelper.Client.Exam
{
public class ExamStruct
public class AssignmentCheckData
{
public string Title { get; set; }
public List<QuestionItem> Questions { get; set; } = new List<QuestionItem>();
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 QuestionItem
{
public string Sequence { get; set; } = string.Empty;
public string QuestionText { get; set; } = string.Empty;
public float Score { get; set; }
}
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
@@ -24,32 +26,32 @@ namespace TechHelper.Client.Exam
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 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 AssignmentCheckQuestion QuestionItem { get; set; } // 原始题目信息
public Dictionary<Guid, bool> StudentAnswers { get; set; } = new Dictionary<Guid, bool>();
}
public static class ExamStructExtensions
{
public static ExamStruct GetStruct(this AssignmentDto dto)
public static AssignmentCheckData GetStruct(this AssignmentDto dto)
{
if (dto == null)
{
return new ExamStruct { Title = "无效试卷", Questions = new List<ExamStruct.QuestionItem>() };
return new AssignmentCheckData { Title = "无效试卷", Questions = new List<AssignmentCheckQuestion>() };
}
var examStruct = new ExamStruct
var examStruct = new AssignmentCheckData
{
Title = dto.Title
Title = dto.Title
};
GetSeqRecursive(dto.ExamStruct, null, examStruct.Questions);
@@ -65,8 +67,8 @@ namespace TechHelper.Client.Exam
/// <param name="allQuestions">用于收集所有生成题目项的列表。</param>
private static void GetSeqRecursive(
AssignmentQuestionDto currentGroup,
string? parentSequence,
List<ExamStruct.QuestionItem> allQuestions)
string? parentSequence,
List<AssignmentCheckQuestion> allQuestions)
{
string currentGroupSequence = parentSequence != null
? $"{parentSequence}.{currentGroup.Index}"
@@ -76,6 +78,17 @@ namespace TechHelper.Client.Exam
{
GetSeqRecursive(subGroup, currentGroupSequence, allQuestions);
}
if (!string.IsNullOrEmpty(currentGroup.Sequence))
{
allQuestions.Add(new AssignmentCheckQuestion
{
AssignmentQuestionDto = currentGroup,
//Sequence = currentGroupSequence,
Sequence = currentGroup.Sequence,
Score = currentGroup.Score,
});
}
}
}
}

View File

@@ -7,7 +7,7 @@ using AutoMapper;
namespace TechHelper.Client.Exam
{
public static class ExamPaperExtensions
public static class AssignmentExtensions
{
public static List<string> ParseOptionsFromText(this string optionsText)
@@ -25,9 +25,9 @@ namespace TechHelper.Client.Exam
public static void SeqQGroupIndex(this AssignmentQuestionDto dto)
{
foreach(var sqg in dto.ChildrenAssignmentQuestion)
foreach (var sqg in dto.ChildrenAssignmentQuestion)
{
sqg.Index = (byte)dto.ChildrenAssignmentQuestion.IndexOf(sqg);
sqg.Index = (byte)(dto.ChildrenAssignmentQuestion.IndexOf(sqg) + 1);
sqg.SeqQGroupIndex();
}

View File

@@ -56,6 +56,7 @@ namespace TechHelper.Client.Exam
public string Description { get; set; } = string.Empty;
public byte Index { get; set; } = 0;
public float Score { get; set; }
public string Sequence { get; set; } = string.Empty;
public QuestionEx? Question { get; set; }
public AssignmentStructType Type { get; set; }
public List<AssignmentQuestionEx> ChildrenAssignmentQuestion { get; set; } = new List<AssignmentQuestionEx>();
@@ -344,6 +345,8 @@ namespace TechHelper.Client.Exam
assignmentQuestionStack.Pop();
}
string sequence = assignmentQuestionStack.Count > 0 ? assignmentQuestionStack.Peek().Sequence : string.Empty;
// 验证捕获组Group 1 是编号Group 2 是题目内容
if (pm.RegexMatch.Groups.Count < 3 || !pm.RegexMatch.Groups[1].Success || string.IsNullOrWhiteSpace(pm.RegexMatch.Groups[2].Value))
{
@@ -372,6 +375,8 @@ namespace TechHelper.Client.Exam
// 提取标题,这里使用 Group 2 的值,它不包含分数
string title = pm.RegexMatch.Groups[2].Value.Trim();
string seq = pm.RegexMatch.Groups[1].Value.Trim();
seq = string.IsNullOrEmpty(seq) || string.IsNullOrEmpty(sequence) ? seq : " ." + seq;
AssignmentQuestionEx newAssignmentQuestion;
if (pm.PatternConfig.Type == AssignmentStructType.Struct)
@@ -380,6 +385,7 @@ namespace TechHelper.Client.Exam
{
Title = title,
Score = score,
Sequence = sequence + seq,
Priority = pm.PatternConfig.Priority,
Type = pm.PatternConfig.Type
};
@@ -390,6 +396,7 @@ namespace TechHelper.Client.Exam
{
Priority = pm.PatternConfig.Priority,
Type = pm.PatternConfig.Type,
Sequence = sequence + seq,
Score = score,
Question = new QuestionEx
{