|
@@ -157,7 +157,7 @@ class MistakeBookService
|
|
|
|
|
|
|
|
// 转换数据格式
|
|
// 转换数据格式
|
|
|
$data = $mistakes->map(function ($mistake) {
|
|
$data = $mistakes->map(function ($mistake) {
|
|
|
- return $this->transformMistakeRecord($mistake);
|
|
|
|
|
|
|
+ return $this->transformMistakeRecord($mistake, false);
|
|
|
})->toArray();
|
|
})->toArray();
|
|
|
|
|
|
|
|
// 获取统计信息
|
|
// 获取统计信息
|
|
@@ -680,6 +680,12 @@ class MistakeBookService
|
|
|
*/
|
|
*/
|
|
|
private function transformMistakeRecord(MistakeRecord $mistake, bool $detailed = false): array
|
|
private function transformMistakeRecord(MistakeRecord $mistake, bool $detailed = false): array
|
|
|
{
|
|
{
|
|
|
|
|
+ // 【新增】通过 question_id 关联获取题目详情
|
|
|
|
|
+ $questionDetails = $this->getQuestionDetails($mistake->question_id);
|
|
|
|
|
+
|
|
|
|
|
+ // 【新增】通过 kp_ids 获取知识点信息
|
|
|
|
|
+ $knowledgePoints = $this->getKnowledgePoints($mistake->kp_ids);
|
|
|
|
|
+
|
|
|
$data = [
|
|
$data = [
|
|
|
'id' => $mistake->id,
|
|
'id' => $mistake->id,
|
|
|
'student_id' => $mistake->student_id,
|
|
'student_id' => $mistake->student_id,
|
|
@@ -687,11 +693,8 @@ class MistakeBookService
|
|
|
'paper_id' => $mistake->paper_id,
|
|
'paper_id' => $mistake->paper_id,
|
|
|
'question_text' => $mistake->question_text,
|
|
'question_text' => $mistake->question_text,
|
|
|
'student_answer' => $mistake->student_answer,
|
|
'student_answer' => $mistake->student_answer,
|
|
|
- 'correct_answer' => $mistake->correct_answer,
|
|
|
|
|
- 'knowledge_point' => $mistake->knowledge_point,
|
|
|
|
|
- 'explanation' => $mistake->explanation,
|
|
|
|
|
- 'source' => $mistake->source,
|
|
|
|
|
- 'source_label' => $mistake->source_label,
|
|
|
|
|
|
|
+ // 【优先】questions 表的答案,其次才是错题本自带的
|
|
|
|
|
+ 'correct_answer' => $questionDetails['answer'] ?? $mistake->correct_answer,
|
|
|
'created_at' => $mistake->created_at?->toISOString(),
|
|
'created_at' => $mistake->created_at?->toISOString(),
|
|
|
'review_status' => $mistake->review_status,
|
|
'review_status' => $mistake->review_status,
|
|
|
'review_status_label' => $mistake->review_status_label,
|
|
'review_status_label' => $mistake->review_status_label,
|
|
@@ -702,12 +705,25 @@ class MistakeBookService
|
|
|
'next_review_at' => $mistake->next_review_at?->toISOString(),
|
|
'next_review_at' => $mistake->next_review_at?->toISOString(),
|
|
|
'error_type' => $mistake->error_type,
|
|
'error_type' => $mistake->error_type,
|
|
|
'error_type_label' => $mistake->error_type_label,
|
|
'error_type_label' => $mistake->error_type_label,
|
|
|
- 'kp_ids' => $mistake->kp_ids,
|
|
|
|
|
|
|
+ // 【移除】kp_ids、source、source_label、knowledge_point、explanation 字段
|
|
|
|
|
+ // 'kp_ids' => $mistake->kp_ids,
|
|
|
|
|
+ // 'source' => $mistake->source,
|
|
|
|
|
+ // 'source_label' => $mistake->source_label,
|
|
|
|
|
+ // 'knowledge_point' => $mistake->knowledge_point,
|
|
|
|
|
+ // 'explanation' => $mistake->explanation,
|
|
|
'skill_ids' => $mistake->skill_ids,
|
|
'skill_ids' => $mistake->skill_ids,
|
|
|
'difficulty' => $mistake->difficulty,
|
|
'difficulty' => $mistake->difficulty,
|
|
|
'difficulty_level' => $mistake->difficulty_level,
|
|
'difficulty_level' => $mistake->difficulty_level,
|
|
|
'importance' => $mistake->importance,
|
|
'importance' => $mistake->importance,
|
|
|
'mastery_level' => $mistake->mastery_level,
|
|
'mastery_level' => $mistake->mastery_level,
|
|
|
|
|
+ // 【新增】知识点信息
|
|
|
|
|
+ 'knowledge_points' => $knowledgePoints,
|
|
|
|
|
+ // 【保留】options、question_type 字段(从 questions 表查询的)
|
|
|
|
|
+ 'options' => $questionDetails['options'] ?? null,
|
|
|
|
|
+ 'question_type' => $questionDetails['question_type'] ?? null,
|
|
|
|
|
+ // 【移除】answer、solution 字段(从 questions 表查询的)
|
|
|
|
|
+ // 'answer' => $questionDetails['answer'] ?? null,
|
|
|
|
|
+ // 'solution' => $questionDetails['solution'] ?? null,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
if ($detailed) {
|
|
if ($detailed) {
|
|
@@ -751,4 +767,73 @@ class MistakeBookService
|
|
|
Log::debug('缓存清除失败(可忽略)', ['error' => $e->getMessage()]);
|
|
Log::debug('缓存清除失败(可忽略)', ['error' => $e->getMessage()]);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新增】通过 question_id 获取题目详情
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getQuestionDetails(?string $questionId): ?array
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!$questionId) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $question = \DB::connection('mysql')
|
|
|
|
|
+ ->table('questions')
|
|
|
|
|
+ ->where('id', $questionId)
|
|
|
|
|
+ ->first();
|
|
|
|
|
+
|
|
|
|
|
+ if (!$question) {
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'stem' => $question->stem ?? null,
|
|
|
|
|
+ 'options' => $question->options ?? null,
|
|
|
|
|
+ 'answer' => $question->answer ?? null,
|
|
|
|
|
+ 'solution' => $question->solution ?? null,
|
|
|
|
|
+ 'difficulty' => $question->difficulty ?? null,
|
|
|
|
|
+ 'question_type' => $question->question_type ?? null,
|
|
|
|
|
+ ];
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::warning('获取题目详情失败', [
|
|
|
|
|
+ 'question_id' => $questionId,
|
|
|
|
|
+ 'error' => $e->getMessage()
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return null;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 【新增】通过 kp_ids 获取知识点信息
|
|
|
|
|
+ */
|
|
|
|
|
+ private function getKnowledgePoints(?array $kpIds): array
|
|
|
|
|
+ {
|
|
|
|
|
+ if (empty($kpIds)) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ $knowledgePoints = \DB::connection('mysql')
|
|
|
|
|
+ ->table('knowledge_points')
|
|
|
|
|
+ ->whereIn('kp_code', $kpIds)
|
|
|
|
|
+ ->select(['kp_code', 'name', 'parent_kp_code'])
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+
|
|
|
|
|
+ return array_map(function ($kp) {
|
|
|
|
|
+ return [
|
|
|
|
|
+ 'kp_code' => $kp->kp_code,
|
|
|
|
|
+ 'name' => $kp->name ?? $kp->kp_code,
|
|
|
|
|
+ 'parent_kp_code' => $kp->parent_kp_code,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }, $knowledgePoints);
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Log::warning('获取知识点信息失败', [
|
|
|
|
|
+ 'kp_ids' => $kpIds,
|
|
|
|
|
+ 'error' => $e->getMessage()
|
|
|
|
|
+ ]);
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|