fix: TRUE/FALSE题型答案映射修复 — 纯文本答案转选项字母

问题: TRUE/FALSE题 stored as MULTIPLE_CHOICE, correctAnswer='TRUE'/'FALSE'
charCodeAt(0)-65 => 'T'=19, 超出选项范围(0-1)
从来没有任何TRUE/FALSE题被正确评分过

修复: 在assessment.service.ts中检测correctAnswer为纯文本(4字符以上)时
查找匹配的选项文本并转换为字母索引

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Developer
2026-06-17 14:18:36 +08:00
parent de5c008306
commit 93255c28dd
@@ -570,6 +570,14 @@ private async getModel(tenantId: string): Promise<ChatOpenAI> {
if (item.questionType === 'MULTIPLE_CHOICE' && options && options.length > 0 && correctAnswer) {
const labels = ['A', 'B', 'C', 'D'];
const optTexts = options.map((o: string) => o.replace(/^[A-D][.)、]\s*/, ''));
// 修复: 当 correctAnswer 是文本(TRUE/FALSE)而非字母(A-D)时,
// 找到匹配的选项文本并转换为字母
if (/^[A-Z]{4,}$/i.test(correctAnswer!)) {
const textIdx = optTexts.findIndex(t => t.trim().toUpperCase() === correctAnswer!.toUpperCase());
if (textIdx >= 0) {
correctAnswer = labels[textIdx];
}
}
const correctIdx = correctAnswer.charCodeAt(0) - 65;
const correctText = correctIdx >= 0 && correctIdx < optTexts.length ? optTexts[correctIdx] : null;
const indices = optTexts.map((_: any, i: number) => i);