student-dashboard 页面的实现方式文件: app/Services/KnowledgeGraphService.php
核心功能:
config('services.knowledge_api.base_url')listKnowledgePoints() 方法获取知识点列表getSkillsByKnowledgePoint() 方法根据知识点获取技能listSkills() 方法获取所有技能配置读取方式:
$this->baseUrl = config('services.knowledge_api.base_url', env('KNOWLEDGE_API_BASE', 'http://localhost:5011'));
文件: app/Filament/Pages/QuestionManagement.php
修改内容:
Http 调用KnowledgeGraphServiceupdatedGenerateKpCode() 监听方法skillsOptions() 计算属性关键代码:
public function updatedGenerateKpCode(): void
{
// 选择新知识点时重置技能选择
$this->selectedSkills = [];
}
#[Computed]
public function skillsOptions(): array
{
if (!$this->generateKpCode) {
return [];
}
$service = app(KnowledgeGraphService::class);
return $service->getSkillsByKnowledgePoint($this->generateKpCode);
}
文件: app/Services/QuestionServiceApi.php
修改内容:
KnowledgeGraphService 替代 KnowledgeServiceApi关键代码:
public function getKnowledgePointOptions(): array
{
try {
$knowledgeService = app(KnowledgeGraphService::class);
$points = $knowledgeService->listKnowledgePoints(1, 1000);
// 转换为键值对格式
$options = [];
foreach ($points as $point) {
$code = $point['code'];
$name = $point['name'];
$options[$code] = $name;
}
// 按名称排序
asort($options);
return $options;
} catch (\Exception $e) {
\Log::error('Failed to get knowledge points: ' . $e->getMessage());
return [];
}
}
# 测试知识点列表
curl http://localhost:5011/knowledge-points/
# ✅ 返回: KP7001 - 代数语言入门
# 测试技能列表
curl http://localhost:5011/graph/node/KP7001
# ✅ 返回: 5个技能
php artisan tinker --execute="
\$service = new App\Services\KnowledgeGraphService();
\$points = \$service->listKnowledgePoints(1, 5);
echo 'Knowledge Points: ' . count(\$points) . PHP_EOL;
echo 'First KP: ' . \$points[0]['code'] . ' - ' . \$points[0]['name'] . PHP_EOL;
\$skills = \$service->getSkillsByKnowledgePoint('KP7001');
echo 'Skills for KP7001: ' . count(\$skills) . PHP_EOL;
"
结果:
测试步骤:
http://fa.test/admin/question-management预期效果:
问题:
http://localhost:5011updatedGenerateKpCode 监听方法改进:
在 .env 文件中添加:
KNOWLEDGE_API_BASE=http://localhost:5011
或在 config/services.php 中添加:
'knowledge_api' => [
'base_url' => env('KNOWLEDGE_API_BASE', 'http://localhost:5011'),
],
// 获取知识点列表
$service = app(KnowledgeGraphService::class);
$points = $service->listKnowledgePoints(1, 100);
// 根据知识点获取技能
$skills = $service->getSkillsByKnowledgePoint('KP7001');
// 检查服务健康状态
$isHealthy = $service->checkHealth();
这个 KnowledgeGraphService 可以在以下地方复用:
通过这次优化:
优化时间: 2025-11-19 14:15
状态: ✅ 完成
作者: Claude Code