修正評審評分資訊的 BUG
This commit is contained in:
@@ -366,8 +366,8 @@ export function ScoringManagement() {
|
|||||||
const selectedParticipant = competitionParticipants.find(p => p.id === manualScoring.participantId)
|
const selectedParticipant = competitionParticipants.find(p => p.id === manualScoring.participantId)
|
||||||
console.log('🔍 選中的參賽者:', selectedParticipant);
|
console.log('🔍 選中的參賽者:', selectedParticipant);
|
||||||
|
|
||||||
// 由於所有參賽者都是團隊的 app,所以 participantType 應該是 'app'
|
// 根據參賽者的實際類型確定 participantType
|
||||||
const participantType = 'app'
|
const participantType = selectedParticipant?.type === 'team' ? 'team' : 'app'
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
judgeId: manualScoring.judgeId,
|
judgeId: manualScoring.judgeId,
|
||||||
@@ -532,34 +532,19 @@ export function ScoringManagement() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (teamsData.success && teamsData.data && teamsData.data.teams) {
|
if (teamsData.success && teamsData.data && teamsData.data.teams) {
|
||||||
// 將每個團隊的每個 app 作為獨立的參賽項目
|
// 將每個團隊作為獨立的參賽項目(而不是團隊中的每個 app)
|
||||||
teamsData.data.teams.forEach((team: any) => {
|
teamsData.data.teams.forEach((team: any) => {
|
||||||
console.log('🔍 處理團隊:', team);
|
console.log('🔍 處理團隊:', team);
|
||||||
if (team.apps && team.apps.length > 0) {
|
|
||||||
team.apps.forEach((app: any) => {
|
|
||||||
console.log('🔍 處理團隊 app:', app);
|
|
||||||
participants.push({
|
participants.push({
|
||||||
id: app.id, // 使用 app 的 ID
|
id: team.id, // 使用團隊的 ID
|
||||||
name: app.name, // app 名稱
|
name: team.name, // 團隊名稱
|
||||||
type: 'team',
|
type: 'team',
|
||||||
teamName: team.name || '未知團隊', // 團隊名稱
|
teamName: team.name || '未知團隊', // 團隊名稱
|
||||||
displayName: app.name, // 只顯示 app 名稱,團隊名稱通過 teamName 屬性獲取
|
displayName: team.name, // 顯示團隊名稱
|
||||||
creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長',
|
creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長',
|
||||||
teamId: team.id // 保存團隊 ID
|
teamId: team.id // 保存團隊 ID
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
// 如果團隊沒有 app,仍然顯示團隊本身
|
|
||||||
participants.push({
|
|
||||||
id: team.id,
|
|
||||||
name: team.name,
|
|
||||||
type: 'team',
|
|
||||||
teamName: team.name || '未知團隊',
|
|
||||||
creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長',
|
|
||||||
teamId: team.id
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
console.log('✅ 團隊數據載入成功:', teamsData.data.teams.length, '個團隊')
|
console.log('✅ 團隊數據載入成功:', teamsData.data.teams.length, '個團隊')
|
||||||
} else {
|
} else {
|
||||||
console.error('❌ 團隊數據載入失敗:', teamsData.message || 'API回應格式錯誤')
|
console.error('❌ 團隊數據載入失敗:', teamsData.message || 'API回應格式錯誤')
|
||||||
|
@@ -1006,9 +1006,9 @@ export class JudgeService extends DatabaseServiceBase {
|
|||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
||||||
SELECT DISTINCT
|
SELECT DISTINCT
|
||||||
a.id,
|
t.id,
|
||||||
a.name,
|
t.name,
|
||||||
'app' as type,
|
'team' as type,
|
||||||
'team' as participant_type,
|
'team' as participant_type,
|
||||||
COALESCE(js.total_score, 0) as score,
|
COALESCE(js.total_score, 0) as score,
|
||||||
CASE
|
CASE
|
||||||
@@ -1017,12 +1017,11 @@ export class JudgeService extends DatabaseServiceBase {
|
|||||||
END as status,
|
END as status,
|
||||||
js.submitted_at,
|
js.submitted_at,
|
||||||
t.name as team_name,
|
t.name as team_name,
|
||||||
CONCAT(t.name, ' - ', a.name) as display_name
|
t.name as display_name
|
||||||
FROM apps a
|
FROM teams t
|
||||||
INNER JOIN competition_teams ct ON a.team_id = ct.team_id
|
INNER JOIN competition_teams ct ON t.id = ct.team_id
|
||||||
LEFT JOIN teams t ON a.team_id = t.id
|
LEFT JOIN app_judge_scores js ON js.app_id = CONCAT('team_', t.id) AND js.judge_id = ?
|
||||||
LEFT JOIN app_judge_scores js ON a.id = js.app_id AND js.judge_id = ?
|
WHERE ct.competition_id = ? AND t.is_active = 1
|
||||||
WHERE ct.competition_id = ? AND a.is_active = 1
|
|
||||||
|
|
||||||
ORDER BY display_name
|
ORDER BY display_name
|
||||||
`;
|
`;
|
||||||
@@ -3888,19 +3887,41 @@ export class ScoringService extends DatabaseServiceBase {
|
|||||||
const judgeCount = judgesResult[0]?.judge_count || 0;
|
const judgeCount = judgesResult[0]?.judge_count || 0;
|
||||||
console.log('🔍 評審數量:', judgeCount);
|
console.log('🔍 評審數量:', judgeCount);
|
||||||
|
|
||||||
// 獲取競賽的參賽APP數量
|
// 獲取競賽類型
|
||||||
|
const competitionResult = await DatabaseServiceBase.safeQuery(`
|
||||||
|
SELECT type FROM competitions WHERE id = ?
|
||||||
|
`, [competitionId]);
|
||||||
|
|
||||||
|
const competitionType = competitionResult[0]?.type || 'individual';
|
||||||
|
console.log('🔍 競賽類型:', competitionType);
|
||||||
|
|
||||||
|
let participantCount = 0;
|
||||||
|
|
||||||
|
if (competitionType === 'team') {
|
||||||
|
// 團隊競賽:獲取參賽團隊數量
|
||||||
|
const teamsResult = await DatabaseServiceBase.safeQuery(`
|
||||||
|
SELECT COUNT(DISTINCT ct.team_id) as team_count
|
||||||
|
FROM competition_teams ct
|
||||||
|
WHERE ct.competition_id = ?
|
||||||
|
`, [competitionId]);
|
||||||
|
|
||||||
|
participantCount = teamsResult[0]?.team_count || 0;
|
||||||
|
console.log('🔍 參賽團隊數量:', participantCount);
|
||||||
|
} else {
|
||||||
|
// 個人競賽:獲取參賽APP數量
|
||||||
const appsResult = await DatabaseServiceBase.safeQuery(`
|
const appsResult = await DatabaseServiceBase.safeQuery(`
|
||||||
SELECT COUNT(DISTINCT ca.app_id) as app_count
|
SELECT COUNT(DISTINCT ca.app_id) as app_count
|
||||||
FROM competition_apps ca
|
FROM competition_apps ca
|
||||||
WHERE ca.competition_id = ?
|
WHERE ca.competition_id = ?
|
||||||
`, [competitionId]);
|
`, [competitionId]);
|
||||||
|
|
||||||
const appCount = appsResult[0]?.app_count || 0;
|
participantCount = appsResult[0]?.app_count || 0;
|
||||||
console.log('🔍 參賽APP數量:', appCount);
|
console.log('🔍 參賽APP數量:', participantCount);
|
||||||
|
}
|
||||||
|
|
||||||
// 如果沒有評審或APP關聯,嘗試從其他方式獲取
|
// 如果沒有評審或參賽者關聯,嘗試從其他方式獲取
|
||||||
let finalJudgeCount = judgeCount;
|
let finalJudgeCount = judgeCount;
|
||||||
let finalAppCount = appCount;
|
let finalParticipantCount = participantCount;
|
||||||
|
|
||||||
if (judgeCount === 0) {
|
if (judgeCount === 0) {
|
||||||
// 嘗試從 judges 表獲取所有評審
|
// 嘗試從 judges 表獲取所有評審
|
||||||
@@ -3909,25 +3930,60 @@ export class ScoringService extends DatabaseServiceBase {
|
|||||||
console.log('🔍 使用所有評審數量:', finalJudgeCount);
|
console.log('🔍 使用所有評審數量:', finalJudgeCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appCount === 0) {
|
if (participantCount === 0) {
|
||||||
|
if (competitionType === 'team') {
|
||||||
|
// 嘗試從 teams 表獲取所有團隊
|
||||||
|
const allTeamsResult = await DatabaseServiceBase.safeQuery('SELECT COUNT(*) as team_count FROM teams');
|
||||||
|
finalParticipantCount = allTeamsResult[0]?.team_count || 0;
|
||||||
|
console.log('🔍 使用所有團隊數量:', finalParticipantCount);
|
||||||
|
} else {
|
||||||
// 嘗試從 apps 表獲取所有APP
|
// 嘗試從 apps 表獲取所有APP
|
||||||
const allAppsResult = await DatabaseServiceBase.safeQuery('SELECT COUNT(*) as app_count FROM apps');
|
const allAppsResult = await DatabaseServiceBase.safeQuery('SELECT COUNT(*) as app_count FROM apps');
|
||||||
finalAppCount = allAppsResult[0]?.app_count || 0;
|
finalParticipantCount = allAppsResult[0]?.app_count || 0;
|
||||||
console.log('🔍 使用所有APP數量:', finalAppCount);
|
console.log('🔍 使用所有APP數量:', finalParticipantCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 獲取已完成的評分數量
|
// 獲取已完成的評分數量
|
||||||
const completedResult = await DatabaseServiceBase.safeQuery(`
|
let completedResult;
|
||||||
|
if (competitionType === 'team') {
|
||||||
|
// 團隊競賽:查詢團隊評分記錄
|
||||||
|
completedResult = await DatabaseServiceBase.safeQuery(`
|
||||||
SELECT COUNT(*) as completed_count
|
SELECT COUNT(*) as completed_count
|
||||||
FROM judge_scores js
|
FROM app_judge_scores js
|
||||||
WHERE js.competition_id = ?
|
WHERE js.app_id LIKE 'team_%'
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM competition_teams ct
|
||||||
|
WHERE ct.competition_id = ?
|
||||||
|
AND js.app_id = CONCAT('team_', ct.team_id)
|
||||||
|
)
|
||||||
`, [competitionId]);
|
`, [competitionId]);
|
||||||
|
} else {
|
||||||
|
// 個人競賽:查詢應用評分記錄
|
||||||
|
completedResult = await DatabaseServiceBase.safeQuery(`
|
||||||
|
SELECT COUNT(*) as completed_count
|
||||||
|
FROM app_judge_scores js
|
||||||
|
WHERE js.app_id NOT LIKE 'team_%'
|
||||||
|
AND EXISTS (
|
||||||
|
SELECT 1 FROM competition_apps ca
|
||||||
|
WHERE ca.competition_id = ?
|
||||||
|
AND ca.app_id = js.app_id
|
||||||
|
)
|
||||||
|
`, [competitionId]);
|
||||||
|
}
|
||||||
|
|
||||||
const completed = completedResult[0]?.completed_count || 0;
|
const completed = completedResult[0]?.completed_count || 0;
|
||||||
const total = finalJudgeCount * finalAppCount;
|
const total = finalJudgeCount * finalParticipantCount;
|
||||||
const percentage = total > 0 ? Math.min(Math.round((completed / total) * 100), 100) : 0;
|
const percentage = total > 0 ? Math.min(Math.round((completed / total) * 100), 100) : 0;
|
||||||
|
|
||||||
console.log('🔍 評分進度結果:', { completed, total, percentage });
|
console.log('🔍 評分進度結果:', {
|
||||||
|
completed,
|
||||||
|
total,
|
||||||
|
percentage,
|
||||||
|
judgeCount: finalJudgeCount,
|
||||||
|
participantCount: finalParticipantCount,
|
||||||
|
competitionType
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
completed,
|
completed,
|
||||||
|
Reference in New Issue
Block a user