This commit is contained in:
SpecialX
2025-05-30 12:46:55 +08:00
parent 95daf9471b
commit e824c081bf
35 changed files with 1800 additions and 363 deletions

View File

@@ -166,8 +166,6 @@
</SQs>
</QG>";
public static string Format { get; internal set; }
}
}

View File

@@ -33,7 +33,6 @@ namespace TechHelper.Client.AI
string content = response.Choices[0].Message?.Content;
if (!string.IsNullOrEmpty(content))
{
// 移除 <think>...</think> 标签及其内容
int startIndex = content.IndexOf("<think>");
int endIndex = content.IndexOf("</think>");
if (startIndex != -1 && endIndex != -1 && endIndex > startIndex)
@@ -46,11 +45,11 @@ namespace TechHelper.Client.AI
}
catch (HttpRequestException ex)
{
Console.WriteLine($"API 请求错误:{ex.Message}");
throw;
}
catch (Exception ex)
{
Console.WriteLine($"发生未知错误:{ex.Message}");
throw;
}
return null;
}

View File

@@ -32,7 +32,7 @@ namespace TechHelper.Client.Exam
[JsonProperty("题号")]
// XML 特性:作为 <QG Id="X"> 属性
[XmlAttribute("Id")]
public string Id { get; set; }
public byte Id { get; set; }
[JsonProperty("标题")]
[XmlElement("T")] // T for Title
@@ -60,9 +60,10 @@ namespace TechHelper.Client.Exam
// 子题目类
public class SubQuestion
{
[JsonProperty("子题号")]
[XmlAttribute("Id")] // Id for SubId
public string SubId { get; set; }
public byte SubId { get; set; }
[JsonProperty("题干")]
[XmlElement("T")] // T for Text (Stem)

View File

@@ -0,0 +1,429 @@
using System.Text.RegularExpressions;
namespace TechHelper.Client.Exam.Parse
{
public class ExamPaper
{
public string Title { get; set; } = "未识别试卷标题";
public string Descript { get; set; } = "未识别试卷描述";
public string SubjectArea { get; set; } = "试卷类别";
public List<MajorQuestionGroup> MajorQuestionGroups { get; set; } = new List<MajorQuestionGroup>();
public List<Question> TopLevelQuestions { get; set; } = new List<Question>();
}
public class MajorQuestionGroup
{
public string Title { get; set; } = string.Empty;
public string Descript { get; set; } = string.Empty;
public float Score { get; set; }
public List<MajorQuestionGroup> SubMajorQuestionGroups { get; set; } = new List<MajorQuestionGroup>();
public List<Question> Questions { get; set; } = new List<Question>();
public int Priority { get; set; }
}
public class Question
{
public string Number { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
public float Score { get; set; }
public List<Option> Options { get; set; } = new List<Option>();
public List<Question> SubQuestions { get; set; } = new List<Question>();
public int Priority { get; set; }
}
public class Option
{
public string Label { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
}
/// <summary>
/// 表示一个带有优先级的正则表达式配置
/// </summary>
public class RegexPatternConfig
{
public string Pattern { get; set; } // 正则表达式字符串
public int Priority { get; set; } // 优先级,数字越小优先级越高
public Regex Regex { get; private set; } // 编译后的Regex对象用于性能优化
public RegexPatternConfig(string pattern, int priority)
{
Pattern = pattern;
Priority = priority;
Regex = new Regex(pattern, RegexOptions.Multiline | RegexOptions.Compiled); // 多行模式,编译以提高性能
}
}
/// <summary>
/// 试卷解析的配置类,包含所有正则表达式
/// </summary>
public class ExamParserConfig
{
public List<RegexPatternConfig> MajorQuestionGroupPatterns { get; set; } = new List<RegexPatternConfig>();
public List<RegexPatternConfig> QuestionPatterns { get; set; } = new List<RegexPatternConfig>();
public List<RegexPatternConfig> OptionPatterns { get; set; } = new List<RegexPatternConfig>();
public ExamParserConfig()
{
MajorQuestionGroupPatterns.Add(new RegexPatternConfig(@"^[一二三四五六七八九十]+\s*[、.]\s*(.+?)(?:\s*\((\d+)\s*分\))?$", 1)); // 如: 一、选择题 (5分)
MajorQuestionGroupPatterns.Add(new RegexPatternConfig(@"^\d+\.\s*(.+?)(?:\s*\((\d+)\s*分\))?$", 2)); // 如: 1. 填空题 (10分)
MajorQuestionGroupPatterns.Add(new RegexPatternConfig(@"^(\(.+\))\s*(.+?)(?:\s*\((\d+)\s*分\))?$", 3)); // 如: (一) 文言文阅读 (8分)
QuestionPatterns.Add(new RegexPatternConfig(@"^(\d+)\.\s*(.*)$", 1)); // 如: 1. 题干
OptionPatterns.Add(new RegexPatternConfig(@"^[A-D]\.\s*(.*)$", 1)); // 如: A. 选项内容
}
}
public class PotentialMatch
{
public int StartIndex { get; set; }
public int EndIndex { get; set; } // 匹配到的结构在原始文本中的结束位置
public string MatchedText { get; set; } // 匹配到的完整行或段落
public Match RegexMatch { get; set; } // 原始的Regex.Match对象方便获取捕获组
public RegexPatternConfig PatternConfig { get; set; } // 匹配到的模式配置
public MatchType Type { get; set; } // 枚举MajorQuestionGroup, Question, Option, etc.
}
public enum MatchType
{
MajorQuestionGroup,
Question,
Option,
Other // 如果有其他需要识别的类型
}
/// <summary>
/// 负责扫描原始文本,收集所有潜在的匹配项(题组、题目、选项)。
/// 它只进行匹配,不进行结构化归属。
/// </summary>
public class ExamDocumentScanner
{
private readonly ExamParserConfig _config;
public ExamDocumentScanner(ExamParserConfig config)
{
_config = config;
}
/// <summary>
/// 扫描给定的文本,返回所有潜在的匹配项,并按起始位置排序。
/// </summary>
/// <param name="text">要扫描的文本</param>
/// <returns>所有匹配到的 PotentialMatch 列表</returns>
public List<PotentialMatch> Scan(string text)
{
var allPotentialMatches = new List<PotentialMatch>();
// 扫描所有题组模式
foreach (var patternConfig in _config.MajorQuestionGroupPatterns)
{
foreach (Match match in patternConfig.Regex.Matches(text))
{
allPotentialMatches.Add(new PotentialMatch
{
StartIndex = match.Index,
EndIndex = match.Index + match.Length,
MatchedText = match.Value,
RegexMatch = match,
PatternConfig = patternConfig,
Type = MatchType.MajorQuestionGroup
});
}
}
// 扫描所有题目模式
foreach (var patternConfig in _config.QuestionPatterns)
{
foreach (Match match in patternConfig.Regex.Matches(text))
{
allPotentialMatches.Add(new PotentialMatch
{
StartIndex = match.Index,
EndIndex = match.Index + match.Length,
MatchedText = match.Value,
RegexMatch = match,
PatternConfig = patternConfig,
Type = MatchType.Question
});
}
}
// 扫描所有选项模式
foreach (var patternConfig in _config.OptionPatterns)
{
foreach (Match match in patternConfig.Regex.Matches(text))
{
allPotentialMatches.Add(new PotentialMatch
{
StartIndex = match.Index,
EndIndex = match.Index + match.Length,
MatchedText = match.Value,
RegexMatch = match,
PatternConfig = patternConfig,
Type = MatchType.Option
});
}
}
// 统一按起始位置排序
return allPotentialMatches.OrderBy(pm => pm.StartIndex).ToList();
}
}
public class ExamStructureBuilder
{
private readonly ExamParserConfig _config;
public ExamStructureBuilder(ExamParserConfig config)
{
_config = config;
}
public ExamPaper BuildExamPaper(string fullExamText, List<PotentialMatch> allPotentialMatches)
{
var examPaper = new ExamPaper();
examPaper.Title = GetExamTitle(fullExamText);
var majorQGStack = new Stack<MajorQuestionGroup>();
MajorQuestionGroup currentMajorQG = null;
var questionStack = new Stack<Question>();
Question currentQuestion = null;
int currentContentStart = 0;
if (allPotentialMatches.Any() && allPotentialMatches[0].StartIndex > 0)
{
string introText = fullExamText.Substring(0, allPotentialMatches[0].StartIndex).Trim();
// 可以选择将这部分文本存储到 ExamPaper 的某个属性,例如 ExamPaper.Description
}
// 这里需要处理currentContentStart的位置,到allPotentialMatches[0].StartIndex
for (int i = 0; i < allPotentialMatches.Count; i++)
{
var pm = allPotentialMatches[i];
string precedingText = fullExamText.Substring(currentContentStart, pm.StartIndex - currentContentStart).Trim();
if (!string.IsNullOrWhiteSpace(precedingText))
{
if (currentQuestion != null)
{
ProcessQuestionContent(currentQuestion, precedingText,
GetSubMatchesForRange(allPotentialMatches, currentContentStart, pm.StartIndex));
}
else if (currentMajorQG != null)
{
currentMajorQG.Descript += (string.IsNullOrWhiteSpace(currentMajorQG.Descript) ? "" : "\n") + precedingText;
}
else
{
// 暂时忽略,或可以添加到 ExamPaper.Description
}
}
if (pm.Type == MatchType.MajorQuestionGroup)
{
// 1. 确定当前 MajorQuestionGroup 的层级关系
while (majorQGStack.Any() && pm.PatternConfig.Priority <= majorQGStack.Peek().Priority)
{
// 当前 QG 的优先级等于或高于栈顶 QG说明栈顶 QG 已经结束
majorQGStack.Pop();
}
MajorQuestionGroup newMajorQG = new MajorQuestionGroup
{
Title = pm.RegexMatch.Groups[1].Value.Trim(),
Score = (pm.RegexMatch.Groups.Count > 2 && pm.RegexMatch.Groups[2].Success) ? float.Parse(pm.RegexMatch.Groups[2].Value) : 0,
Priority = pm.PatternConfig.Priority
};
if (majorQGStack.Any())
{
majorQGStack.Peek().SubMajorQuestionGroups.Add(newMajorQG);
}
else
{
examPaper.MajorQuestionGroups.Add(newMajorQG);
}
majorQGStack.Push(newMajorQG);
currentMajorQG = newMajorQG;
questionStack.Clear();
currentQuestion = null;
}
else if (pm.Type == MatchType.Question)
{
// 1. 确定当前 Question 的层级关系(子题目)
// 找到比当前 Question 优先级高或相等的 Question 作为其父级
while (questionStack.Any() && pm.PatternConfig.Priority <= questionStack.Peek().Priority)
{
// 如果当前 Question 的优先级等于或高于栈顶 Question说明栈顶 Question 已经结束
questionStack.Pop();
}
Question newQuestion = new Question
{
Number = pm.RegexMatch.Groups[1].Value.Trim(),
Text = pm.RegexMatch.Groups[2].Value.Trim(),
Priority = pm.PatternConfig.Priority
};
if (pm.RegexMatch.Groups.Count > 2 && pm.RegexMatch.Groups[2].Success)
{
float.TryParse(pm.RegexMatch.Groups[2].Value, out float score);
newQuestion.Score = score;
}
if (questionStack.Any())
{
questionStack.Peek().SubQuestions.Add(newQuestion);
}
else if (currentMajorQG != null)
{
// 归属于当前活跃的 MajorQuestionGroup
currentMajorQG.Questions.Add(newQuestion);
}
else
{
// 没有活跃的 MajorQuestionGroup 或 Question作为 ExamPaper 的顶级 Questions
examPaper.TopLevelQuestions.Add(newQuestion);
}
questionStack.Push(newQuestion); // 新的 Question 入栈,成为当前活跃 Question
currentQuestion = newQuestion;
}
else if (pm.Type == MatchType.Option)
{
// 选项必须归属于一个题目
if (currentQuestion != null)
{
Option newOption = new Option
{
Label = pm.RegexMatch.Groups[1].Value.Trim(),
Text = pm.RegexMatch.Groups[2].Value.Trim()
};
currentQuestion.Options.Add(newOption);
}
else
{
// 孤立的选项,可能需要日志记录或错误处理
Console.WriteLine($"Warning: Found isolated Option at index {pm.StartIndex}: {pm.MatchedText}");
}
}
// --- 步骤3: 更新 currentContentStart 为当前匹配点的 EndIndex ---
// 下一次循环将从这里开始提取内容
currentContentStart = pm.EndIndex;
}
// --- 步骤4: 处理循环结束后,最后一个匹配点之后到文本末尾的剩余内容 ---
if (currentContentStart < fullExamText.Length)
{
string remainingText = fullExamText.Substring(currentContentStart).Trim();
if (!string.IsNullOrWhiteSpace(remainingText))
{
if (currentQuestion != null)
{
// 最后一个题目后面的内容(可能是选项或多行描述)
ProcessQuestionContent(currentQuestion, remainingText,
GetSubMatchesForRange(allPotentialMatches, currentContentStart, fullExamText.Length));
}
else if (currentMajorQG != null)
{
// 最后一个题组后面的内容(可能是描述或题目)
currentMajorQG.Descript += (string.IsNullOrWhiteSpace(currentMajorQG.Descript) ? "" : "\n") + remainingText;
}
else
{
// 顶级剩余文本,可能作为 ExamPaper 的整体描述
// examPaper.Description += remainingText;
}
}
}
return examPaper;
}
/// <summary>
/// 提取试卷标题 (简单实现)
/// </summary>
private string GetExamTitle(string examPaperText)
{
var firstLine = examPaperText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
.FirstOrDefault(line => !string.IsNullOrWhiteSpace(line));
return firstLine ?? "未识别试卷标题";
}
/// <summary>
/// 获取给定 PotentialMatch 列表在指定范围内的子集。
/// 这个方法用于辅助 ProcessQuestionContent为其提供该范围内的 Options 和 SubQuestions。
/// </summary>
private List<PotentialMatch> GetSubMatchesForRange(List<PotentialMatch> allMatches, int start, int end)
{
// 注意:这里需要考虑 potentialMatches 的索引与 fullExamText 索引的映射
// 这里的 StartIndex 是相对于 fullExamText 的
return allMatches.Where(pm => pm.StartIndex >= start && pm.StartIndex < end).ToList();
}
/// <summary>
/// 处理 Question 的内容,主要用于解析 Options 和识别非结构化文本。
/// </summary>
private void ProcessQuestionContent(Question question, string contentText, List<PotentialMatch> potentialMatchesInScope)
{
// 遍历当前范围内的所有 PotentialMatch找出 Options
var optionsText = new System.Text.StringBuilder();
int lastOptionEndIndex = 0; // 记录最后一个处理的选项的结束位置
foreach (var pm in potentialMatchesInScope.OrderBy(p => p.StartIndex))
{
// 检查是否是选项
if (pm.Type == MatchType.Option)
{
// 收集选项之间的文本作为题干的延续或描述
if (pm.StartIndex > lastOptionEndIndex)
{
string textBeforeOption = contentText.Substring(lastOptionEndIndex, pm.StartIndex - lastOptionEndIndex).Trim();
if (!string.IsNullOrWhiteSpace(textBeforeOption))
{
question.Text += (string.IsNullOrWhiteSpace(question.Text) ? "" : "\n") + textBeforeOption;
}
}
var newOption = new Option
{
Label = pm.RegexMatch.Groups[1].Value.Trim(),
Text = pm.RegexMatch.Groups[2].Value.Trim()
};
question.Options.Add(newOption);
lastOptionEndIndex = pm.EndIndex;
}
// TODO: 如果有 SubQuestion 类型,在这里也可以类似处理
// else if (pm.Type == MatchType.Question && pm.PatternConfig.Priority > question.Priority)
// {
// // 这是一个子题目,需要进一步解析
// // 递归调用但这里的逻辑会更复杂因为需要识别子题目自己的Options
// // 可能会在这里创建一个临时的 Question然后递归 ProcessQuestionContent
// }
}
// 处理所有选项之后剩余的文本
if (lastOptionEndIndex < contentText.Length)
{
string remainingContent = contentText.Substring(lastOptionEndIndex).Trim();
if (!string.IsNullOrWhiteSpace(remainingContent))
{
question.Text += (string.IsNullOrWhiteSpace(question.Text) ? "" : "\n") + remainingContent;
}
}
}
}
}

View File

@@ -0,0 +1,171 @@
using System.Xml.Serialization;
using TechHelper.Client.AI;
using TechHelper.Services;
using Entities.DTO;
namespace TechHelper.Client.Exam
{
public class ExamService : IExamService
{
private IAIService aIService;
public ExamService(IAIService aIService)
{
this.aIService = aIService;
}
public ApiResponse ConvertToXML<T>(string xmlContent)
{
string cleanedXml = xmlContent.Trim();
XmlSerializer serializer = new XmlSerializer(typeof(T));
using (StringReader reader = new StringReader(cleanedXml))
{
try
{
T deserializedObject = (T)serializer.Deserialize(reader);
// 成功时返回 ApiResponse
return new ApiResponse
{
Status = true,
Result = deserializedObject,
Message = "XML 反序列化成功。"
};
}
catch (InvalidOperationException ex)
{
return new ApiResponse
{
Status = false,
Result = null,
Message = $"XML 反序列化操作错误: {ex.Message}. 内部异常: {ex.InnerException?.Message ?? ""}"
};
}
catch (Exception ex)
{
return new ApiResponse
{
Status = false,
Result = null,
Message = $"处理 XML 反序列化时发生未知错误: {ex.Message}"
};
}
}
}
public async Task<ApiResponse> DividExam(string examContent)
{
try
{
string respon = await aIService.CallGLM(examContent, AIConfiguration.BreakQuestions);
if (respon != null)
{
return new ApiResponse
{
Status = true,
Result = respon,
Message = "试题分割成功。"
};
}
else
{
return new ApiResponse
{
Status = false,
Result = null,
Message = "AI 服务未能返回有效内容,或返回内容为空。"
};
}
}
catch (Exception ex)
{
return new ApiResponse
{
Status = false,
Result = null,
Message = $"处理试题分割时发生内部错误: {ex.Message}"
};
}
}
public async Task<ApiResponse> FormatExam(string examContent)
{
try
{
string respon = await aIService.CallGLM(examContent, AIConfiguration.Format);
if (respon != null)
{
return new ApiResponse
{
Status = true,
Result = respon,
Message = "试题格式化成功。"
};
}
else
{
return new ApiResponse
{
Status = false,
Result = null,
Message = "AI 服务未能返回有效内容,或返回内容为空。"
};
}
}
catch (Exception ex)
{
return new ApiResponse
{
Status = false,
Result = null,
Message = $"处理试题格式化时发生内部错误: {ex.Message}"
};
}
}
public async Task<ApiResponse> ParseSingleQuestionGroup(string examContent)
{
try
{
string respon = await aIService.CallGLM(examContent, AIConfiguration.ParseSignelQuestion2);
if (respon != null)
{
return new ApiResponse
{
Status = true,
Result = respon,
Message = "试题解析成功。"
};
}
else
{
return new ApiResponse
{
Status = false,
Result = null,
Message = "AI 服务未能返回有效内容,或返回内容为空。"
};
}
}
catch (Exception ex)
{
return new ApiResponse
{
Status = false,
Result = null,
Message = $"处理试题解析时发生内部错误: {ex.Message}"
};
}
}
public Task<ApiResponse> SaveParsedExam(ExamDto examDto)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,14 @@
using Entities.DTO;
using TechHelper.Services;
namespace TechHelper.Client.Exam
{
public interface IExamService
{
public Task<ApiResponse> FormatExam(string examContent);
public Task<ApiResponse> DividExam(string examContent);
public Task<ApiResponse> SaveParsedExam(ExamDto examDto);
public Task<ApiResponse> ParseSingleQuestionGroup(string examContent);
public ApiResponse ConvertToXML<T>(string xmlContent);
}
}

View File

@@ -5,29 +5,38 @@
<MudPopoverProvider />
<MudPaper Class="d-flex flex-column flex-grow-1" Style="height: 100vh;">
<MudPaper Class="d-flex flex-column flex-grow-1 overflow-hidden">
<MudPaper Style="position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: url('/ref/bg4.jpg');
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
filter: blur(10px);
z-index: -1;">
</MudPaper>
<MudPaper Class="d-flex flex-column flex-grow-0 overflow-auto" Style="height: 100vh; background-color:#22222200">
<MudPaper Height="5%" Class=" d-flex flex-grow-1" Style="background-color:mediumseagreen">
<MudSpacer> </MudSpacer>
<AuthLinks/>
<MudPaper Class="d-flex flex-column flex-grow-1 overflow-hidden" Style="background-color:transparent">
<MudPaper Elevation="3" Height="10%" Class=" d-flex justify-content-around flex-grow-0" Style="background-color:#ffffff55">
<NavBar Class="flex-column flex-grow-1 " Style="background-color:transparent" />
<AuthLinks Class="flex-column flex-grow-0 " Style="background-color:transparent" />
</MudPaper>
<MudPaper Height="95%" Class="d-flex flex-row flex-grow-1 overflow-hidden">
<MudPaper Elevation="3" Class="d-flex flex-row flex-grow-1 overflow-hidden" Style="background-color:transparent">
<MudPaper Width="5%" Class="pa-2 mr-1 d-flex flex-column flex-grow-0 justify-content-between">
<NavBar Class="flex-column flex-grow-0 rounded-pill" />
<AccountView Class="flex-column flex-grow-0 rounded-pill" />
<MudPaper Width="10%" Class="pa-2 ma-1 d-flex flex-column flex-grow-0 justify-content-between" Style="background-color:#ffffffaa">
</MudPaper>
<MudPaper Class="d-flex flex-grow-1 pa-3 ma-1 ">
<MudPaper Elevation="3" Class="d-flex flex-grow-1 pa-3 ma-1 overflow-hidden" Style="background-color:#ffffff22 ">
@Body
</MudPaper>

View File

@@ -1,13 +1,17 @@
<MudPaper Class=@Class>
<MudNavLink Icon="@Icons.Material.Filled.Home" Class="py-5 px-3" Href="" Match="NavLinkMatch.All"></MudNavLink>
<MudNavLink Icon="@Icons.Material.Filled.Person" Class="py-5 px-3" Href="Account/Manage"></MudNavLink>
<MudNavLink Icon="@Icons.Material.Filled.Edit" Class="py-5 px-3" Href="Edit"></MudNavLink>
<MudNavLink Icon="@Icons.Material.Filled.Air" Class="py-5 px-3" Href="ai"></MudNavLink>
<MudNavLink Icon="@Icons.Material.Filled.SportsTennis" Class="py-5 px-3" Href="test"></MudNavLink>
<MudPaper Class=@Class Style=@Style>
<MudStack Row="true">
<MudNavLink Class="py-5 px-3" Href="" Match="NavLinkMatch.All"> 主页 </MudNavLink>
<MudNavLink Class="py-5 px-3" Href="Account/Manage"> 个人中心 </MudNavLink>
<MudNavLink Class="py-5 px-3" Href="Edit"> 编辑器 </MudNavLink>
<MudNavLink Class="py-5 px-3" Href="ai"> AI </MudNavLink>
<MudNavLink Class="py-5 px-3" Href="test"> 测试页面 </MudNavLink>
</MudStack>
</MudPaper>
@code {
[Parameter]
public string? Class { get; set; }
[Parameter]
public string? Style { get; set; }
}

View File

@@ -1,4 +1,4 @@
<MudPaper Class=@Class>
<MudPaper Class=@Class Style="background-color:transparent">
<MudNavLink Icon="@Icons.Material.Filled.Settings" Href="" Match="NavLinkMatch.All" Class="py-5 px-3"></MudNavLink>
<MudNavLink Icon="@Icons.Material.Filled.Person4" Href="Account/Manage" Class="py-5 px-3"></MudNavLink>
</MudPaper>

View File

@@ -1,23 +1,31 @@
@inject IAuthenticationClientService AuthenticationClientService
@inject NavigationManager NavigationManager
<MudPaper Class=@Class Style=@Style>
<AuthorizeView>
<Authorized>
<MudText>
Hello, @context.User.Identity.Name!
</MudText>
<MudButton OnClick="Logout"> LOGOUT </MudButton>
</Authorized>
<NotAuthorized>
<MudButton Class="" Href="Register"> Register </MudButton>
<MudButton Class="" Href="Login"> Login </MudButton>
</NotAuthorized>
</AuthorizeView>
<AuthorizeView>
<Authorized>
<MudText>
Hello, @context.User.Identity.Name!
</MudText>
<MudButton OnClick="Logout"> LOGOUT </MudButton>
</Authorized>
<NotAuthorized>
<MudButton Class="" Href="Register"> Register </MudButton>
<MudButton Class="" Href="Login"> Login </MudButton>
</NotAuthorized>
</AuthorizeView>
</MudPaper>
@code {
[Parameter]
public string? Class { get; set; }
[Parameter]
public string? Style { get; set; }
private async Task Logout()
{
await AuthenticationClientService.LogoutAsync();

View File

@@ -2,85 +2,138 @@
@using Blazored.TextEditor
@using System.Text.RegularExpressions
@using TechHelper.Client.Pages.Exam
<MudPaper Class="d-flex flex-column flex-grow-1">
<MudPaper class="d-flex flex-grow-0 flex-column">
<MudPaper Class="d-flex flex-column flex-grow-1 pa-4" Elevation="0" Style="background-color:#ffffff55">
@if (@lode == true)
{
<MudStack Row="true">
<MudProgressLinear Color="Color.Primary" Indeterminate="true" />
</MudStack>
<MudPaper Class="d-flex flex-column flex-grow-0 mb-4" Elevation="1" Style="background-color:#FFFFFF22">
}
<MudButtonGroup Color="Color.Primary" Variant="Variant.Filled">
<MudButton OnClick="GetHTML">One</MudButton>
<MudButton OnClick="ParseQuestions">ParseQuestions</MudButton>
<MudButton OnClick="ParseXML">ParseXML</MudButton>
<MudButton OnClick="ParseWithAI">ParseWithAI</MudButton>
<MudButton OnClick="ReCorrectXMLAsync">ReCorrectXML</MudButton>
<MudButton OnClick="ReCorrectXMLAsync">AplyAIResult</MudButton>
<MudButton OnClick="ReCorrectXMLAsync">Save</MudButton>
<MudButton OnClick="ReCorrectXMLAsync">Public</MudButton>
<MudButton OnClick="CopyToClipboard">Copy</MudButton>
</MudButtonGroup>
<MudPaper Class="d-flex flex-row flex-grow-0 justify-content-between mb-4" Elevation="1" Style="background-color:#FFFFFF22">
<MudButtonGroup Variant="Variant.Filled" OverrideStyles="true" Class="pa-2">
<MudButton OnClick="TriggerFullAIParsingProcessAsync" Disabled="@_isProcessing"
Style="background-color: var(--mud-palette-primary); color: white;">
@if (_isProcessing)
{
<MudProgressCircular Indeterminate="true" Size="Size.Small" Class="mr-2" />
}
**全自动流程 (AI)**
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="GetEditorTextContentAsync" Disabled="@_isProcessing">
获取编辑器HTML
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="DivideExamContentByAIAsync" Disabled="@_isProcessing">
AI 分割题组 (仅文本)
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ConvertDividedXmlToQuestionList" Disabled="@_isProcessing">
转换为题组列表
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ParseEachQuestionGroupAsync" Disabled="@_isProcessing">
AI 解析每个题组 (仅文本)
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Secondary" OnClick="ConvertParsedXmlsToQuestionGroups" Disabled="@_isProcessing">
转换为题组对象
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Tertiary" OnClick="CopyToClipboard" Disabled="@_isProcessing">
复制当前结果
</MudButton>
</MudButtonGroup>
<MudButtonGroup Variant="Variant.Filled" OverrideStyles="true" Class="pa-2">
<MudButton Variant="Variant.Outlined" Color="Color.Info" Disabled="@_isProcessing">
保存
</MudButton>
<MudButton Variant="Variant.Outlined" Color="Color.Success" Disabled="@_isProcessing">
发布
</MudButton>
</MudButtonGroup>
</MudPaper>
<MudPaper Style="background-color:#FFFFFF22">
<MudText Typo="Typo.body2" Class="mt-2 ml-2">**当前状态:** @_processingStatusMessage</MudText>
</MudPaper>
</MudPaper>
<MudPaper Class="d-flex flex-row flex-grow-1 overflow-hidden">
<MudPaper Class="d-flex flex-row flex-grow-1 overflow-hidden" Elevation="0" Style="background-color:#FFFFFF77">
<MudPaper Class="d-flex flex-column flex-grow-1 mr-4" Style="min-width: 400px; max-width: 70%;background-color:#FFFFFFaa" Elevation="2">
<MudTabs Elevation="0" Rounded="true" PanelClass="pa-4 flex-grow-1 justify-content-around overflow-auto" Style="background-color:#FFFFFF11"
Class="flex-grow-1 d-flex flex-column overflow-auto">
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 overflow-auto">
<MudTabPanel Text="编辑器内容" Icon="@Icons.Material.Filled.Edit" Style="background-color:#FFFFFF11">
<MudText Typo="Typo.h6">编辑器原始HTML/文本内容:</MudText>
<MudTextField T="string" @bind-value="@_editorHtmlContent" MaxLines="20" Variant="Variant.Outlined" AutoGrow="true" />
</MudTabPanel>
<MudTabPanel Text="分割XML" Icon="@Icons.Material.Filled.Code">
<MudText Typo="Typo.h6">AI 分割后的原始XML内容:</MudText>
<MudTextField T="string" @bind-value="@_rawDividedExamXmlContent" MaxLines="20" Variant="Variant.Outlined" AutoGrow="true" />
</MudTabPanel>
@if (QuestionS != null && QuestionS.Any())
{
@foreach (var item in QuestionS)
{
<QuestionGroupDisplay QuestionGroup="item" IsNested="false" />
}
}
else
{
<MudText Typo="Typo.body1">暂无试题内容。</MudText>
}
<MudTabPanel Text="题组列表" Icon="@Icons.Material.Filled.List">
@if (_dividedQuestionGroupList != null && _dividedQuestionGroupList.Items.Any())
{
<MudText Typo="Typo.h6">转换为题组列表 (StringsList):</MudText>
@foreach (var item in _dividedQuestionGroupList.Items)
{
<MudTextField T="string" Value="@item" MaxLines="5" Variant="Variant.Outlined" Class="mb-2" AutoGrow="true" />
}
}
else
{
<MudText Typo="Typo.body1">将分割XML转换为题组列表 (StringsList) 后将显示在此处。</MudText>
}
</MudTabPanel>
@* Tab 4: 每个题组的原始 XML (Raw Parsed XMLs) *@
<MudTabPanel Text="解析XML" Icon="@Icons.Material.Filled.Article">
<ChildContent>
<MudText Typo="Typo.h6">AI 解析的每个题组原始XML内容:</MudText>
@for (int i = 0; i < _rawParsedQuestionXmls.Count; i++)
{
int index = i; // 捕获迭代变量
<MudCard Class="mb-3" Style="background-color:#ffffff88">
<MudCardHeader>
<MudCardActions>
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="(() => DeleteFromParse(index))">删除</MudButton>
</MudCardActions>
</MudCardHeader>
<MudCardContent>
<MudTextField Class="ma-0" AutoGrow="true" @bind-Value="_rawParsedQuestionXmls[index]" Variant="Variant.Outlined" />
</MudCardContent>
</MudCard>
}
</ChildContent>
</MudTabPanel>
@* Tab 5: 最终的 QuestionGroup 对象 *@
<MudTabPanel Text="最终结果" Icon="@Icons.Material.Filled.Check">
@if (_finalQuestionGroups != null && _finalQuestionGroups.Any())
{
<MudText Typo="Typo.h6">最终解析的题组对象:</MudText>
@foreach (var item in _finalQuestionGroups)
{
<QuestionGroupDisplay QuestionGroup="item" IsNested="false" />
}
}
else
{
<MudText Typo="Typo.body1">最终解析为 QuestionGroup 对象的试题内容将显示在此处。</MudText>
}
</MudTabPanel>
</MudTabs>
</MudPaper>
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 justify-content-between overflow-auto">
<MudText Typo="Typo.body1">@ProgStatues</MudText>
@for (int i = 0; i < ParseResult.Count; i++)
{
int index = i;
<MudCard Style="background-color:#ffffff88">
<MudCardHeader>
<MudCardActions>
<MudButton Variant="Variant.Filled" Color ="Color.Primary" OnClick="(()=>DeleteFromParse(index))"> Delete </MudButton>
</MudCardActions>
</MudCardHeader>
<MudCardContent>
<MudTextField Class="ma-3" AutoGrow="true" @bind-Value="ParseResult[index]"></MudTextField>
</MudCardContent>
</MudCard>
}
<MudText>@Error</MudText>
</MudPaper>
<MudPaper Width="33%" Class="d-flex flex-column flex-grow-1 overflow-auto">
<BlazoredTextEditor @ref="@QuillHtml">
<ToolbarContent>
<MudPaper Class="d-flex flex-column flex-grow-1" Style="min-width: 200px; max-width: 30%; background-color:#FFFFFF77;" Elevation="2">
<BlazoredTextEditor @ref="@_quillHtmlEditor" EditorCssStyle="height: 93%;" >
<ToolbarContent >
<select class="ql-header">
<option selected=""></option>
<option value="1"></option>
@@ -107,17 +160,10 @@
<button class="ql-link"></button>
</span>
</ToolbarContent>
<EditorContent>
<EditorContent >
</EditorContent>
</BlazoredTextEditor>
</MudPaper>
</MudPaper>
</MudPaper>

View File

@@ -1,172 +1,528 @@
using Blazored.TextEditor;
using Entities.Contracts;
using Entities.DTO;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using MudBlazor;
using System.Text.RegularExpressions;
using TechHelper.Client.AI;
using TechHelper.Client.Exam;
using TechHelper.Services;
using static Org.BouncyCastle.Crypto.Engines.SM2Engine;
namespace TechHelper.Client.Pages.Editor
{
public enum ProgEnum
public enum ProcessingStage
{
AIPrase,
AIRectify
Idle, // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
FetchingContent, // <20><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DividingExam, // <20><><EFBFBD>ڷָ<DAB7><D6B8><EFBFBD><EFBFBD><EFBFBD> (AI<41><49><EFBFBD><EFBFBD>ԭʼXML)
ConvertingDividedXml, // <20><><EFBFBD>ڽ<EFBFBD><DABD>ָ<EFBFBD>XMLת<4C><D7AA>ΪStringsList
ParsingGroups, // <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (AI<41><49><EFBFBD><EFBFBD>ԭʼXML)
ConvertingParsedXmls, // <20><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XMLת<4C><D7AA>ΪQuestionGroup<75><70><EFBFBD><EFBFBD>
Completed, // <20><><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ErrorOccurred, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Saving
}
public partial class EditorMain
{
private List<QuestionGroup> QuestionS = new List<QuestionGroup>();
private bool lode = false;
BlazoredTextEditor QuillHtml;
string QuillHTMLContent;
string AIParseResult;
string Error;
string ProgStatues = string.Empty;
List<string> ParseResult = new List<string>();
public async Task GetHTML()
{
QuillHTMLContent = await this.QuillHtml.GetHTML();
}
public async Task GetText()
{
QuillHTMLContent = await this.QuillHtml.GetText();
}
private string EditorHtmlContent { get; set; } = string.Empty;
private List<ParsedQuestion>? ParsedQuestions { get; set; }
private bool _parseAttempted = false;
public class ParsedQuestion
{
public int Id { get; set; } // <20><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public string? Content { get; set; } // <20><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTML <20><><EFBFBD><EFBFBD>
public string? Title { get; set; } // <20><>Ŀ<EFBFBD>ı<EFBFBD><C4B1>ⲿ<EFBFBD>֣<EFBFBD><D6A3><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>Դ<EFBFBD> Content <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1>
}
[Inject]
public IAIService aIService { get; set; }
public IExamService ExamService { get; set; } = default!;
[Inject]
public ISnackbar Snackbar { get; set; }
private async void ParseWithAI()
public ISnackbar Snackbar { get; set; } = default!;
// --- UI <20>󶨺<EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD> ---
private BlazoredTextEditor? _quillHtmlEditor; // <20><><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><E0BCAD>ʵ<EFBFBD><CAB5>
private string _editorHtmlContent = string.Empty; // <20><EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD> HTML/<2F>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
private bool _isProcessing = false; // <20><><EFBFBD>Ƽ<EFBFBD><C6BC><EFBFBD>״̬<D7B4>ı<EFBFBD>־
private string _processingStatusMessage = "<22>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>..."; // <20><>ʾ<EFBFBD><CABE><EFBFBD>û<EFBFBD><C3BB>ĵ<EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>״̬<D7B4><CCAC>Ϣ
// --- <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD>ݽṹ (<28>洢ÿһ<C3BF><D2BB><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD>ı<EFBFBD>) ---
// 1. AI <20>ָ<EFBFBD>ԭʼ<D4AD><CABC>Ӧ (XML <20>ı<EFBFBD>)
private string? _rawDividedExamXmlContent;
// 2. <20><> _rawDividedExamXmlContent ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> StringsList
private StringsList? _dividedQuestionGroupList;
// 3. AI <20><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC>Ӧ (XML <20>ı<EFBFBD><C4B1>б<EFBFBD>)
private List<string> _rawParsedQuestionXmls = new();
// 4. <20><> _rawParsedQuestionXmls ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> QuestionGroup <20><><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
private List<QuestionGroup> _finalQuestionGroups = new();
// --- Blazor <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD> ---
protected override void OnInitialized()
{
QuestionS.Clear();
ParseResult.Clear();
_processingStatusMessage = ProcessingStage.Idle.ToString();
}
await GetText();
lode = true;
// --- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ---
// ͳһ<CDB3><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󲢸<EFBFBD><F3B2A2B8><EFBFBD> UI
private void HandleProcessError(string errorMessage, Exception? ex = null)
{
_processingStatusMessage = $"{ProcessingStage.ErrorOccurred}: {errorMessage}";
Snackbar.Add(errorMessage, Severity.Error);
_isProcessing = false;
StateHasChanged();
ProgStatues = ProgEnum.AIPrase.ToString();
ProgStatues = $"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ȴ<EFBFBD>";
Snackbar.Add("<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ȴ<EFBFBD>", Severity.Info);
StateHasChanged();
string respon = await aIService.CallGLM(QuillHTMLContent, AIConfiguration.BreakQuestions);
if (respon == null)
if (ex != null)
{
lode = false;
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>");
return;
// <20><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD>ϸ<EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̨<EFBFBD><CCA8><EFBFBD><EFBFBD>־ϵͳ
Console.Error.WriteLine($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}\n{ex.StackTrace}\n<>ڲ<EFBFBD><DAB2>쳣: {ex.InnerException?.Message}");
}
}
var ParRespon = ExamParser.ParseExamXml<StringsList>(respon);
if (ParRespon != null)
{
int i = 1;
foreach (var item in ParRespon.Items)
{
ProgStatues = $"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>, <20><><EFBFBD>ȴ<EFBFBD>";
Snackbar.Add($"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>, <20><><EFBFBD>ȴ<EFBFBD>", Severity.Info);
StateHasChanged();
i++;
try
{
var parResult = await aIService.CallGLM(item, AIConfiguration.ParseSignelQuestion2);
ParseResult.Add(parResult);
}
catch (Exception ex)
{
Snackbar.Add($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>{i}<7D><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>Ժ<EFBFBD><D4BA><EFBFBD><EFBFBD><EFBFBD>. <20><><EFBFBD><EFBFBD>Ϊ:{ex.Message}", Severity.Error);
}
}
}
AIParseResult = respon;
ProgStatues = ProgEnum.AIRectify.ToString();
Snackbar.Add($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>", Severity.Info);
//await ReCorrectXMLAsync();
ProgStatues = string.Empty;
lode = false;
// <20><><EFBFBD>´<EFBFBD><C2B4><EFBFBD>״̬<D7B4><CCAC> UI
private void UpdateProcessingStatus(ProcessingStage stage, string message)
{
_processingStatusMessage = $"{stage}: {message}";
Snackbar.Add(message, Severity.Info);
StateHasChanged();
}
// --- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߷<EFBFBD><DFB7><EFBFBD> (<28><><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>) ---
private async Task ReCorrectXMLAsync()
// <20><>ȡ<EFBFBD><EFBFBD><E0BCAD> HTML <20><><EFBFBD><EFBFBD>
public async Task GetEditorHtmlContentAsync()
{
string respon = string.Empty;
if (_isProcessing) return;
_isProcessing = true;
UpdateProcessingStatus(ProcessingStage.FetchingContent, "<22><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><EFBFBD><E0BCAD>HTML<4D><4C><EFBFBD><EFBFBD>...");
try
{
foreach (var item in ParseResult)
if (_quillHtmlEditor != null)
{
//respon = await aIService.CallGLM(AIParseResult, AIConfiguration.ParseSignelQuestion);
var xmlResult = ExamParser.ParseExamXml<QuestionGroup>(item);
QuestionS.Add(xmlResult);
_editorHtmlContent = await _quillHtmlEditor.GetHTML();
UpdateProcessingStatus(ProcessingStage.FetchingContent, "<22><EFBFBD><E0BCAD>HTML<4D><4C><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9><EFBFBD>ȡ<EFBFBD><C8A1>");
}
else
{
HandleProcessError("<22><EFBFBD><E0BCAD>ʵ<EFBFBD><CAB5>δ׼<CEB4><D7BC><EFBFBD>ã<EFBFBD><C3A3>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݡ<EFBFBD>");
}
}
catch (Exception ex)
{
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>" + ex.Message, Severity.Error);
HandleProcessError($"<22><>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
if (string.IsNullOrEmpty(respon))
finally
{
lode = false;
Snackbar.Add("<22><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD>°<EFBFBD>", Severity.Error);
}
AIParseResult = respon;
}
private void ParseXML()
{
try
{
var paper = ExamParser.ParseExamXml<QuestionGroup>(AIParseResult);
//QuestionS = paper.QuestionGroups;
Error = string.Empty;
}
catch (InvalidOperationException ex)
{
Snackbar.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message, Severity.Error);
}
catch (Exception ex)
{
Snackbar.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>" + ex.Message, Severity.Error);
Error = ex.Message;
}
}
private void DeleteFromParse(int index)
{
if (index >= 0 && index < ParseResult.Count)
{
ParseResult.RemoveAt(index);
_isProcessing = false;
StateHasChanged();
}
}
// <20><>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>)
public async Task GetEditorTextContentAsync()
{
if (_isProcessing) return;
_isProcessing = true;
UpdateProcessingStatus(ProcessingStage.FetchingContent, "<22><><EFBFBD>ڻ<EFBFBD>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>...");
try
{
if (_quillHtmlEditor != null)
{
_editorHtmlContent = await _quillHtmlEditor.GetText();
UpdateProcessingStatus(ProcessingStage.FetchingContent, "<22><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9><EFBFBD>ȡ<EFBFBD><C8A1>");
}
else
{
HandleProcessError("<22><EFBFBD><E0BCAD>ʵ<EFBFBD><CAB5>δ׼<CEB4><D7BC><EFBFBD>ã<EFBFBD><C3A3>޷<EFBFBD><DEB7><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݡ<EFBFBD>");
}
}
catch (Exception ex)
{
HandleProcessError($"<22><>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false;
StateHasChanged();
}
}
// --- <20><><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD> (ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6BC><EFBFBD>ֶ<EFBFBD><D6B6><EFBFBD><EFBFBD><EFBFBD>) ---
// <20><><EFBFBD><EFBFBD> 1: <20><><EFBFBD><EFBFBD> AI <20><><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><><D6BB>ȡԭʼ XML <20>ı<EFBFBD>)
public async Task DivideExamContentByAIAsync()
{
if (_isProcessing) return;
_isProcessing = true;
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ˲<DAB4><CBB2><EFBFBD><EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD>
_rawDividedExamXmlContent = null;
_dividedQuestionGroupList = null;
_rawParsedQuestionXmls.Clear();
_finalQuestionGroups.Clear();
UpdateProcessingStatus(ProcessingStage.DividingExam, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AI <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD>ȴ<EFBFBD>...");
if (string.IsNullOrWhiteSpace(_editorHtmlContent))
{
HandleProcessError("<22><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>գ<EFBFBD><D5A3><EFBFBD><EFBFBD>Ȼ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ݡ<EFBFBD>");
return;
}
try
{
var response = await ExamService.DividExam(_editorHtmlContent);
if (!response.Status)
{
HandleProcessError(response.Message ?? "AI<41><49><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>", response.Result as Exception);
return;
}
// **<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC> XML <20>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ˲<DAB4><CBB2><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>**
_rawDividedExamXmlContent = response.Result as string;
if (string.IsNullOrWhiteSpace(_rawDividedExamXmlContent))
{
HandleProcessError("AI <20><><EFBFBD>񷵻صķָ<C4B7><D6B8><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ա<EFBFBD>");
return;
}
UpdateProcessingStatus(ProcessingStage.DividingExam, response.Message ?? "AI<41><49><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ɹ<EFBFBD><C9B9><EFBFBD>ԭʼXML<4D>ѱ<EFBFBD><D1B1>档");
}
catch (Exception ex)
{
HandleProcessError($"<22>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false;
StateHasChanged();
}
}
// <20><><EFBFBD><EFBFBD> 2: <20><>ԭʼ<D4AD>ָ<EFBFBD> XML <20>ı<EFBFBD>ת<EFBFBD><D7AA>Ϊ StringsList
public void ConvertDividedXmlToQuestionList()
{
if (_isProcessing) return; // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>UI<55><49><EFBFBD>ð<EFBFBD>ť<EFBFBD><C5A5><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD>
_isProcessing = true;
_dividedQuestionGroupList = null; // <20><><EFBFBD><EFBFBD><EFBFBD>ϴν<CFB4><CEBD><EFBFBD>
_rawParsedQuestionXmls.Clear();
_finalQuestionGroups.Clear();
UpdateProcessingStatus(ProcessingStage.ConvertingDividedXml, "<22><><EFBFBD>ڽ<EFBFBD><DABD>ָ<EFBFBD>XMLת<4C><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>...");
if (string.IsNullOrWhiteSpace(_rawDividedExamXmlContent))
{
HandleProcessError(<><C3BB>ԭʼ<D4AD>ָ<EFBFBD>XML<4D>ı<EFBFBD><C4B1>ɹ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4> '<27>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD> (AI)' <20><><EFBFBD>衣");
return;
}
try
{
// <20><><EFBFBD><EFBFBD> ExamService <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
var xmlConversionResponse = ExamService.ConvertToXML<StringsList>(_rawDividedExamXmlContent);
if (!xmlConversionResponse.Status)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼXMLת<4C><D7AA>ΪStringsListʧ<74>ܣ<EFBFBD><DCA3><EFBFBD>ԭʼXML<4D><4C>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>
HandleProcessError(xmlConversionResponse.Message ?? "AI<41><49><EFBFBD>ص<EFBFBD>XML<4D>޷<EFBFBD>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>", xmlConversionResponse.Result as Exception);
return;
}
_dividedQuestionGroupList = xmlConversionResponse.Result as StringsList;
if (_dividedQuestionGroupList == null || !_dividedQuestionGroupList.Items.Any())
{
HandleProcessError("AI <20><><EFBFBD>񷵻ص<F1B7B5BB>XML<4D><4C>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>Ϊ<EFBFBD>ա<EFBFBD>");
return;
}
UpdateProcessingStatus(ProcessingStage.ConvertingDividedXml, "<22>ָ<EFBFBD>XML<4D>ѳɹ<D1B3>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD>");
}
catch (Exception ex)
{
HandleProcessError($"ת<><D7AA><EFBFBD>ָ<EFBFBD>XML<4D><4C><EFBFBD>б<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false;
StateHasChanged();
}
}
// <20><><EFBFBD><EFBFBD> 3: ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6BB>ȡԭʼ XML <20>ı<EFBFBD>)
public async Task ParseEachQuestionGroupAsync()
{
if (_isProcessing) return;
_isProcessing = true;
_rawParsedQuestionXmls.Clear(); // <20><><EFBFBD><EFBFBD><EFBFBD>ϴν<CFB4><CEBD><EFBFBD>
_finalQuestionGroups.Clear();
UpdateProcessingStatus(ProcessingStage.ParsingGroups, "<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E9A3AC><EFBFBD>ȴ<EFBFBD>...");
if (_dividedQuestionGroupList == null || !_dividedQuestionGroupList.Items.Any())
{
HandleProcessError(<>пɽ<D0BF><C9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>' <20><><EFBFBD>衣");
return;
}
try
{
int currentGroupIndex = 1;
foreach (var itemXml in _dividedQuestionGroupList.Items)
{
UpdateProcessingStatus(ProcessingStage.ParsingGroups, $"<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD> {currentGroupIndex} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
var parseResponse = await ExamService.ParseSingleQuestionGroup(itemXml);
if (!parseResponse.Status)
{
// <20><>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD>ԭʼ<D4AD><CABC> _dividedQuestionGroupList <20><>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>
HandleProcessError($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> {currentGroupIndex} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>: {parseResponse.Message}", parseResponse.Result as Exception);
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʧ<C7B0>ܵ<EFBFBD><DCB5><EFBFBD><EEB2A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ֹͣ
return;
}
// **<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC> XML <20>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ˲<DAB4><CBB2><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>**
_rawParsedQuestionXmls.Add(parseResponse.Result as string ?? string.Empty);
UpdateProcessingStatus(ProcessingStage.ParsingGroups, $"<22><> {currentGroupIndex} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD>");
currentGroupIndex++;
}
UpdateProcessingStatus(ProcessingStage.ParsingGroups, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭʼXML<4D>ѱ<EFBFBD><D1B1>档");
}
catch (Exception ex)
{
HandleProcessError($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false;
StateHasChanged();
}
}
// <20><><EFBFBD><EFBFBD> 4: <20><>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD> XML <20>ı<EFBFBD>ת<EFBFBD><D7AA>Ϊ QuestionGroup <20><><EFBFBD><EFBFBD>
public void ConvertParsedXmlsToQuestionGroups()
{
if (_isProcessing) return; // <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
_isProcessing = true;
_finalQuestionGroups.Clear(); // <20><><EFBFBD><EFBFBD><EFBFBD>ϴν<CFB4><CEBD><EFBFBD>
UpdateProcessingStatus(ProcessingStage.ConvertingParsedXmls, "<22><><EFBFBD>ڽ<EFBFBD><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XMLת<4C><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȴ<EFBFBD>...");
if (!_rawParsedQuestionXmls.Any())
{
HandleProcessError(<>п<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD>ԭʼ<D4AD><CABC><EFBFBD><EFBFBD>XML<4D><4C><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4> '<27><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (AI)' <20><><EFBFBD>衣");
return;
}
try
{
foreach (var xmlString in _rawParsedQuestionXmls)
{
// <20><><EFBFBD><EFBFBD> ExamService <20><>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>
ApiResponse xmlConversionResponse = ExamService.ConvertToXML<QuestionGroup>(xmlString);
if (!xmlConversionResponse.Status)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>ʧ<EFBFBD>ܣ<EFBFBD><DCA3><EFBFBD>ԭʼXML<4D><4C>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD>
HandleProcessError($"XML ת<><D7AA>Ϊ QuestionGroup ʧ<><CAA7>: {xmlConversionResponse.Message}", xmlConversionResponse.Result as Exception);
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰʧ<C7B0>ܵ<EFBFBD><DCB5><EFBFBD><EEB2A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>ֹͣ
return;
}
QuestionGroup? questionGroup = xmlConversionResponse.Result as QuestionGroup;
if (questionGroup != null)
{
_finalQuestionGroups.Add(questionGroup);
}
else
{
// <20><>ʹ Status Ϊ true<75><65>Result Ҳ<><D2B2><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD>Ԥ<EFBFBD>ڵ<EFBFBD><DAB5><EFBFBD><EFBFBD><EFBFBD>
HandleProcessError("XML ת<><D7AA><EFBFBD>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͳ<EFBFBD>ƥ<EFBFBD><C6A5> QuestionGroup<75><70>");
return;
}
}
UpdateProcessingStatus(ProcessingStage.ConvertingParsedXmls, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XML<4D>ѳɹ<D1B3>ת<EFBFBD><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
}
catch (Exception ex)
{
HandleProcessError($"ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>XML<4D><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
if (_finalQuestionGroups.Count > 0)
OrderQuestionGroup(_finalQuestionGroups);
_isProcessing = false;
StateHasChanged();
}
}
private void OrderQuestionGroup(List<QuestionGroup> QG)
{
int index = 1;
QG.ForEach(qg =>
{
qg.Id = (byte)index++;
int sqIndex = 1;
qg.SubQuestions.ForEach(sq => sq.SubId = (byte)sqIndex++);
});
QG.ForEach(qg => OrderQuestionGroup(qg.SubQuestionGroups));
}
private ExamDto MapToCreateExamDto(List<QuestionGroup> questionGroups)
{
var createDto = new ExamDto();
createDto.QuestionGroups = MapQuestionGroupsToDto(questionGroups);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ҪΪ<D2AA><CEAA><EFBFBD>α<EFBFBD><CEB1><EFBFBD>ָ<EFBFBD><D6B8>һ<EFBFBD><D2BB>AssignmentId<49><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// createDto.AssignmentId = YourCurrentAssignmentId;
return createDto;
}
private List<QuestionGroupDto> MapQuestionGroupsToDto(List<QuestionGroup> qgs)
{
var dtos = new List<QuestionGroupDto>();
foreach (var qg in qgs)
{
var qgDto = new QuestionGroupDto
{
Title = qg.Title,
Score = qg.Score,
QuestionReference = qg.QuestionReference,
SubQuestions = MapSubQuestionsToDto(qg.SubQuestions),
SubQuestionGroups = MapQuestionGroupsToDto(qg.SubQuestionGroups)
};
dtos.Add(qgDto);
}
return dtos;
}
private List<SubQuestionDto> MapSubQuestionsToDto(List<SubQuestion> sqs)
{
var dtos = new List<SubQuestionDto>();
foreach (var sq in sqs)
{
var sqDto = new SubQuestionDto
{
Index = sq.SubId,
Stem = sq.Stem,
Score = sq.Score,
SampleAnswer = sq.SampleAnswer,
Options = sq.Options.Select(o => new OptionDto { Value = o.Value }).ToList(),
// TODO: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Щֵ<D0A9>ܴ<EFBFBD>AI<41><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ȡ
// <20><><EFBFBD>磺QuestionType = "SingleChoice",
// DifficultyLevel = "Medium",
// SubjectArea = "Math"
};
dtos.Add(sqDto);
}
return dtos;
}
public async Task Save()
{
if (_isProcessing) return;
_isProcessing = true;
UpdateProcessingStatus(ProcessingStage.Saving, "<22><><EFBFBD><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
if (!_finalQuestionGroups.Any())
{
HandleProcessError(<>пɱ<D0BF><C9B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD><DDA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>衣");
return;
}
try
{
// ȷ<><C8B7> _finalQuestionGroups <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD> Index <20><><EFBFBD><EFBFBD> (<28><><EFBFBD><EFBFBD>֮ǰ<D6AE><C7B0> ConvertParsedXmlsToQuestionGroups ֮<><D6AE><EFBFBD><EFBFBD> Save <20><>ʼʱ<CABC><CAB1><EFBFBD><EFBFBD>)
_finalQuestionGroups = _finalQuestionGroups.OrderBy(qg => qg.Id).ToList();
// ӳ<>䵽 DTO
var createExamDto = MapToCreateExamDto(_finalQuestionGroups);
// <20><><EFBFBD><EFBFBD> ExamService <20><><EFBFBD><EFBFBD> DTO
// <20><><EFBFBD><EFBFBD> ExamService <20><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> DTO
var response = await ExamService.SaveParsedExam(createExamDto);
if (!response.Status)
{
HandleProcessError(response.Message ?? "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E2B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܡ<EFBFBD>", response.Result as Exception);
return;
}
UpdateProcessingStatus(ProcessingStage.Saving, response.Message ?? "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9><EFBFBD><EFBFBD><EFBFBD><E6B5BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
Snackbar.Add("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѳɹ<D1B3><C9B9><EFBFBD><EFBFBD>档", Severity.Success);
}
catch (Exception ex)
{
HandleProcessError($"<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false;
StateHasChanged();
}
}
// --- ȫ<>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD> ---
// <20><><EFBFBD><EFBFBD> AI <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><>Զ<EFBFBD>)
public async Task TriggerFullAIParsingProcessAsync()
{
if (_isProcessing) return;
_isProcessing = true; // <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>״̬
// ȫ<><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD><EFBFBD>
_rawDividedExamXmlContent = null;
_dividedQuestionGroupList = null;
_rawParsedQuestionXmls.Clear();
_finalQuestionGroups.Clear();
UpdateProcessingStatus(ProcessingStage.Idle, "<22><>ʼȫ<CABC>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>...");
try
{
// 1. <20><>ȡ<EFBFBD><EFBFBD><E0BCAD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
await GetEditorTextContentAsync();
if (_processingStatusMessage.Contains(ProcessingStage.ErrorOccurred.ToString())) return;
// 2. <20><><EFBFBD><EFBFBD> AI <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD> (<28><>ȡԭʼ XML)
await DivideExamContentByAIAsync();
if (_processingStatusMessage.Contains(ProcessingStage.ErrorOccurred.ToString())) return;
// 3. ת<><D7AA><EFBFBD>ָ<EFBFBD> XML Ϊ StringsList
ConvertDividedXmlToQuestionList(); // ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (_processingStatusMessage.Contains(ProcessingStage.ErrorOccurred.ToString())) return;
// 4. ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (<28><>ȡԭʼ XML)
await ParseEachQuestionGroupAsync();
if (_processingStatusMessage.Contains(ProcessingStage.ErrorOccurred.ToString())) return;
// 5. ת<><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD> XML Ϊ QuestionGroup <20><><EFBFBD><EFBFBD>
ConvertParsedXmlsToQuestionGroups(); // ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if (_processingStatusMessage.Contains(ProcessingStage.ErrorOccurred.ToString())) return;
UpdateProcessingStatus(ProcessingStage.Completed, <>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD>");
}
catch (Exception ex)
{
HandleProcessError($"ȫ<>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD>δԤ<CEB4>ڴ<EFBFBD><DAB4><EFBFBD>: {ex.Message}", ex);
}
finally
{
_isProcessing = false; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
StateHasChanged();
}
}
private void DeleteFromParse(int index)
{
if (index >= 0 && index < _finalQuestionGroups.Count)
{
_finalQuestionGroups.RemoveAt(index);
StateHasChanged();
}
}
#region JS
[Inject]
public IJSRuntime JSRuntime { get; set; }
@@ -199,60 +555,7 @@ namespace TechHelper.Client.Pages.Editor
Console.WriteLine($"<22><><EFBFBD>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>: {ex.Message}");
}
}
private void ParseQuestions()
{
ParsedQuestions = new List<ParsedQuestion>();
_parseAttempted = true;
if (string.IsNullOrWhiteSpace(QuillHTMLContent))
{
return;
}
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD><C4BF>ʼ<EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
string startTag = "[<5B><>Ŀ<EFBFBD><C4BF>ʼ]";
string endTag = "[<5B><>Ŀ<EFBFBD><C4BF><EFBFBD><EFBFBD>]";
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ƥ<EFBFBD><C6A5><EFBFBD>ӿ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>ǵ<EFBFBD><C7B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD>
// (?s) <20><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD> . ƥ<><EFBFBD>з<EFBFBD>
string pattern = Regex.Escape(startTag) + "(.*?)" + Regex.Escape(endTag);
var matches = Regex.Matches(QuillHTMLContent, pattern, RegexOptions.Singleline);
int questionId = 1;
foreach (Match match in matches)
{
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
string rawQuestionHtml = match.Groups[1].Value;
// <20>Ƴ<EFBFBD><C6B3><EFBFBD><EFBFBD>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еı<D0B5><C4B1>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD>Ѿ<EFBFBD><D1BE>ų<EFBFBD><C5B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǣ<EFBFBD><C7A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
string cleanedQuestionContent = rawQuestionHtml
.Replace(startTag, "")
.Replace(endTag, "")
.Trim();
// <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><E2A3A8><EFBFBD>磬ƥ<E7A3AC>һ<E4A1B0><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>У<EFBFBD>
string? questionTitle = null;
try
{
var firstLineMatch = Regex.Match(cleanedQuestionContent, @"^(<p>)?\s*([һ<><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߰˾<DFB0>ʮ]+\s*[<5B><><EFBFBD><EFBFBD>]|\d+\s*[<5B><>\.]).*?</p>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
if (firstLineMatch.Success)
{
// <20><> HTML <20><><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>
questionTitle = Regex.Replace(firstLineMatch.Value, "<[^>]*>", "").Trim();
}
}
catch (Exception ex) { }
ParsedQuestions.Add(new ParsedQuestion
{
Id = questionId++,
Content = cleanedQuestionContent,
Title = questionTitle
});
}
}
#endregion
}
}

View File

@@ -1,41 +1,45 @@
@using TechHelper.Client.Exam
<MudCard Class="@(IsNested ? "mb-3 pa-2" : "my-4")" Outlined="@IsNested">
@* 嵌套时添加边框和内边距 *@
<MudCardHeader>
<MudStack>
@if (QuestionGroup.Title != string.Empty)
{
<MudCardHeader>
<MudStack>
<MudStack Row="true" AlignItems="AlignItems.Center">
<MudText Typo="@(IsNested ? Typo.h6 : Typo.h5)">@QuestionGroup.Id. </MudText> @* 嵌套时字号稍小 *@
<MudText Typo="@(IsNested ? Typo.h6 : Typo.h5)">@QuestionGroup.Title</MudText>
<MudStack Row="true" AlignItems="AlignItems.Center">
<MudText Typo="@(IsNested ? Typo.h6 : Typo.h5)">@QuestionGroup.Id. </MudText> @* 嵌套时字号稍小 *@
<MudText Typo="@(IsNested ? Typo.h6 : Typo.h5)">@QuestionGroup.Title</MudText>
</MudStack>
@if (!string.IsNullOrEmpty(QuestionGroup.QuestionReference))
{
<MudText Class="mt-2" Style="white-space: pre-wrap;">@QuestionGroup.QuestionReference</MudText>
}
</MudStack>
@if (!string.IsNullOrEmpty(QuestionGroup.QuestionReference))
{
<MudText Class="mt-2" Style="white-space: pre-wrap;">@QuestionGroup.QuestionReference</MudText>
}
</MudStack>
</MudCardHeader>
</MudCardHeader>
}
<MudCardContent>
@* 渲染直接子题目 *@
@if (QuestionGroup.SubQuestions != null && QuestionGroup.SubQuestions.Any())
{
@if (!IsNested) // 只有顶级大题才显示“子题目”标题
{
<MudText Typo="Typo.subtitle1" Class="mb-2">题目详情:</MudText>
}
@foreach (var qitem in QuestionGroup.SubQuestions)
{
<MudStack Row="true" AlignItems="AlignItems.Baseline" Class="mb-2">
<MudText Typo="Typo.body1">@qitem.SubId. </MudText>
<MudText Typo="Typo.body1">@qitem.Stem</MudText>
</MudStack>
@if (qitem.Options != null && qitem.Options.Any())
{
@foreach (var oitem in qitem.Options)
{
<MudText Typo="Typo.body2" Class="ml-6 mb-2">@oitem.Value</MudText>
}
}
@if (!string.IsNullOrEmpty(qitem.SampleAnswer))
{
<MudText Typo="Typo.body2" Color="Color.Tertiary" Class="ml-6 mb-2">示例答案: @qitem.SampleAnswer</MudText>
}
@if (qitem.Options != null && qitem.Options.Any())
{
}
}
}

View File

@@ -13,6 +13,7 @@ using TechHelper.Client.Services;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using TechHelper.Client.AI;
using TechHelper.Client.Exam;
var builder = WebAssemblyHostBuilder.CreateDefault(args);
@@ -30,6 +31,7 @@ builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddLocalStorageServices();
builder.Services.AddScoped<IAuthenticationClientService, AuthenticationClientService>();
builder.Services.AddScoped<IExamService, ExamService>();
builder.Services.AddScoped<AuthenticationStateProvider, AuthStateProvider>();
builder.Services.Configure<ApiConfiguration>(builder.Configuration.GetSection("ApiConfiguration"));
builder.Services.AddScoped<RefreshTokenService>();

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 285 KiB