修正獎勵評審資訊、評分資訊
This commit is contained in:
@@ -149,9 +149,12 @@ export async function GET(request: NextRequest) {
|
||||
competitionId: award.competition_id,
|
||||
competitionName: (award as any).competition_name,
|
||||
competitionType: (award as any).competition_type,
|
||||
competitionDescription: (award as any).competition_description,
|
||||
competitionStartDate: (award as any).competition_start_date,
|
||||
competitionEndDate: (award as any).competition_end_date,
|
||||
awardName: award.award_name,
|
||||
awardType: award.award_type,
|
||||
teamName: award.team_name,
|
||||
teamName: (award as any).team_name_from_teams || award.team_name,
|
||||
appName: award.app_name,
|
||||
applicationLinks: award.application_links ? JSON.parse(award.application_links) : null,
|
||||
documents: award.documents ? JSON.parse(award.documents) : [],
|
||||
|
211
app/api/awards/[id]/scores/route.ts
Normal file
211
app/api/awards/[id]/scores/route.ts
Normal file
@@ -0,0 +1,211 @@
|
||||
// =====================================================
|
||||
// 獲取獎項評分詳情 API
|
||||
// =====================================================
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { db } from '@/lib/database';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
try {
|
||||
const awardId = params.id;
|
||||
|
||||
console.log('🔍 獲取獎項評分詳情:', awardId);
|
||||
|
||||
// 先獲取獎項資訊
|
||||
const awardSql = 'SELECT * FROM awards WHERE id = ?';
|
||||
console.log('🔍 執行 SQL:', awardSql, '參數:', [awardId]);
|
||||
|
||||
const award = await db.queryOne(awardSql, [awardId]);
|
||||
console.log('📊 查詢結果:', award);
|
||||
|
||||
if (!award) {
|
||||
console.log('❌ 找不到獎項:', awardId);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '找不到指定的獎項',
|
||||
data: []
|
||||
});
|
||||
}
|
||||
|
||||
console.log('📊 獎項資訊:', {
|
||||
id: award.id,
|
||||
competitionType: award.competition_type,
|
||||
appId: award.app_id,
|
||||
proposalId: award.proposal_id
|
||||
});
|
||||
|
||||
let scores = [];
|
||||
|
||||
// 根據競賽類型查詢對應的評分表
|
||||
if (award.competition_type === 'individual' && award.app_id) {
|
||||
// 查詢 app_judge_scores
|
||||
const sql = `
|
||||
SELECT
|
||||
ajs.*,
|
||||
j.name as judge_name,
|
||||
j.title as judge_title,
|
||||
j.avatar as judge_avatar,
|
||||
j.department as judge_department
|
||||
FROM app_judge_scores ajs
|
||||
LEFT JOIN judges j ON ajs.judge_id = j.id
|
||||
WHERE ajs.app_id = ?
|
||||
ORDER BY ajs.created_at DESC
|
||||
`;
|
||||
console.log('🔍 執行個人賽 SQL:', sql, '參數:', [award.app_id]);
|
||||
scores = await db.query(sql, [award.app_id]);
|
||||
console.log('📊 從 app_judge_scores 獲取到:', scores.length, '筆');
|
||||
} else if (award.competition_type === 'proposal' && award.proposal_id) {
|
||||
// 查詢 proposal_judge_scores
|
||||
const sql = `
|
||||
SELECT
|
||||
pjs.*,
|
||||
j.name as judge_name,
|
||||
j.title as judge_title,
|
||||
j.avatar as judge_avatar,
|
||||
j.department as judge_department
|
||||
FROM proposal_judge_scores pjs
|
||||
LEFT JOIN judges j ON pjs.judge_id = j.id
|
||||
WHERE pjs.proposal_id = ?
|
||||
ORDER BY pjs.created_at DESC
|
||||
`;
|
||||
console.log('🔍 執行提案賽 SQL:', sql, '參數:', [award.proposal_id]);
|
||||
scores = await db.query(sql, [award.proposal_id]);
|
||||
console.log('📊 從 proposal_judge_scores 獲取到:', scores.length, '筆');
|
||||
} else if (award.competition_type === 'team' && award.app_id) {
|
||||
// 查詢 judge_scores (團隊賽)
|
||||
const sql = `
|
||||
SELECT
|
||||
js.*,
|
||||
j.name as judge_name,
|
||||
j.title as judge_title,
|
||||
j.avatar as judge_avatar,
|
||||
j.department as judge_department
|
||||
FROM judge_scores js
|
||||
LEFT JOIN judges j ON js.judge_id = j.id
|
||||
WHERE js.app_id = ?
|
||||
ORDER BY js.submitted_at DESC
|
||||
`;
|
||||
console.log('🔍 執行團隊賽 SQL:', sql, '參數:', [award.app_id]);
|
||||
scores = await db.query(sql, [award.app_id]);
|
||||
console.log('📊 從 judge_scores 獲取到:', scores.length, '筆');
|
||||
} else {
|
||||
console.log('❌ 無法確定評分表類型:', {
|
||||
competitionType: award.competition_type,
|
||||
hasAppId: !!award.app_id,
|
||||
hasProposalId: !!award.proposal_id,
|
||||
hasTeamId: !!award.team_id
|
||||
});
|
||||
}
|
||||
|
||||
// 處理評分資料
|
||||
const processedScores = scores.map((score: any) => {
|
||||
// 根據不同的評分表處理不同的欄位
|
||||
let overallScore = 0;
|
||||
let criteria: Array<{name: string, score: number, maxScore: number}> = [];
|
||||
|
||||
if (award.competition_type === 'individual') {
|
||||
// app_judge_scores 的處理
|
||||
overallScore = score.total_score || 0;
|
||||
criteria = [
|
||||
{ name: '創新性', score: score.innovation_score, maxScore: 10 },
|
||||
{ name: '技術性', score: score.technical_score, maxScore: 10 },
|
||||
{ name: '可用性', score: score.usability_score, maxScore: 10 },
|
||||
{ name: '展示性', score: score.presentation_score, maxScore: 10 },
|
||||
{ name: '影響力', score: score.impact_score, maxScore: 10 }
|
||||
];
|
||||
} else if (award.competition_type === 'proposal') {
|
||||
// proposal_judge_scores 的處理
|
||||
overallScore = score.total_score || 0;
|
||||
criteria = [
|
||||
{ name: '問題識別', score: score.problem_identification_score, maxScore: 10 },
|
||||
{ name: '解決方案可行性', score: score.solution_feasibility_score, maxScore: 10 },
|
||||
{ name: '創新性', score: score.innovation_score, maxScore: 10 },
|
||||
{ name: '影響力', score: score.impact_score, maxScore: 10 },
|
||||
{ name: '展示性', score: score.presentation_score, maxScore: 10 }
|
||||
];
|
||||
} else if (award.competition_type === 'team') {
|
||||
// judge_scores (團隊賽) 的處理
|
||||
overallScore = score.overall_score || score.total_score || 0;
|
||||
// 嘗試解析 criteria 欄位,如果沒有則使用預設的團隊評分標準
|
||||
if (score.criteria) {
|
||||
try {
|
||||
criteria = typeof score.criteria === 'string'
|
||||
? JSON.parse(score.criteria)
|
||||
: score.criteria;
|
||||
} catch (e) {
|
||||
console.error('解析 criteria 失敗:', e);
|
||||
criteria = [];
|
||||
}
|
||||
}
|
||||
|
||||
// 如果沒有 criteria 或解析失敗,使用預設的團隊評分標準
|
||||
if (!criteria || criteria.length === 0) {
|
||||
criteria = [
|
||||
{ name: '團隊合作', score: score.teamwork_score || 0, maxScore: 10 },
|
||||
{ name: '創新性', score: score.innovation_score || 0, maxScore: 10 },
|
||||
{ name: '技術實作', score: score.technical_score || 0, maxScore: 10 },
|
||||
{ name: '展示能力', score: score.presentation_score || 0, maxScore: 10 },
|
||||
{ name: '整體表現', score: score.overall_performance || 0, maxScore: 10 }
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: score.id,
|
||||
awardId: awardId,
|
||||
judgeId: score.judge_id,
|
||||
judgeName: score.judge_name || '未知評審',
|
||||
judgeTitle: score.judge_title || '評審',
|
||||
judgeAvatar: score.judge_avatar,
|
||||
judgeDepartment: score.judge_department,
|
||||
overallScore: overallScore,
|
||||
submittedAt: score.submitted_at || score.created_at,
|
||||
comment: score.comment || score.comments || '',
|
||||
criteria: criteria,
|
||||
};
|
||||
});
|
||||
|
||||
console.log('✅ 處理後的評分資料:', processedScores.length, '筆');
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '評分詳情獲取成功',
|
||||
data: processedScores
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 獲取評分詳情失敗:', error);
|
||||
console.error('❌ 錯誤詳情:', {
|
||||
message: error instanceof Error ? error.message : '未知錯誤',
|
||||
stack: error instanceof Error ? error.stack : undefined,
|
||||
awardId: params.id
|
||||
});
|
||||
|
||||
// 檢查評分表是否存在
|
||||
try {
|
||||
const tableCheck = await db.query("SHOW TABLES LIKE 'judge_scores'");
|
||||
console.log('🔍 judge_scores 表存在檢查:', tableCheck);
|
||||
|
||||
if (tableCheck.length > 0) {
|
||||
// 檢查表結構
|
||||
const structure = await db.query("DESCRIBE judge_scores");
|
||||
console.log('🔍 judge_scores 表結構:', structure);
|
||||
}
|
||||
} catch (tableError) {
|
||||
console.error('❌ 檢查表存在性失敗:', tableError);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '獲取評分詳情失敗',
|
||||
error: error instanceof Error ? error.message : '未知錯誤',
|
||||
details: {
|
||||
awardId: params.id,
|
||||
errorType: error instanceof Error ? error.constructor.name : 'Unknown'
|
||||
}
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user