修正競賽團隊編輯、個人賽顯示、團體賽顯示 bug

This commit is contained in:
2025-09-20 22:44:21 +08:00
parent c5bbec5ca8
commit 049b53fa43
15 changed files with 480 additions and 85 deletions

View File

@@ -0,0 +1,50 @@
-- =====================================================
-- 插入團隊成員測試數據
-- =====================================================
-- 首先查看現有的團隊
SELECT '=== 現有團隊 ===' as info;
SELECT id, name, leader_id FROM teams WHERE is_active = 1;
-- 查看現有用戶
SELECT '=== 現有用戶 ===' as info;
SELECT id, name, department FROM users WHERE status = 'active' LIMIT 10;
-- 為每個團隊插入成員數據
-- 團隊 1: aaa (ID: t1757702332911zcl6iafq1)
INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES
('tm_1_1', 't1757702332911zcl6iafq1', 'db19b491-8f63-44b5-a28a-1f8eeb4fdd3c', '隊長', NOW()),
('tm_1_2', 't1757702332911zcl6iafq1', 'db19b491-8f63-44b5-a28a-1f8eeb4fdd3c', '成員', NOW());
-- 如果有其他團隊,請按照相同格式添加
-- 團隊 2: (如果有的話)
-- INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES
-- ('tm_2_1', 'team_id_2', 'user_id_2', '隊長', NOW()),
-- ('tm_2_2', 'team_id_2', 'user_id_3', '成員', NOW());
-- 驗證插入結果
SELECT '=== 團隊成員插入結果 ===' as info;
SELECT
tm.id,
tm.team_id,
t.name as team_name,
tm.user_id,
u.name as user_name,
tm.role,
tm.joined_at
FROM team_members tm
LEFT JOIN teams t ON tm.team_id = t.id
LEFT JOIN users u ON tm.user_id = u.id
ORDER BY tm.team_id, tm.role;
-- 檢查團隊成員統計
SELECT '=== 團隊成員統計 ===' as info;
SELECT
t.id,
t.name as team_name,
COUNT(tm.id) as member_count
FROM teams t
LEFT JOIN team_members tm ON t.id = tm.team_id
WHERE t.is_active = 1
GROUP BY t.id, t.name
ORDER BY t.name;

View File

@@ -0,0 +1,82 @@
const mysql = require('mysql2/promise');
async function insertTeamMembers() {
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('🔍 開始插入團隊成員測試數據...');
// 查看現有團隊
const [teams] = await connection.execute('SELECT id, name, leader_id FROM teams WHERE is_active = 1 LIMIT 5');
console.log('現有團隊:', teams);
// 查看現有用戶
const [users] = await connection.execute('SELECT id, name FROM users WHERE status = "active" LIMIT 5');
console.log('現有用戶:', users);
if (teams.length > 0 && users.length > 0) {
// 為每個團隊插入成員
for (let i = 0; i < Math.min(teams.length, 3); i++) {
const team = teams[i];
const teamId = team.id;
// 插入隊長(使用團隊的 leader_id
await connection.execute(
'INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES (?, ?, ?, ?, NOW())',
[`tm_${Date.now()}_${i}_1`, teamId, team.leader_id, '隊長']
);
// 插入成員(使用其他用戶)
for (let j = 1; j < Math.min(users.length, 3); j++) {
if (users[j].id !== team.leader_id) {
await connection.execute(
'INSERT IGNORE INTO team_members (id, team_id, user_id, role, joined_at) VALUES (?, ?, ?, ?, NOW())',
[`tm_${Date.now()}_${i}_${j+1}`, teamId, users[j].id, '成員']
);
}
}
console.log(`✅ 團隊 ${team.name} 成員插入成功`);
}
}
// 驗證結果
const [members] = await connection.execute(`
SELECT tm.*, t.name as team_name, u.name as user_name
FROM team_members tm
LEFT JOIN teams t ON tm.team_id = t.id
LEFT JOIN users u ON tm.user_id = u.id
ORDER BY tm.team_id
`);
console.log('📊 團隊成員統計:', members);
// 檢查團隊成員數量
const [counts] = await connection.execute(`
SELECT
t.id,
t.name as team_name,
COUNT(tm.id) as member_count
FROM teams t
LEFT JOIN team_members tm ON t.id = tm.team_id
WHERE t.is_active = 1
GROUP BY t.id, t.name
ORDER BY t.name
`);
console.log('📈 團隊成員數量:', counts);
} catch (error) {
console.error('❌ 錯誤:', error);
} finally {
await connection.end();
}
}
insertTeamMembers();

70
scripts/test-team-data.js Normal file
View File

@@ -0,0 +1,70 @@
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();