217 lines
7.4 KiB
PHP
217 lines
7.4 KiB
PHP
<?php
|
||
|
||
namespace Database\Seeders;
|
||
|
||
use App\Models\Guide;
|
||
use App\Models\GuidePage;
|
||
use App\Models\Station;
|
||
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();
|
||
$stations = Station::all();
|
||
|
||
// 1. 如何用光(带分支)
|
||
$guide1 = $this->createHowToUseBeamGuide($admin);
|
||
|
||
// 2. 真空阀门故障处理
|
||
$guide2 = $this->createVacuumValveIssueGuide($admin);
|
||
|
||
// 3. 漏水报警处理
|
||
$guide3 = $this->createWaterLeakAlarmGuide($admin);
|
||
|
||
// 将指引关联到所有线站(非全局,关联所有线站 = 各线站均可见)
|
||
$this->command->info('关联指引到所有线站...');
|
||
$stationIds = $stations->pluck('id')->toArray();
|
||
$guide1->stations()->attach($stationIds);
|
||
$guide2->stations()->attach($stationIds);
|
||
$guide3->stations()->attach($stationIds);
|
||
|
||
$this->command->info('操作指引数据创建完成!');
|
||
$this->command->info(' - 指引数量: ' . Guide::count());
|
||
$this->command->info(' - 指引页面数量: ' . GuidePage::count());
|
||
$this->command->info(' - 关联线站数量: ' . $stations->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;
|
||
}
|
||
}
|