完成評審評分機制
This commit is contained in:
72
scripts/check-app-competition-relation.js
Normal file
72
scripts/check-app-competition-relation.js
Normal file
@@ -0,0 +1,72 @@
|
||||
// =====================================================
|
||||
// 檢查APP與競賽的關聯關係
|
||||
// =====================================================
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
async function checkAppCompetitionRelation() {
|
||||
console.log('🔍 檢查APP與競賽的關聯關係...\n');
|
||||
|
||||
try {
|
||||
// 連接數據庫
|
||||
const connection = await mysql.createConnection({
|
||||
host: 'mysql.theaken.com',
|
||||
port: 33306,
|
||||
user: 'AI_Platform',
|
||||
password: 'Aa123456',
|
||||
database: 'db_AI_Platform'
|
||||
});
|
||||
|
||||
console.log('✅ 數據庫連接成功');
|
||||
|
||||
// 檢查特定APP
|
||||
const appId = "7f7395f4-ad9f-4d14-9e2c-84962ecbcfd7";
|
||||
console.log(`\n📊 檢查APP ${appId}:`);
|
||||
|
||||
// 檢查APP是否存在
|
||||
const [apps] = await connection.execute('SELECT * FROM apps WHERE id = ?', [appId]);
|
||||
console.log('APP信息:', apps);
|
||||
|
||||
// 檢查APP的競賽關聯
|
||||
const [competitionApps] = await connection.execute(
|
||||
'SELECT ca.*, c.name as competition_name FROM competition_apps ca LEFT JOIN competitions c ON ca.competition_id = c.id WHERE ca.app_id = ?',
|
||||
[appId]
|
||||
);
|
||||
console.log('競賽關聯:', competitionApps);
|
||||
|
||||
// 檢查所有競賽
|
||||
console.log('\n📊 所有競賽:');
|
||||
const [competitions] = await connection.execute('SELECT id, name, type FROM competitions');
|
||||
console.log(competitions);
|
||||
|
||||
// 檢查所有競賽APP關聯
|
||||
console.log('\n📊 所有競賽APP關聯:');
|
||||
const [allCompetitionApps] = await connection.execute('SELECT * FROM competition_apps LIMIT 10');
|
||||
console.log(allCompetitionApps);
|
||||
|
||||
// 如果沒有關聯,創建一個
|
||||
if (competitionApps.length === 0 && apps.length > 0 && competitions.length > 0) {
|
||||
console.log('\n🔧 創建APP與競賽的關聯...');
|
||||
const competitionId = competitions[0].id;
|
||||
|
||||
try {
|
||||
await connection.execute(
|
||||
'INSERT INTO competition_apps (id, competition_id, app_id) VALUES (UUID(), ?, ?)',
|
||||
[competitionId, appId]
|
||||
);
|
||||
console.log('✅ 關聯創建成功');
|
||||
} catch (error) {
|
||||
console.log('❌ 關聯創建失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
await connection.end();
|
||||
console.log('\n✅ 數據庫連接已關閉');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 檢查失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 執行檢查
|
||||
checkAppCompetitionRelation();
|
Reference in New Issue
Block a user