完成評審評分機制
This commit is contained in:
71
scripts/create-virtual-apps.js
Normal file
71
scripts/create-virtual-apps.js
Normal file
@@ -0,0 +1,71 @@
|
||||
// =====================================================
|
||||
// 創建虛擬應用記錄用於團隊評分
|
||||
// =====================================================
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
|
||||
async function createVirtualApps() {
|
||||
console.log('🔧 創建虛擬應用記錄...\n');
|
||||
|
||||
try {
|
||||
// 連接資料庫
|
||||
const connection = await mysql.createConnection({
|
||||
host: process.env.DB_HOST || '122.100.99.161',
|
||||
port: parseInt(process.env.DB_PORT || '43306'),
|
||||
user: process.env.DB_USER || 'AI_Platform',
|
||||
password: process.env.DB_PASSWORD || 'Aa123456',
|
||||
database: process.env.DB_NAME || 'db_AI_Platform'
|
||||
});
|
||||
|
||||
console.log('✅ 資料庫連接成功');
|
||||
|
||||
// 獲取所有團隊
|
||||
const [teams] = await connection.execute('SELECT id, name FROM teams WHERE is_active = TRUE');
|
||||
console.log('📋 找到', teams.length, '個團隊');
|
||||
|
||||
// 為每個團隊創建虛擬應用
|
||||
for (const team of teams) {
|
||||
const virtualAppId = `team_${team.id}`;
|
||||
|
||||
// 檢查是否已存在
|
||||
const [existing] = await connection.execute('SELECT id FROM apps WHERE id = ?', [virtualAppId]);
|
||||
|
||||
if (existing.length === 0) {
|
||||
const sql = `
|
||||
INSERT INTO apps (id, name, description, creator_id, category, type, app_url, icon, icon_color, likes_count, views_count, rating, is_active, created_at, updated_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW())
|
||||
`;
|
||||
|
||||
const params = [
|
||||
virtualAppId,
|
||||
`[團隊評分] ${team.name}`,
|
||||
`團隊 ${team.name} 的評分記錄`,
|
||||
'00000000-0000-0000-0000-000000000000', // 虛擬創建者ID
|
||||
'team_scoring',
|
||||
'team',
|
||||
null,
|
||||
'Users',
|
||||
'from-gray-500 to-gray-600',
|
||||
0,
|
||||
0,
|
||||
0.00,
|
||||
true
|
||||
];
|
||||
|
||||
await connection.execute(sql, params);
|
||||
console.log(`✅ 創建虛擬應用: ${virtualAppId} (${team.name})`);
|
||||
} else {
|
||||
console.log(`⏭️ 虛擬應用已存在: ${virtualAppId}`);
|
||||
}
|
||||
}
|
||||
|
||||
await connection.end();
|
||||
console.log('\n✅ 虛擬應用記錄創建完成!');
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ 創建虛擬應用失敗:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
// 執行創建
|
||||
createVirtualApps();
|
Reference in New Issue
Block a user