diff --git a/app/Services/AdminApplicationExportService.php b/app/Services/AdminApplicationExportService.php index 1238a25..d2d6784 100644 --- a/app/Services/AdminApplicationExportService.php +++ b/app/Services/AdminApplicationExportService.php @@ -331,6 +331,8 @@ class AdminApplicationExportService '提交时间', '附件数量', '进程', + '总分', + '平均分', '评分详情', ])); @@ -433,6 +435,18 @@ class AdminApplicationExportService } $completed = count($scoresByReviewerId); $progress = $required > 0 ? ($completed.'/'.$required) : '-'; + $fullyCompleted = $required > 0 && $completed >= $required; + + $numericScores = []; + foreach ($scoresByReviewerId as $score) { + if ($score->line_total !== null && is_numeric($score->line_total)) { + $numericScores[] = (float) $score->line_total; + } + } + $teamSum = $numericScores === [] ? null : array_sum($numericScores); + $teamAvg = $numericScores === [] ? null : ($teamSum / count($numericScores)); + $totalCell = $fullyCompleted ? $this->formatExportScore($teamSum) : '待评审'; + $avgCell = $fullyCompleted ? $this->formatExportScore($teamAvg) : '-'; $scoreDetails = collect($trackReviewers) ->map(function (array $reviewer) use ($scoresByReviewerId): string { @@ -465,6 +479,8 @@ class AdminApplicationExportService $app->submitted_at?->format('Y-m-d H:i:s') ?? '', (int) ($app->files_count ?? $app->files->count()), $progress, + $totalCell, + $avgCell, $scoreDetails, ]; } diff --git a/tests/Feature/AdminApplicationExportTest.php b/tests/Feature/AdminApplicationExportTest.php index fd6bd03..214509b 100644 --- a/tests/Feature/AdminApplicationExportTest.php +++ b/tests/Feature/AdminApplicationExportTest.php @@ -166,16 +166,50 @@ class AdminApplicationExportTest extends TestCase $this->assertGreaterThanOrEqual(2, count($rows)); $header = $rows[0]; $this->assertContains('进程', $header); + $this->assertContains('总分', $header); + $this->assertContains('平均分', $header); $this->assertContains('评分详情', $header); $progressIdx = array_search('进程', $header, true); + $totalIdx = array_search('总分', $header, true); + $avgIdx = array_search('平均分', $header, true); $detailIdx = array_search('评分详情', $header, true); $this->assertNotFalse($progressIdx); + $this->assertNotFalse($totalIdx); + $this->assertNotFalse($avgIdx); $this->assertNotFalse($detailIdx); $data = $rows[1]; $this->assertSame('1/2', (string) $data[$progressIdx]); + $this->assertSame('待评审', (string) $data[$totalIdx]); + $this->assertSame('-', (string) $data[$avgIdx]); $this->assertStringContainsString('评委甲 88.5', (string) $data[$detailIdx]); $this->assertStringContainsString('评委乙 未评审', (string) $data[$detailIdx]); + + ApplicationReviewScore::query()->create([ + 'application_id' => $application->id, + 'reviewer_id' => $reviewer2->id, + 'payload_json' => ['line_total' => 91.5], + 'line_total' => 91.5, + ]); + + $xlsxPath2 = $service->buildXlsxExportPath($competition, ['status' => 'submitted']); + $this->assertFileExists($xlsxPath2); + $reader2 = new Reader; + $reader2->open($xlsxPath2); + $rows2 = []; + foreach ($reader2->getSheetIterator() as $sheet) { + foreach ($sheet->getRowIterator() as $row) { + $rows2[] = $row->toArray(); + } + break; + } + $reader2->close(); + @unlink($xlsxPath2); + + $data2 = $rows2[1]; + $this->assertSame('2/2', (string) $data2[$progressIdx]); + $this->assertSame('180', (string) $data2[$totalIdx]); + $this->assertSame('90', (string) $data2[$avgIdx]); } }