refactor: kb & station & terminal
This commit is contained in:
@@ -22,20 +22,20 @@ class TerminalApiController extends Controller
|
||||
public function config(Request $request): JsonResponse
|
||||
{
|
||||
$terminal = $request->attributes->get('terminal');
|
||||
$terminal->load('prompt');
|
||||
$terminal->load(['prompt', 'station']);
|
||||
|
||||
// 返回原始提示词模板(占位符由HMI端替换)
|
||||
// 返回原始提示词模板
|
||||
$systemPrompt = $terminal->prompt?->prompt_template ?? '';
|
||||
|
||||
// 获取终端关联的已发布指引数量
|
||||
$guideCount = $terminal->guides()->published()->count();
|
||||
// 获取终端所属线站的已发布指引数量(含全局指引)
|
||||
$guideCount = $this->getTerminalGuides($terminal)->count();
|
||||
|
||||
return response()->json([
|
||||
'terminal' => [
|
||||
'id' => $terminal->id,
|
||||
'name' => $terminal->name,
|
||||
'code' => $terminal->code,
|
||||
'station_id' => $terminal->station_id,
|
||||
'terminal_name' => $terminal->name,
|
||||
'terminal_code' => $terminal->code,
|
||||
'station_name' => $terminal->station?->name,
|
||||
'diagram_url' => $terminal->diagram_url,
|
||||
'scada_data_url' => $terminal->scada_data_url,
|
||||
'scada_tags_url' => $terminal->scada_tags_url,
|
||||
@@ -57,7 +57,8 @@ class TerminalApiController extends Controller
|
||||
'query' => 'required|string|max:500',
|
||||
]);
|
||||
|
||||
$result = $this->knowledgeService->search($request->input('query'));
|
||||
$terminal = $request->attributes->get('terminal');
|
||||
$result = $this->knowledgeService->search($request->input('query'), $terminal);
|
||||
|
||||
return response()->json($result);
|
||||
}
|
||||
@@ -69,7 +70,7 @@ class TerminalApiController extends Controller
|
||||
public function guides(Request $request): JsonResponse
|
||||
{
|
||||
$terminal = $request->attributes->get('terminal');
|
||||
$query = $terminal->guides()->published()->withCount('pages');
|
||||
$query = $this->getTerminalGuides($terminal)->withCount('pages');
|
||||
|
||||
if ($category = $request->input('category')) {
|
||||
$query->where('category', $category);
|
||||
@@ -99,7 +100,7 @@ class TerminalApiController extends Controller
|
||||
]);
|
||||
|
||||
$terminal = $request->attributes->get('terminal');
|
||||
$accessibleIds = $terminal->guides()->published()->pluck('guides.id')->toArray();
|
||||
$accessibleIds = $this->getTerminalGuides($terminal)->pluck('guides.id')->toArray();
|
||||
|
||||
$guideIds = $request->input('guide_ids');
|
||||
$pages = [];
|
||||
@@ -199,6 +200,21 @@ class TerminalApiController extends Controller
|
||||
return $loads;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取终端可见的指引(线站关联 + 全局)
|
||||
*/
|
||||
private function getTerminalGuides($terminal)
|
||||
{
|
||||
$stationId = $terminal->station_id;
|
||||
|
||||
return Guide::published()->where(function ($q) use ($stationId) {
|
||||
$q->whereDoesntHave('stations'); // 全局指引
|
||||
if ($stationId) {
|
||||
$q->orWhereHas('stations', fn ($sq) => $sq->where('stations.id', $stationId));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* POST /api/terminal/heartbeat
|
||||
* 终端心跳上报
|
||||
|
||||
Reference in New Issue
Block a user