實現完整的後台得獎資訊

This commit is contained in:
2025-09-27 02:42:22 +08:00
parent 2597a07514
commit b06fd94c99
8 changed files with 302 additions and 111 deletions

View File

@@ -1670,17 +1670,6 @@ export class CompetitionService extends DatabaseServiceBase {
// 競賽關聯數據管理方法
// =====================================================
// 獲取競賽的評審列表
static async getCompetitionJudges(competitionId: string): Promise<any[]> {
const sql = `
SELECT j.*, cj.assigned_at
FROM competition_judges cj
JOIN judges j ON cj.judge_id = j.id
WHERE cj.competition_id = ? AND j.is_active = 1
ORDER BY cj.assigned_at ASC
`;
return await DatabaseServiceBase.safeQuery(sql, [competitionId]);
}
// 為競賽添加評審
static async addCompetitionJudges(competitionId: string, judgeIds: string[]): Promise<boolean> {
@@ -2080,6 +2069,63 @@ export class CompetitionService extends DatabaseServiceBase {
rules
};
}
// 根據競賽ID獲取評審信息
static async getCompetitionJudges(competitionId: string): Promise<any[]> {
try {
console.log('🔍 查詢競賽評審:', competitionId);
// 先檢查 competition_judges 表是否有資料
const checkSql = `SELECT COUNT(*) as count FROM competition_judges WHERE competition_id = ?`;
const checkResult = await db.query<any>(checkSql, [competitionId]);
console.log('📊 competition_judges 表中該競賽的記錄數:', checkResult[0]?.count || 0);
// 檢查 judges 表是否有資料
const judgesCountSql = `SELECT COUNT(*) as count FROM judges WHERE is_active = TRUE`;
const judgesCountResult = await db.query<any>(judgesCountSql, []);
console.log('📊 judges 表中活躍評審數:', judgesCountResult[0]?.count || 0);
// 檢查關聯查詢
const joinCheckSql = `
SELECT
cj.competition_id,
cj.judge_id,
j.id as judge_table_id,
j.name,
j.is_active
FROM competition_judges cj
LEFT JOIN judges j ON cj.judge_id = j.id
WHERE cj.competition_id = ?
`;
const joinResult = await db.query<any>(joinCheckSql, [competitionId]);
console.log('🔗 關聯查詢結果:', joinResult);
const sql = `
SELECT
j.id,
j.name,
j.title,
j.department,
j.expertise,
j.avatar,
cj.assigned_at
FROM competition_judges cj
LEFT JOIN judges j ON cj.judge_id = j.id
WHERE cj.competition_id = ? AND j.is_active = TRUE
ORDER BY j.name
`;
console.log('📝 執行評審查詢SQL:', sql);
console.log('📝 查詢參數:', [competitionId]);
const result = await db.query<any>(sql, [competitionId]);
console.log('✅ 查詢評審結果:', result?.length || 0, '位評審');
console.log('👥 評審詳細結果:', result);
return result;
} catch (error) {
console.error('❌ 查詢評審失敗:', error);
throw error;
}
}
}
// =====================================================
@@ -4569,33 +4615,6 @@ export class AwardService extends DatabaseServiceBase {
return await db.queryOne<Award>(sql, [id]);
}
// 根據競賽ID獲取評審信息
static async getCompetitionJudges(competitionId: string): Promise<any[]> {
try {
console.log('🔍 查詢競賽評審:', competitionId);
const sql = `
SELECT
j.id,
j.name,
j.title,
j.department,
j.expertise,
j.avatar
FROM competition_judges cj
LEFT JOIN judges j ON cj.judge_id = j.id
WHERE cj.competition_id = ? AND j.is_active = TRUE
ORDER BY j.name
`;
console.log('📝 執行評審查詢SQL:', sql);
const result = await db.query<any>(sql, [competitionId]);
console.log('✅ 查詢評審結果:', result?.length || 0, '位評審');
return result;
} catch (error) {
console.error('❌ 查詢評審失敗:', error);
throw error;
}
}
// 更新獎項
static async updateAward(id: string, updates: Partial<Award>): Promise<boolean> {
const fields = Object.keys(updates).filter(key =>
@@ -4664,11 +4683,6 @@ export class AwardService extends DatabaseServiceBase {
return await db.query<Award>(sql, [year]);
}
// 根據競賽獲取獎項
static async getAwardsByCompetition(competitionId: string): Promise<Award[]> {
const sql = 'SELECT * FROM awards WHERE competition_id = ? ORDER BY rank ASC';
return await db.query<Award>(sql, [competitionId]);
}
}
// =====================================================