Parcourir la source

学情分析修复和增加教材系列状态

yemeishu il y a 8 heures
Parent
commit
eb3c1723a3
1 fichiers modifiés avec 45 ajouts et 10 suppressions
  1. 45 10
      app/Services/ExamAnswerAnalysisService.php

+ 45 - 10
app/Services/ExamAnswerAnalysisService.php

@@ -240,33 +240,68 @@ class ExamAnswerAnalysisService
                 ->orWhere('question_code', $questionId)
                 ->orWhere('question_code', $questionId)
                 ->first();
                 ->first();
 
 
+            $kpCode = null;
             if ($question) {
             if ($question) {
                 // 尝试从 kp_code 或 knowledge_point 字段获取
                 // 尝试从 kp_code 或 knowledge_point 字段获取
                 $kpCode = $question->kp_code
                 $kpCode = $question->kp_code
                     ?? $question->knowledge_point
                     ?? $question->knowledge_point
                     ?? $question->knowledge_points
                     ?? $question->knowledge_points
                     ?? null;
                     ?? null;
+            }
 
 
-                if ($kpCode) {
-                    return [
-                        'kp_id' => $kpCode,
-                        'kp_name' => $kpCode
-                    ];
-                }
+            // 如果questions表中没有,从knowledge_points表查找
+            if (!$kpCode) {
+                $kpCode = $questionId; // 假设question_id就是kp_code
+            }
+
+            // 从 knowledge_points 表获取知识点详细信息(包含中文名称)
+            $kpInfo = DB::connection('mysql')
+                ->table('knowledge_points')
+                ->where('kp_code', $kpCode)
+                ->first();
+
+            if ($kpInfo) {
+                Log::debug('从knowledge_points表获取知识点', [
+                    'question_id' => $questionId,
+                    'kp_code' => $kpCode,
+                    'kp_name' => $kpInfo->name
+                ]);
+                return [
+                    'kp_id' => $kpCode,
+                    'kp_name' => $kpInfo->name
+                ];
             }
             }
 
 
             // 备选:从 QuestionBank API 获取知识点
             // 备选:从 QuestionBank API 获取知识点
             $questionBankInfo = $this->getQuestionFromQuestionBank($questionId);
             $questionBankInfo = $this->getQuestionFromQuestionBank($questionId);
             if ($questionBankInfo && !empty($questionBankInfo['knowledge_points'])) {
             if ($questionBankInfo && !empty($questionBankInfo['knowledge_points'])) {
-                $kpCode = $questionBankInfo['knowledge_points'][0]['code'] ?? null;
-                if ($kpCode) {
+                $apiKpCode = $questionBankInfo['knowledge_points'][0]['code'] ?? null;
+                if ($apiKpCode) {
+                    // 尝试从 knowledge_points 表获取中文名称
+                    $apiKpInfo = DB::connection('mysql')
+                        ->table('knowledge_points')
+                        ->where('kp_code', $apiKpCode)
+                        ->first();
+
                     return [
                     return [
-                        'kp_id' => $kpCode,
-                        'kp_name' => $questionBankInfo['knowledge_points'][0]['name'] ?? $kpCode
+                        'kp_id' => $apiKpCode,
+                        'kp_name' => $apiKpInfo->name ?? ($questionBankInfo['knowledge_points'][0]['name'] ?? $apiKpCode)
                     ];
                     ];
                 }
                 }
             }
             }
 
 
+            // 最后备选:使用kpCode作为名称
+            if ($kpCode) {
+                Log::warning('未找到知识点中文名称,使用编码作为名称', [
+                    'question_id' => $questionId,
+                    'kp_code' => $kpCode
+                ]);
+                return [
+                    'kp_id' => $kpCode,
+                    'kp_name' => $kpCode
+                ];
+            }
+
             return null;
             return null;
 
 
         } catch (\Exception $e) {
         } catch (\Exception $e) {