const mysql = require('mysql2/promise'); async function testTeamData() { const connection = await mysql.createConnection({ host: 'mysql.theaken.com', port: 33306, user: 'AI_Platform', password: 'Aa123456', database: 'db_AI_Platform', charset: 'utf8mb4', timezone: '+08:00' }); try { console.log('๐Ÿ” ๆธฌ่ฉฆๅœ˜้šŠๆ•ธๆ“šๆŸฅ่ฉข...'); // ไฝฟ็”จ่ˆ‡ getAllTeams ็›ธๅŒ็š„ๆŸฅ่ฉข const [results] = await connection.execute(` SELECT t.*, u.name as leader_name, u.phone as leader_phone, t.leader_id as leader, COUNT(DISTINCT tm.id) as member_count, COUNT(DISTINCT a.id) as app_count, t.created_at as submissionDate FROM teams t LEFT JOIN users u ON t.leader_id = u.id LEFT JOIN team_members tm ON t.id = tm.team_id LEFT JOIN apps a ON t.id = a.team_id AND a.is_active = 1 WHERE t.is_active = 1 GROUP BY t.id, t.name, t.leader_id, t.department, t.contact_email, t.total_likes, t.is_active, t.created_at, t.updated_at, u.name, u.phone ORDER BY t.created_at DESC LIMIT 5 `); console.log('๐Ÿ“Š ๆŸฅ่ฉข็ตๆžœ:'); results.forEach((team, index) => { console.log(`\nๅœ˜้šŠ ${index + 1}:`); console.log(` ๅ็จฑ: ${team.name}`); console.log(` ้šŠ้•ทID: ${team.leader}`); console.log(` ้šŠ้•ทๅง“ๅ: ${team.leader_name || 'NULL'}`); console.log(` ๆˆๅ“กๆ•ธ้‡: ${team.member_count || 0}`); console.log(` ๆไบคๆ—ฅๆœŸ: ${team.submissionDate || 'NULL'}`); console.log(` ้ƒจ้–€: ${team.department}`); }); // ๆชขๆŸฅ็‰นๅฎšๅœ˜้šŠ็š„ๆˆๅ“ก if (results.length > 0) { const teamId = results[0].id; const [members] = await connection.execute(` SELECT tm.*, u.name as user_name FROM team_members tm LEFT JOIN users u ON tm.user_id = u.id WHERE tm.team_id = ? `, [teamId]); console.log(`\n๐Ÿ” ๅœ˜้šŠ ${results[0].name} ็š„ๆˆๅ“ก:`); members.forEach(member => { console.log(` - ${member.user_name} (${member.role})`); }); } } catch (error) { console.error('โŒ ้Œฏ่ชค:', error); } finally { await connection.end(); } } testTeamData();