修正評審評分機制問題

This commit is contained in:
2025-09-21 20:57:14 +08:00
parent f6abef38e9
commit 36e29c5a3f
6 changed files with 244 additions and 43 deletions

View File

@@ -960,11 +960,16 @@ export class JudgeService extends DatabaseServiceBase {
// 獲取評審的評分任務
static async getJudgeScoringTasks(judgeId: string, competitionId?: string): Promise<any[]> {
console.log('🔍 JudgeService.getJudgeScoringTasks 被調用');
console.log('judgeId:', judgeId);
console.log('competitionId:', competitionId);
let sql: string;
let params: any[];
if (competitionId) {
// 獲取特定競賽的評分任務
// 使用 UNION 來合併個人競賽和團隊競賽的應用程式
sql = `
SELECT DISTINCT
a.id,
@@ -977,16 +982,37 @@ export class JudgeService extends DatabaseServiceBase {
ELSE 'pending'
END as status,
js.submitted_at,
t.name as team_name,
NULL as team_name,
a.name as display_name
FROM apps a
INNER JOIN competition_apps ca ON a.id = ca.app_id
LEFT JOIN app_judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE ca.competition_id = ? AND a.is_active = 1
UNION ALL
SELECT DISTINCT
a.id,
a.name,
'app' as type,
'team' as participant_type,
COALESCE(js.total_score, 0) as score,
CASE
WHEN js.total_score > 0 THEN 'completed'
ELSE 'pending'
END as status,
js.submitted_at,
t.name as team_name,
CONCAT(t.name, ' - ', a.name) as display_name
FROM apps a
INNER JOIN competition_teams ct ON a.team_id = ct.team_id
LEFT JOIN teams t ON a.team_id = t.id
LEFT JOIN competition_apps ca ON a.id = ca.app_id
LEFT JOIN judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE ca.competition_id = ?
ORDER BY a.name
LEFT JOIN app_judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE ct.competition_id = ? AND a.is_active = 1
ORDER BY display_name
`;
params = [judgeId, competitionId];
params = [judgeId, competitionId, judgeId, competitionId];
} else {
// 獲取所有競賽的任務
sql = `
@@ -1001,19 +1027,46 @@ export class JudgeService extends DatabaseServiceBase {
ELSE 'pending'
END as status,
js.submitted_at,
t.name as team_name,
NULL as team_name,
a.name as display_name
FROM apps a
INNER JOIN competition_apps ca ON a.id = ca.app_id
LEFT JOIN app_judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE a.is_active = 1
UNION ALL
SELECT DISTINCT
a.id,
a.name,
'app' as type,
'team' as participant_type,
COALESCE(js.total_score, 0) as score,
CASE
WHEN js.total_score > 0 THEN 'completed'
ELSE 'pending'
END as status,
js.submitted_at,
t.name as team_name,
CONCAT(t.name, ' - ', a.name) as display_name
FROM apps a
INNER JOIN competition_teams ct ON a.team_id = ct.team_id
LEFT JOIN teams t ON a.team_id = t.id
LEFT JOIN competition_apps ca ON a.id = ca.app_id
LEFT JOIN judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE ca.competition_id IS NOT NULL
ORDER BY a.name
LEFT JOIN app_judge_scores js ON a.id = js.app_id AND js.judge_id = ?
WHERE a.is_active = 1
ORDER BY display_name
`;
params = [judgeId];
params = [judgeId, judgeId];
}
console.log('🔍 執行SQL查詢:');
console.log('SQL:', sql);
console.log('參數:', params);
const results = await DatabaseServiceBase.safeQuery(sql, params);
console.log('📊 查詢結果:', results);
return results;
}
}