完成評審評分機制
This commit is contained in:
92
scripts/setup-competition-relations.js
Normal file
92
scripts/setup-competition-relations.js
Normal file
@@ -0,0 +1,92 @@
|
||||
// =====================================================
|
||||
// 設置競賽關聯數據
|
||||
// =====================================================
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
async function setupCompetitionRelations() {
|
||||
console.log('🔧 設置競賽關聯數據...\n');
|
||||
|
||||
try {
|
||||
// 連接數據庫
|
||||
const connection = await mysql.createConnection({
|
||||
host: 'mysql.theaken.com',
|
||||
port: 33306,
|
||||
user: 'AI_Platform',
|
||||
password: 'Aa123456',
|
||||
database: 'db_AI_Platform'
|
||||
});
|
||||
|
||||
console.log('✅ 數據庫連接成功');
|
||||
|
||||
const competitionId = "be4b0a71-91f1-11f0-bb38-4adff2d0e33e";
|
||||
|
||||
// 檢查現有的評審
|
||||
console.log('\n📊 檢查現有評審...');
|
||||
const [judges] = await connection.execute('SELECT id, name FROM judges LIMIT 5');
|
||||
console.log('現有評審:', judges);
|
||||
|
||||
// 檢查現有的APP
|
||||
console.log('\n📱 檢查現有APP...');
|
||||
const [apps] = await connection.execute('SELECT id, name FROM apps LIMIT 5');
|
||||
console.log('現有APP:', apps);
|
||||
|
||||
// 檢查現有的關聯
|
||||
console.log('\n🔗 檢查現有關聯...');
|
||||
const [existingJudges] = await connection.execute(
|
||||
'SELECT COUNT(*) as count FROM competition_judges WHERE competition_id = ?',
|
||||
[competitionId]
|
||||
);
|
||||
const [existingApps] = await connection.execute(
|
||||
'SELECT COUNT(*) as count FROM competition_apps WHERE competition_id = ?',
|
||||
[competitionId]
|
||||
);
|
||||
console.log('競賽評審關聯數:', existingJudges[0].count);
|
||||
console.log('競賽APP關聯數:', existingApps[0].count);
|
||||
|
||||
// 如果沒有關聯,創建一些測試關聯
|
||||
if (existingJudges[0].count === 0 && judges.length > 0) {
|
||||
console.log('\n➕ 創建評審關聯...');
|
||||
for (let i = 0; i < Math.min(3, judges.length); i++) {
|
||||
await connection.execute(
|
||||
'INSERT INTO competition_judges (competition_id, judge_id) VALUES (?, ?)',
|
||||
[competitionId, judges[i].id]
|
||||
);
|
||||
console.log(`✅ 關聯評審: ${judges[i].name}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (existingApps[0].count === 0 && apps.length > 0) {
|
||||
console.log('\n➕ 創建APP關聯...');
|
||||
for (let i = 0; i < Math.min(2, apps.length); i++) {
|
||||
await connection.execute(
|
||||
'INSERT INTO competition_apps (competition_id, app_id) VALUES (?, ?)',
|
||||
[competitionId, apps[i].id]
|
||||
);
|
||||
console.log(`✅ 關聯APP: ${apps[i].name}`);
|
||||
}
|
||||
}
|
||||
|
||||
// 驗證關聯
|
||||
console.log('\n✅ 驗證關聯...');
|
||||
const [finalJudges] = await connection.execute(
|
||||
'SELECT COUNT(*) as count FROM competition_judges WHERE competition_id = ?',
|
||||
[competitionId]
|
||||
);
|
||||
const [finalApps] = await connection.execute(
|
||||
'SELECT COUNT(*) as count FROM competition_apps WHERE competition_id = ?',
|
||||
[competitionId]
|
||||
);
|
||||
console.log('最終評審關聯數:', finalJudges[0].count);
|
||||
console.log('最終APP關聯數:', finalApps[0].count);
|
||||
|
||||
await connection.end();
|
||||
console.log('\n✅ 數據庫連接已關閉');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 設置失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 執行設置
|
||||
setupCompetitionRelations();
|
Reference in New Issue
Block a user