refactor: 修复知识库和操作指引

This commit is contained in:
2026-03-13 14:32:37 +08:00
parent bbe8e60646
commit 58f42de9df
88 changed files with 3387 additions and 2472 deletions

View File

@@ -0,0 +1,219 @@
<?php
namespace Database\Seeders;
use App\Models\Guide;
use App\Models\GuidePage;
use App\Models\Terminal;
use App\Models\User;
use Illuminate\Database\Seeder;
class GuideSeeder extends Seeder
{
private const BASE_URL = 'https://ssrf.9z.work/guides';
/**
* Run the database seeds.
*/
public function run(): void
{
$this->command->info('开始创建操作指引数据...');
$admin = User::where('email', 'admin@example.com')->first();
$terminals = Terminal::all();
// 1. 如何用光(带分支)
$guide1 = $this->createHowToUseBeamGuide($admin);
// 2. 真空阀门故障处理
$guide2 = $this->createVacuumValveIssueGuide($admin);
// 3. 漏水报警处理
$guide3 = $this->createWaterLeakAlarmGuide($admin);
// 将所有指引关联到所有终端
$this->command->info('关联指引到所有终端...');
foreach ($terminals as $terminal) {
$terminal->guides()->attach([
$guide1->id => ['priority' => 1],
$guide2->id => ['priority' => 2],
$guide3->id => ['priority' => 3],
]);
}
$this->command->info('操作指引数据创建完成!');
$this->command->info(' - 指引数量: ' . Guide::count());
$this->command->info(' - 指引页面数量: ' . GuidePage::count());
$this->command->info(' - 关联终端数量: ' . $terminals->count());
}
private function createHowToUseBeamGuide(User $admin): Guide
{
$this->command->info('创建指引: 如何用光...');
$guide = Guide::create([
'name' => '如何用光',
'description' => '光束线用光操作完整流程指引包含前门12和后门两条路径',
'category' => 'operation',
'tags' => ['用光', '光闸', 'PS1', '光学棚屋'],
'status' => 'published',
'created_by' => $admin->id,
'published_at' => now(),
]);
$baseUrl = self::BASE_URL . '/how-to-use-beam';
// 步骤1: 打开光子光闸 PS1根节点
$step1 = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 1,
'title' => '打开光子光闸 PS1',
'html_url' => "{$baseUrl}/step-1.html",
'parent_id' => -1,
'sort_order' => 0,
]);
// 步骤2: 搜索光学棚屋带选项前门12 / 后门)
$step2 = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 2,
'title' => '搜索光学棚屋',
'html_url' => "{$baseUrl}/step-2.html",
'parent_id' => $step1->id,
'sort_order' => 1,
'options' => ['前门12', '后门'],
]);
// 步骤3a: 前门12路径 - 检查设备状态
$step3a = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 3,
'title' => '前门12路径 - 检查设备状态',
'html_url' => "{$baseUrl}/step-3a.html",
'parent_id' => $step2->id,
'sort_order' => 0,
'branch_option' => '前门12',
]);
// 步骤3b: 后门路径 - 安全确认
$step3b = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 3,
'title' => '后门路径 - 安全确认',
'html_url' => "{$baseUrl}/step-3b.html",
'parent_id' => $step2->id,
'sort_order' => 1,
'branch_option' => '后门',
]);
// 步骤4a: 前门12路径 - 打开实验站光闸
GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 4,
'title' => '前门12路径 - 打开实验站光闸',
'html_url' => "{$baseUrl}/step-4a.html",
'parent_id' => $step3a->id,
'sort_order' => 0,
]);
// 步骤4b: 后门路径 - 设备检查
GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 4,
'title' => '后门路径 - 设备检查',
'html_url' => "{$baseUrl}/step-4b.html",
'parent_id' => $step3b->id,
'sort_order' => 0,
]);
// 步骤5: 完成(根节点,最终汇合)
GuidePage::create([
'guide_id' => $guide->id,
'page_number' => 5,
'title' => '完成',
'html_url' => "{$baseUrl}/step-5.html",
'parent_id' => -1,
'sort_order' => 1,
]);
return $guide;
}
private function createVacuumValveIssueGuide(User $admin): Guide
{
$this->command->info('创建指引: 真空阀门故障处理...');
$guide = Guide::create([
'name' => '真空阀门故障处理',
'description' => '真空阀门异常时的排查和处理流程',
'category' => 'fault_handling',
'tags' => ['真空', '阀门', '故障', '联锁', '气动'],
'status' => 'published',
'created_by' => $admin->id,
'published_at' => now(),
]);
$baseUrl = self::BASE_URL . '/vacuum-valve-issue';
$steps = [
['title' => '检查真空度', 'file' => 'step-1.html'],
['title' => '检查联锁状态', 'file' => 'step-2.html'],
['title' => '尝试手动复位', 'file' => 'step-3.html'],
['title' => '检查气动系统', 'file' => 'step-4.html'],
['title' => '联系维护人员', 'file' => 'step-5.html'],
];
$parentId = -1;
foreach ($steps as $i => $step) {
$page = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => $i + 1,
'title' => $step['title'],
'html_url' => "{$baseUrl}/{$step['file']}",
'parent_id' => $parentId,
'sort_order' => $parentId === -1 ? $i : 0,
]);
$parentId = $page->id;
}
return $guide;
}
private function createWaterLeakAlarmGuide(User $admin): Guide
{
$this->command->info('创建指引: 漏水报警处理...');
$guide = Guide::create([
'name' => '漏水报警处理',
'description' => '漏水报警时的应急处理和复位流程',
'category' => 'fault_handling',
'tags' => ['漏水', '报警', '应急', '复位'],
'status' => 'published',
'created_by' => $admin->id,
'published_at' => now(),
]);
$baseUrl = self::BASE_URL . '/water-leak-alarm';
$steps = [
['title' => '确认报警位置', 'file' => 'step-1.html'],
['title' => '搜索光学棚屋', 'file' => 'step-2.html'],
['title' => '定位并处理漏水点', 'file' => 'step-3.html'],
['title' => '复位报警', 'file' => 'step-4.html'],
['title' => '完成', 'file' => 'step-5.html'],
];
$parentId = -1;
foreach ($steps as $i => $step) {
$page = GuidePage::create([
'guide_id' => $guide->id,
'page_number' => $i + 1,
'title' => $step['title'],
'html_url' => "{$baseUrl}/{$step['file']}",
'parent_id' => $parentId,
'sort_order' => $parentId === -1 ? $i : 0,
]);
$parentId = $page->id;
}
return $guide;
}
}