完整呈現 AI 評審結果和詳細資訊

This commit is contained in:
2025-09-23 23:10:12 +08:00
parent f018e71577
commit 7bfedc4162
6 changed files with 157 additions and 331 deletions

View File

@@ -119,34 +119,167 @@ export async function GET(
// 整體改進建議 - evaluation_feedback 的第一筆 overall
overallSuggestions: feedbackByType.overall[0]?.content || '無改進建議',
// 繼續保持的優勢 - evaluation_feedback 的 strength
// 繼續保持的優勢 - evaluation_feedback 的 feedback_type = strength 且 criteria_item_id 是 null 的全部資料
maintainStrengths: feedbackByType.strength
.filter(f => f.criteria_item_id) // 只取 criteria_item_id 的
.map(f => ({
title: f.criteria_item_name || '優勢',
description: f.content || '無描述'
}))
.filter((item, index, arr) => arr.findIndex(i => i.title === item.title) === index), // 去重
.filter(f => f.criteria_item_id === null) // 只取 criteria_item_id 是 null
.map(f => {
const content = f.content || '無描述';
const colonIndex = content.indexOf(':');
const title = colonIndex > -1 ? content.substring(0, colonIndex + 1) : '系統優勢:';
const description = colonIndex > -1 ? content.substring(colonIndex + 1).trim() : content;
return {
title: title,
description: description
};
}),
// 重點改進方向 - evaluation_feedback 的 improvement (除了最後3筆)
keyImprovements: feedbackByType.improvement
.filter(f => f.criteria_item_id) // 只取有 criteria_item_id 的
.slice(0, -3) // 排除最後3筆
.map(f => ({
title: f.criteria_item_name || '改進項目',
description: f.content || '無描述',
suggestions: [f.content || '無建議']
}))
.filter((item, index, arr) => arr.findIndex(i => i.title === item.title) === index), // 去重
// 重點改進方向 - evaluation_feedback 的 feedback_type = improvement 且 criteria_item_id 是 null 的全部資料,但不能有最後 3 筆數據,也不能是第一筆
keyImprovements: (() => {
const allImprovementData = feedbackByType.improvement
.filter(f => f.criteria_item_id === null); // 只取 criteria_item_id 是 null 的
// 如果數據不足5筆則不進行過濾直接使用所有數據
const improvementData = allImprovementData.length >= 5
? allImprovementData.slice(1, -3) // 排除第一筆和最後3筆
: allImprovementData; // 數據不足時使用所有數據
// 分組處理 - 先收集所有組,然後合併相同標題的組
const tempGroups = [];
let currentGroup = null;
for (const item of improvementData) {
const content = item.content || '';
const colonIndex = content.indexOf(':');
if (colonIndex > -1) {
// 有冒號的情況
const title = content.substring(0, colonIndex + 1);
const remainingContent = content.substring(colonIndex + 1).trim();
// 檢查是否包含小標題 "建議:"
const suggestionIndex = remainingContent.indexOf('建議:');
if (suggestionIndex > -1) {
// 如果有小標題,開始新的 group
if (currentGroup) {
tempGroups.push(currentGroup);
}
currentGroup = {
title: title,
subtitle: '建議:',
suggestions: []
};
// 處理建議後面的內容
const suggestionsText = remainingContent.substring(suggestionIndex + 3).trim();
const suggestions = suggestionsText.split('\n')
.map(s => s.trim())
.filter(s => s.startsWith('•'))
.map(s => s.substring(1).trim());
currentGroup.suggestions = suggestions;
} else if (remainingContent.startsWith('•')) {
// 如果是條列資料,添加到當前 group
if (currentGroup) {
const suggestion = remainingContent.substring(1).trim();
currentGroup.suggestions.push(suggestion);
}
} else {
// 如果是普通描述,創建簡單的 group
if (currentGroup) {
tempGroups.push(currentGroup);
}
currentGroup = {
title: title,
subtitle: '',
suggestions: [remainingContent]
};
}
} else {
// 沒有冒號的情況,創建簡單的 group
if (currentGroup) {
tempGroups.push(currentGroup);
}
// 檢查內容是否以 • 開頭
if (content.startsWith('•')) {
// 如果是條列資料,添加到當前 group
if (currentGroup) {
const suggestion = content.substring(1).trim();
currentGroup.suggestions.push(suggestion);
} else {
// 如果沒有當前 group創建一個
currentGroup = {
title: '改進方向:',
subtitle: '',
suggestions: [content.substring(1).trim()]
};
}
} else {
// 如果是普通描述,創建新的 group將內容作為描述而不是條列建議
currentGroup = {
title: '改進方向:',
subtitle: '',
description: content,
suggestions: []
};
}
}
}
// 添加最後一個 group
if (currentGroup) {
tempGroups.push(currentGroup);
}
// 合併相同標題的組
const groups = [];
const groupMap = new Map();
for (const group of tempGroups) {
if (groupMap.has(group.title)) {
// 合併到現有組
const existingGroup = groupMap.get(group.title);
if (group.suggestions && group.suggestions.length > 0) {
// 合併建議並去重
const allSuggestions = [...(existingGroup.suggestions || []), ...group.suggestions];
existingGroup.suggestions = [...new Set(allSuggestions)]; // 使用 Set 去重
}
if (group.description) {
existingGroup.description = group.description;
}
} else {
// 創建新組
groupMap.set(group.title, { ...group });
}
}
// 將合併後的組添加到結果數組
for (const group of groupMap.values()) {
groups.push(group);
}
return groups;
})(),
// 下一步行動計劃 - evaluation_feedback 的 improvement 最後3筆
// 下一步行動計劃 - evaluation_feedback 的 feedback_type = improvement 且 criteria_item_id 是 null 的最後 3 筆數據
actionPlan: feedbackByType.improvement
.filter(f => f.criteria_item_id) // 只取 criteria_item_id 的
.filter(f => f.criteria_item_id === null) // 只取 criteria_item_id 是 null
.slice(-3) // 取最後3筆
.map((f, index) => ({
phase: `階段 ${index + 1}`,
description: f.content || '無描述'
}))
.map((f, index) => {
const content = f.content || '無描述';
const colonIndex = content.indexOf(':');
const phase = colonIndex > -1 ? content.substring(0, colonIndex + 1) : `階段 ${index + 1}:`;
const description = colonIndex > -1 ? content.substring(colonIndex + 1).trim() : content;
return {
phase: phase,
description: description
};
})
},
chartData: chartData
};
@@ -165,4 +298,4 @@ export async function GET(
{ status: 500 }
);
}
}
}