修正評分計算彙總 bug
This commit is contained in:
@@ -68,6 +68,9 @@ export function ScoringManagement() {
|
|||||||
const [scoringSummary, setScoringSummary] = useState<any>(null)
|
const [scoringSummary, setScoringSummary] = useState<any>(null)
|
||||||
const [isLoadingSummary, setIsLoadingSummary] = useState(false)
|
const [isLoadingSummary, setIsLoadingSummary] = useState(false)
|
||||||
|
|
||||||
|
// 評分進度狀態(用於確保APP數量一致性)
|
||||||
|
const [scoringProgress, setScoringProgress] = useState<any>(null)
|
||||||
|
|
||||||
// APP詳細評分狀態
|
// APP詳細評分狀態
|
||||||
const [selectedApp, setSelectedApp] = useState<any>(null)
|
const [selectedApp, setSelectedApp] = useState<any>(null)
|
||||||
const [appScoringDetails, setAppScoringDetails] = useState<any>(null)
|
const [appScoringDetails, setAppScoringDetails] = useState<any>(null)
|
||||||
@@ -504,65 +507,42 @@ export function ScoringManagement() {
|
|||||||
setCompetitionJudges([])
|
setCompetitionJudges([])
|
||||||
}
|
}
|
||||||
|
|
||||||
// 載入競賽參賽者(應用和團隊)
|
// 使用統一的評分進度API來獲取準確的參賽者數量
|
||||||
console.log('📱 載入競賽參賽者...')
|
console.log('📱 載入競賽參賽者(使用統一計算邏輯)...')
|
||||||
const [appsResponse, teamsResponse] = await Promise.all([
|
const scoringProgressResponse = await fetch(`/api/competitions/scoring-progress?competitionId=${selectedCompetition.id}`)
|
||||||
fetch(`/api/competitions/${selectedCompetition.id}/apps`),
|
const scoringProgressData = await scoringProgressResponse.json()
|
||||||
fetch(`/api/competitions/${selectedCompetition.id}/teams`)
|
|
||||||
])
|
|
||||||
|
|
||||||
const appsData = await appsResponse.json()
|
|
||||||
const teamsData = await teamsResponse.json()
|
|
||||||
|
|
||||||
console.log('應用API回應:', appsData)
|
|
||||||
console.log('團隊API回應:', teamsData)
|
|
||||||
|
|
||||||
const participants = []
|
|
||||||
|
|
||||||
if (appsData.success && appsData.data && appsData.data.apps) {
|
console.log('評分進度API回應:', scoringProgressData)
|
||||||
participants.push(...appsData.data.apps.map((app: any) => ({
|
|
||||||
id: app.id,
|
|
||||||
name: app.name,
|
|
||||||
type: 'individual',
|
|
||||||
creator: app.creator
|
|
||||||
})))
|
|
||||||
console.log('✅ 應用數據載入成功:', appsData.data.apps.length, '個應用')
|
|
||||||
} else {
|
|
||||||
console.error('❌ 應用數據載入失敗:', appsData.message || 'API回應格式錯誤')
|
|
||||||
}
|
|
||||||
|
|
||||||
if (teamsData.success && teamsData.data && teamsData.data.teams) {
|
let participants = []
|
||||||
// 將每個團隊的每個 app 作為獨立的參賽項目
|
|
||||||
teamsData.data.teams.forEach((team: any) => {
|
if (scoringProgressData.success && scoringProgressData.data) {
|
||||||
console.log('🔍 處理團隊:', team);
|
// 保存評分進度數據
|
||||||
if (team.apps && team.apps.length > 0) {
|
setScoringProgress(scoringProgressData.data)
|
||||||
team.apps.forEach((app: any) => {
|
|
||||||
console.log('🔍 處理團隊 app:', app);
|
// 獲取競賽的實際參賽APP(使用與評分進度相同的邏輯)
|
||||||
participants.push({
|
const appsResponse = await fetch(`/api/competitions/${selectedCompetition.id}/apps`)
|
||||||
id: app.id, // 使用 app 的 ID
|
const appsData = await appsResponse.json()
|
||||||
name: app.name, // app 名稱
|
|
||||||
type: 'team',
|
console.log('應用API回應:', appsData)
|
||||||
teamName: team.name || '未知團隊', // 團隊名稱
|
|
||||||
displayName: app.name, // 只顯示 app 名稱,團隊名稱通過 teamName 屬性獲取
|
if (appsData.success && appsData.data && appsData.data.apps) {
|
||||||
creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長',
|
// 直接使用API返回的APP數據,確保數量與評分進度一致
|
||||||
teamId: team.id // 保存團隊 ID
|
participants = appsData.data.apps.map((app: any) => ({
|
||||||
})
|
id: app.id,
|
||||||
})
|
name: app.name,
|
||||||
} else {
|
type: selectedCompetition.type === 'team' ? 'team' : 'individual',
|
||||||
// 如果團隊沒有 app,仍然顯示團隊本身
|
teamName: app.teamName || (selectedCompetition.type === 'team' ? '未知團隊' : null),
|
||||||
participants.push({
|
displayName: app.name,
|
||||||
id: team.id,
|
creator: app.creator || '未知作者',
|
||||||
name: team.name,
|
teamId: app.teamId || null
|
||||||
type: 'team',
|
}))
|
||||||
teamName: team.name || '未知團隊',
|
console.log(`✅ ${selectedCompetition.type === 'team' ? '團隊' : '個人'}競賽APP數據載入成功:`, participants.length, '個APP')
|
||||||
creator: team.members && team.members.find((m: any) => m.role === '隊長')?.name || '未知隊長',
|
} else {
|
||||||
teamId: team.id
|
console.error('❌ 應用數據載入失敗:', appsData.message || 'API回應格式錯誤')
|
||||||
})
|
}
|
||||||
}
|
|
||||||
})
|
|
||||||
console.log('✅ 團隊數據載入成功:', teamsData.data.teams.length, '個團隊')
|
|
||||||
} else {
|
} else {
|
||||||
console.error('❌ 團隊數據載入失敗:', teamsData.message || 'API回應格式錯誤')
|
console.error('❌ 評分進度數據載入失敗:', scoringProgressData.message || 'API回應格式錯誤')
|
||||||
}
|
}
|
||||||
|
|
||||||
setCompetitionParticipants(participants)
|
setCompetitionParticipants(participants)
|
||||||
@@ -778,7 +758,7 @@ export function ScoringManagement() {
|
|||||||
<CardContent className="p-4">
|
<CardContent className="p-4">
|
||||||
<div className="text-center">
|
<div className="text-center">
|
||||||
<p className="text-2xl font-bold text-green-600">
|
<p className="text-2xl font-bold text-green-600">
|
||||||
{competitionParticipants.length}
|
{scoringProgress?.appCount || competitionParticipants.length}
|
||||||
</p>
|
</p>
|
||||||
<p className="text-sm text-gray-600">參賽APP數</p>
|
<p className="text-sm text-gray-600">參賽APP數</p>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -3895,6 +3895,7 @@ export class ScoringService extends DatabaseServiceBase {
|
|||||||
completed: number;
|
completed: number;
|
||||||
total: number;
|
total: number;
|
||||||
percentage: number;
|
percentage: number;
|
||||||
|
appCount: number;
|
||||||
}> {
|
}> {
|
||||||
try {
|
try {
|
||||||
console.log('🔍 獲取競賽評分進度,competitionId:', competitionId);
|
console.log('🔍 獲取競賽評分進度,competitionId:', competitionId);
|
||||||
@@ -3948,11 +3949,12 @@ export class ScoringService extends DatabaseServiceBase {
|
|||||||
return {
|
return {
|
||||||
completed,
|
completed,
|
||||||
total,
|
total,
|
||||||
percentage
|
percentage,
|
||||||
|
appCount
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('獲取評分進度失敗:', error);
|
console.error('獲取評分進度失敗:', error);
|
||||||
return { completed: 0, total: 0, percentage: 0 };
|
return { completed: 0, total: 0, percentage: 0, appCount: 0 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user