studentId = $studentId; $this->laService = new LearningAnalyticsService(); $this->loadStudentData(); } public function loadStudentData() { $this->loading = true; $this->error = ''; try { // 获取学生基本信息 $this->student = User::where('user_id', $this->studentId)->firstOrFail(); // 从 MySQL 获取练习历史 $exercises = DB::connection('remote_mysql') ->table('student_exercises') ->where('student_id', $this->studentId) ->orderBy('created_at', 'desc') ->limit(50) ->get() ->toArray(); // 从 LearningAnalytics 获取掌握度数据 $this->masteryData = $this->laService->getStudentMastery($this->studentId) ?: []; // 从 LearningAnalytics 获取学习分析 $this->analysis = $this->laService->getStudentAnalysis($this->studentId); // 合并数据 $this->analysis['exercises'] = $exercises; $this->analysis['exercises_count'] = count($exercises); } catch (\Exception $e) { $this->error = '加载学生数据失败: ' . $e->getMessage(); \Log::error('StudentAnalytics load error', [ 'student_id' => $this->studentId, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); } finally { $this->loading = false; } } public function render() { return view('livewire.student-analytics', [ 'masteryPoints' => $this->masteryData['data'] ?? [], 'totalKnowledgePoints' => count($this->masteryData['data'] ?? []), 'student' => $this->student, ]); } }