| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Services\KnowledgeMasteryService;
- use Illuminate\Http\JsonResponse;
- use Illuminate\Http\Request;
- /**
- * 知识点掌握情况 API 控制器
- *
- * 提供:
- * 1. 获取学生知识点掌握情况统计
- * 2. 获取知识点图谱数据(考试快照)
- * 3. 获取知识点图谱快照列表
- */
- class KnowledgeMasteryController extends Controller
- {
- protected KnowledgeMasteryService $service;
- public function __construct(KnowledgeMasteryService $service)
- {
- $this->service = $service;
- }
- /**
- * 获取学生知识点掌握情况统计
- *
- * GET /api/knowledge-mastery/stats/{studentId}
- *
- * @param string $studentId 学生ID
- * @return JsonResponse
- */
- public function stats(string $studentId): JsonResponse
- {
- $result = $this->service->getStats($studentId);
- if (!$result['success']) {
- return response()->json([
- 'success' => false,
- 'message' => $result['error'] ?? '获取知识点掌握情况失败',
- ], 500);
- }
- return response()->json([
- 'success' => true,
- 'data' => $result['data'],
- ]);
- }
- /**
- * 获取学生知识点掌握摘要(简化版)
- *
- * GET /api/knowledge-mastery/summary/{studentId}
- *
- * @param string $studentId 学生ID
- * @return JsonResponse
- */
- public function summary(string $studentId): JsonResponse
- {
- $result = $this->service->getSummary($studentId);
- if (!$result['success']) {
- return response()->json([
- 'success' => false,
- 'message' => $result['error'] ?? '获取知识点掌握摘要失败',
- ], 500);
- }
- return response()->json([
- 'success' => true,
- 'data' => $result['data'],
- ]);
- }
- /**
- * 获取学生知识点图谱数据
- *
- * GET /api/knowledge-mastery/graph/{studentId}
- *
- * @param Request $request
- * @param string $studentId 学生ID
- * @return JsonResponse
- */
- public function graph(Request $request, string $studentId): JsonResponse
- {
- $examId = $request->query('exam_id');
- $result = $this->service->getGraph($studentId, $examId);
- if (!$result['success']) {
- return response()->json([
- 'success' => false,
- 'message' => $result['error'] ?? '获取知识点图谱失败',
- ], 500);
- }
- return response()->json([
- 'success' => true,
- 'data' => $result['data'],
- ]);
- }
- /**
- * 获取学生知识点图谱快照列表
- *
- * GET /api/knowledge-mastery/graph/snapshots/{studentId}
- *
- * @param Request $request
- * @param string $studentId 学生ID
- * @return JsonResponse
- */
- public function graphSnapshots(Request $request, string $studentId): JsonResponse
- {
- $limit = (int) $request->query('limit', 10);
- $result = $this->service->getGraphSnapshots($studentId, $limit);
- if (!$result['success']) {
- return response()->json([
- 'success' => false,
- 'message' => $result['error'] ?? '获取知识点图谱快照列表失败',
- ], 500);
- }
- return response()->json([
- 'success' => true,
- 'data' => $result['data'],
- ]);
- }
- /**
- * 创建知识点掌握度快照
- *
- * POST /api/knowledge-mastery/snapshot/{studentId}
- *
- * @param Request $request
- * @param string $studentId 学生ID
- * @return JsonResponse
- */
- public function createSnapshot(Request $request, string $studentId): JsonResponse
- {
- $snapshotType = $request->input('snapshot_type', 'report');
- $sourceId = $request->input('source_id');
- $sourceName = $request->input('source_name');
- $notes = $request->input('notes');
- $result = $this->service->createSnapshot(
- $studentId,
- $snapshotType,
- $sourceId,
- $sourceName,
- $notes
- );
- if (!$result['success']) {
- return response()->json([
- 'success' => false,
- 'message' => $result['error'] ?? '创建知识点掌握度快照失败',
- ], 500);
- }
- return response()->json([
- 'success' => true,
- 'message' => '快照创建成功',
- 'data' => $result['data'],
- ]);
- }
- }
|