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