OCRPaperGrading.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. namespace App\Filament\Pages;
  3. use App\Models\OCRRecord;
  4. use App\Services\ExamPaperService;
  5. use App\Jobs\RegradeOCRSubmission;
  6. use App\Filament\Traits\HasUserRole;
  7. use Filament\Pages\Page;
  8. use Filament\Notifications\Notification;
  9. use Livewire\Attributes\Computed;
  10. class OCRPaperGrading extends Page
  11. {
  12. use HasUserRole;
  13. protected static ?string $navigationLabel = 'OCR智能阅卷';
  14. protected static ?string $title = 'OCR试卷智能阅卷系统';
  15. protected static ?string $slug = 'ocr-paper-grading';
  16. public static function getNavigationIcon(): ?string
  17. {
  18. return 'heroicon-o-document-duplicate';
  19. }
  20. public static function getNavigationGroup(): ?string
  21. {
  22. return 'OCR+AI系统';
  23. }
  24. protected string $view = 'filament.pages.ocr-paper-grading';
  25. // 选择相关
  26. public ?string $teacherId = null;
  27. public ?string $studentId = null;
  28. public ?string $selectedPaperId = null;
  29. // 处理状态
  30. public ?int $selectedRecordId = null;
  31. public ?OCRRecord $selectedRecord = null;
  32. public function mount(): void
  33. {
  34. $this->initializeUserRole();
  35. if ($this->isTeacher) {
  36. $teacherId = $this->getCurrentTeacherId();
  37. if ($teacherId) {
  38. $this->teacherId = $teacherId;
  39. }
  40. }
  41. }
  42. #[Computed]
  43. public function teachers(): array
  44. {
  45. return app(ExamPaperService::class)->getTeachers(
  46. $this->isTeacher ? $this->getCurrentTeacherId() : null
  47. );
  48. }
  49. #[Computed]
  50. public function students(): array
  51. {
  52. return app(ExamPaperService::class)->getStudents($this->teacherId);
  53. }
  54. #[Computed]
  55. public function studentPapers(): array
  56. {
  57. return app(ExamPaperService::class)->getStudentPapers($this->studentId);
  58. }
  59. #[Computed]
  60. public function selectedPaperQuestions(): array
  61. {
  62. return app(ExamPaperService::class)->getPaperQuestions($this->selectedPaperId);
  63. }
  64. public function updatedTeacherId($value): void
  65. {
  66. $this->studentId = null;
  67. $this->selectedPaperId = null;
  68. }
  69. public function updatedStudentId($value): void
  70. {
  71. $this->selectedPaperId = null;
  72. }
  73. /**
  74. * 查看OCR记录
  75. */
  76. public function viewRecord(int $recordId): void
  77. {
  78. $this->selectedRecordId = $recordId;
  79. $this->selectedRecord = OCRRecord::with('questions')->findOrFail($recordId);
  80. }
  81. /**
  82. * 手动重新判分
  83. */
  84. public function regrade(int $recordId): void
  85. {
  86. RegradeOCRSubmission::dispatch($recordId);
  87. Notification::make()
  88. ->title('已触发重新判分')
  89. ->body('请稍后刷新查看结果')
  90. ->success()
  91. ->send();
  92. }
  93. /**
  94. * 获取最近的OCR记录
  95. */
  96. public function getRecentRecords(): \Illuminate\Database\Eloquent\Collection
  97. {
  98. return OCRRecord::with('questions')
  99. ->orderBy('created_at', 'desc')
  100. ->limit(10)
  101. ->get();
  102. }
  103. }