refactor: kb & station & terminal
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Group;
|
||||
use App\Models\Station;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
@@ -13,231 +12,79 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
use WithoutModelEvents;
|
||||
|
||||
/**
|
||||
* Seed the application's database.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('开始生成演示数据...');
|
||||
|
||||
// 0. 创建权限和角色(必须最先执行)
|
||||
// 0. 权限和角色
|
||||
$this->call(PermissionSeeder::class);
|
||||
|
||||
// 1. 创建系统设置
|
||||
// 1. 系统设置
|
||||
$this->call(SystemSettingSeeder::class);
|
||||
|
||||
// 2. 创建管理员用户
|
||||
$this->command->info('创建管理员用户...');
|
||||
// 2. 创建用户
|
||||
|
||||
$pass = 'TRG}E^5BvPcbyErc';
|
||||
|
||||
$this->command->info('创建用户...');
|
||||
$admin = User::factory()->create([
|
||||
'name' => '系统管理员',
|
||||
'email' => 'admin@example.com',
|
||||
'password' => Hash::make('TRG}E^5BvPcbyErc'),
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
|
||||
// 为管理员分配 super-admin 角色
|
||||
$admin->assignRole('super-admin');
|
||||
|
||||
// 3. 创建普通用户
|
||||
$this->command->info('创建普通用户...');
|
||||
$user1 = User::factory()->create([
|
||||
'name' => '张三',
|
||||
'email' => 'zhangsan@example.com',
|
||||
'password' => Hash::make('TRG}E^5BvPcbyErc'),
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
$user1->assignRole('user');
|
||||
|
||||
$user2 = User::factory()->create([
|
||||
'name' => '李四',
|
||||
'email' => 'lisi@example.com',
|
||||
'password' => Hash::make('TRG}E^5BvPcbyErc'),
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
$user2->assignRole('user');
|
||||
|
||||
$user3 = User::factory()->create([
|
||||
'name' => '王五',
|
||||
'email' => 'wangwu@example.com',
|
||||
'password' => Hash::make('TRG}E^5BvPcbyErc'),
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
$user3->assignRole('admin');
|
||||
|
||||
$user4 = User::factory()->create([
|
||||
'name' => '赵六',
|
||||
'email' => 'zhaoliu@example.com',
|
||||
'password' => Hash::make('TRG}E^5BvPcbyErc'),
|
||||
'password' => Hash::make($pass),
|
||||
]);
|
||||
$user4->assignRole('user');
|
||||
|
||||
// 3. 创建分组(按照光束线)
|
||||
$this->command->info('创建光束线分组...');
|
||||
$beamlines = [
|
||||
'BL02U1',
|
||||
'BL07U',
|
||||
'BL08U',
|
||||
'BL13HB',
|
||||
'BL13U',
|
||||
'BL14B',
|
||||
'BL14W',
|
||||
'BL15U',
|
||||
'BL16B',
|
||||
'BL16U1',
|
||||
];
|
||||
|
||||
$groups = [];
|
||||
foreach ($beamlines as $beamline) {
|
||||
$groups[$beamline] = Group::factory()->create([
|
||||
'name' => $beamline,
|
||||
'description' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
// 4. 建立用户和分组的关联关系
|
||||
$this->command->info('建立用户和分组的关联关系...');
|
||||
// 管理员属于所有光束线分组
|
||||
$admin->groups()->attach(array_column($groups, 'id'));
|
||||
|
||||
// 张三和李四属于 BL02U1
|
||||
$user1->groups()->attach($groups['BL02U1']->id);
|
||||
$user2->groups()->attach($groups['BL02U1']->id);
|
||||
|
||||
// 王五属于 BL07U
|
||||
$user3->groups()->attach($groups['BL07U']->id);
|
||||
|
||||
// 赵六属于 BL08U
|
||||
$user4->groups()->attach($groups['BL08U']->id);
|
||||
|
||||
// 5. 创建全局文档(仅元数据,不创建实际文件)
|
||||
$this->command->info('创建全局文档...');
|
||||
Document::create([
|
||||
'title' => '公司员工手册',
|
||||
'description' => '包含公司规章制度、员工福利、考勤制度等重要信息',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => '员工手册_2024.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'global',
|
||||
'group_id' => null,
|
||||
'uploaded_by' => $admin->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
Document::create([
|
||||
'title' => '办公室使用规范',
|
||||
'description' => '办公室设施使用规范和注意事项',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => '办公室规范.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'global',
|
||||
'group_id' => null,
|
||||
'uploaded_by' => $admin->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
Document::create([
|
||||
'title' => '公司年度总结报告',
|
||||
'description' => '2024年度公司发展总结和2025年规划',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => '年度总结_2024.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'global',
|
||||
'group_id' => null,
|
||||
'uploaded_by' => $admin->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
Document::create([
|
||||
'title' => '安全管理制度',
|
||||
'description' => '公司信息安全和物理安全管理制度',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => '安全管理制度.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'global',
|
||||
'group_id' => null,
|
||||
'uploaded_by' => $admin->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
// 6. 创建 BL02U1 光束线专用文档
|
||||
$this->command->info('创建 BL02U1 光束线专用文档...');
|
||||
Document::create([
|
||||
'title' => 'BL02U1 操作手册',
|
||||
'description' => 'BL02U1 光束线设备操作规程和注意事项',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => 'BL02U1_操作手册.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'dedicated',
|
||||
'group_id' => $groups['BL02U1']->id,
|
||||
'uploaded_by' => $user1->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
Document::create([
|
||||
'title' => 'BL02U1 维护记录',
|
||||
'description' => 'BL02U1 光束线设备维护和检修记录',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => 'BL02U1_维护记录.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'dedicated',
|
||||
'group_id' => $groups['BL02U1']->id,
|
||||
'uploaded_by' => $user2->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
// 7. 创建 BL07U 光束线专用文档
|
||||
$this->command->info('创建 BL07U 光束线专用文档...');
|
||||
Document::create([
|
||||
'title' => 'BL07U 操作手册',
|
||||
'description' => 'BL07U 光束线设备操作规程和注意事项',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => 'BL07U_操作手册.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'dedicated',
|
||||
'group_id' => $groups['BL07U']->id,
|
||||
'uploaded_by' => $user3->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
// 8. 创建 BL08U 光束线专用文档
|
||||
$this->command->info('创建 BL08U 光束线专用文档...');
|
||||
Document::create([
|
||||
'title' => 'BL08U 操作手册',
|
||||
'description' => 'BL08U 光束线设备操作规程和注意事项',
|
||||
'file_path' => 'documents/' . date('Y/m/d') . '/' . fake()->uuid() . '.docx',
|
||||
'file_name' => 'BL08U_操作手册.docx',
|
||||
'file_size' => fake()->numberBetween(100000, 500000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => 'dedicated',
|
||||
'group_id' => $groups['BL08U']->id,
|
||||
'uploaded_by' => $user4->id,
|
||||
'conversion_status' => 'pending',
|
||||
]);
|
||||
|
||||
$this->command->info('演示数据生成完成!');
|
||||
|
||||
// 9. 创建终端数据
|
||||
// 3. 创建线站、知识库、终端
|
||||
$this->call(TerminalSeeder::class);
|
||||
|
||||
// 10. 创建操作指引数据
|
||||
// 4. 用户关联线站(管理员不关联 = 可访问全部)
|
||||
$this->command->info('建立用户-线站关联...');
|
||||
$bl02u1 = Station::where('name', 'BL02U1')->first();
|
||||
$bl07u = Station::where('name', 'BL07U')->first();
|
||||
$bl08u = Station::where('name', 'BL08U')->first();
|
||||
|
||||
$user1->stations()->attach($bl02u1);
|
||||
$user2->stations()->attach($bl02u1);
|
||||
$user3->stations()->attach($bl07u);
|
||||
$user4->stations()->attach($bl08u);
|
||||
|
||||
// 5. 操作指引
|
||||
$this->call(GuideSeeder::class);
|
||||
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的数据摘要 ===');
|
||||
$this->command->info('用户数量: ' . User::count());
|
||||
$this->command->info('分组数量: ' . Group::count());
|
||||
$this->command->info('文档数量: ' . Document::count());
|
||||
$this->command->info(' - 全局文档: ' . Document::global()->count());
|
||||
$this->command->info(' - 专用文档: ' . Document::dedicated()->count());
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 测试账号信息 ===');
|
||||
$this->command->info('超级管理员: admin@example.com / TRG}E^5BvPcbyErc (super-admin)');
|
||||
$this->command->info('张三(BL02U1): zhangsan@example.com / TRG}E^5BvPcbyErc (user)');
|
||||
$this->command->info('李四(BL02U1): lisi@example.com / TRG}E^5BvPcbyErc (user)');
|
||||
$this->command->info('王五(BL07U): wangwu@example.com / TRG}E^5BvPcbyErc (admin)');
|
||||
$this->command->info('赵六(BL08U): zhaoliu@example.com / TRG}E^5BvPcbyErc (user)');
|
||||
$this->command->info("{$admin->name} : {$admin->email} / $pass");
|
||||
$this->command->info("{$user1->name}({$bl02u1->name}): {$user1->email} / $pass");
|
||||
$this->command->info("{$user2->name}({$bl02u1->name}): {$user2->email} / $pass");
|
||||
$this->command->info("{$user3->name}({$bl07u->name}): {$user3->email} / $pass");
|
||||
$this->command->info("{$user4->name}({$bl08u->name}): {$user4->email} / $pass");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace Database\Seeders;
|
||||
|
||||
use App\Models\Guide;
|
||||
use App\Models\GuidePage;
|
||||
use App\Models\Terminal;
|
||||
use App\Models\Station;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -20,7 +20,7 @@ class GuideSeeder extends Seeder
|
||||
$this->command->info('开始创建操作指引数据...');
|
||||
|
||||
$admin = User::where('email', 'admin@example.com')->first();
|
||||
$terminals = Terminal::all();
|
||||
$stations = Station::all();
|
||||
|
||||
// 1. 如何用光(带分支)
|
||||
$guide1 = $this->createHowToUseBeamGuide($admin);
|
||||
@@ -31,20 +31,17 @@ class GuideSeeder extends Seeder
|
||||
// 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('关联指引到所有线站...');
|
||||
$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(' - 关联终端数量: ' . $terminals->count());
|
||||
$this->command->info(' - 关联线站数量: ' . $stations->count());
|
||||
}
|
||||
|
||||
private function createHowToUseBeamGuide(User $admin): Guide
|
||||
|
||||
@@ -46,11 +46,11 @@ class PermissionSeeder extends Seeder
|
||||
'guide.publish' => '发布指引',
|
||||
'guide.archive' => '归档指引',
|
||||
|
||||
// 分组管理权限
|
||||
'group.view' => '查看分组',
|
||||
'group.create' => '创建分组',
|
||||
'group.update' => '编辑分组',
|
||||
'group.delete' => '删除分组',
|
||||
// 线站管理权限
|
||||
'station.view' => '查看线站',
|
||||
'station.create' => '创建线站',
|
||||
'station.update' => '编辑线站',
|
||||
'station.delete' => '删除线站',
|
||||
|
||||
// 用户管理权限
|
||||
'user.view' => '查看用户',
|
||||
@@ -126,6 +126,12 @@ class PermissionSeeder extends Seeder
|
||||
'terminal.update',
|
||||
'terminal.delete',
|
||||
|
||||
// 线站管理
|
||||
'station.view',
|
||||
'station.create',
|
||||
'station.update',
|
||||
'station.delete',
|
||||
|
||||
// 操作指引
|
||||
'guide.view',
|
||||
'guide.create',
|
||||
@@ -134,12 +140,6 @@ class PermissionSeeder extends Seeder
|
||||
'guide.publish',
|
||||
'guide.archive',
|
||||
|
||||
// 分组管理
|
||||
'group.view',
|
||||
'group.create',
|
||||
'group.update',
|
||||
'group.delete',
|
||||
|
||||
// 用户管理
|
||||
'user.view',
|
||||
'user.create',
|
||||
@@ -167,14 +167,14 @@ class PermissionSeeder extends Seeder
|
||||
'document.create',
|
||||
'document.download',
|
||||
|
||||
// 终端管理(仅查看)
|
||||
// 终端查看
|
||||
'terminal.view',
|
||||
|
||||
// 操作指引(仅查看)
|
||||
'guide.view',
|
||||
// 线站查看
|
||||
'station.view',
|
||||
|
||||
// 分组管理(仅查看)
|
||||
'group.view',
|
||||
// 操作指引查看
|
||||
'guide.view',
|
||||
];
|
||||
|
||||
$role->givePermissionTo($permissions);
|
||||
|
||||
@@ -2,20 +2,18 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\KnowledgeBase;
|
||||
use App\Models\Station;
|
||||
use App\Models\Terminal;
|
||||
use App\Models\TerminalPrompt;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class TerminalSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('开始创建终端数据...');
|
||||
$this->command->info('开始创建线站、知识库和终端...');
|
||||
|
||||
// 光束线列表
|
||||
$beamlines = [
|
||||
'BL02U1' => '192.168.1.21',
|
||||
'BL07U' => '192.168.1.27',
|
||||
@@ -29,19 +27,32 @@ class TerminalSeeder extends Seeder
|
||||
'BL16U1' => '192.168.1.39',
|
||||
];
|
||||
|
||||
// 默认提示词模板(占位符由HMI端替换)
|
||||
$defaultPrompt = <<<'PROMPT'
|
||||
你是{station_id}光束线的AI助手。当前时间是{time}。请根据用户{user}的问题,提供准确的光束线操作指导、实验支持和技术咨询。你可以回答关于光束线参数、实验流程、设备状态、安全规范等方面的问题。
|
||||
你是{station_name}光束线的AI助手(终端: {terminal_name} / {terminal_code})。当前时间是{time}。请根据用户{user}的问题,提供准确的光束线操作指导、实验支持和技术咨询。你可以回答关于光束线参数、实验流程、设备状态、安全规范等方面的问题。
|
||||
PROMPT;
|
||||
|
||||
// 为每条光束线创建智慧屏终端
|
||||
$this->command->info('创建光束线智慧屏终端...');
|
||||
// 创建通用知识库(全局,不关联线站)
|
||||
$this->command->info('创建通用知识库...');
|
||||
KnowledgeBase::create(['name' => '通用知识库', 'description' => '全站通用的规章制度和管理文档', 'status' => 'active']);
|
||||
|
||||
foreach ($beamlines as $beamline => $ipAddress) {
|
||||
// 创建线站
|
||||
$station = Station::firstOrCreate(['name' => $beamline]);
|
||||
|
||||
// 创建线站专属知识库并关联
|
||||
$kb = KnowledgeBase::create([
|
||||
'name' => "{$beamline} 知识库",
|
||||
'description' => "{$beamline} 光束线专用文档",
|
||||
'status' => 'active',
|
||||
]);
|
||||
$station->knowledgeBases()->attach($kb);
|
||||
|
||||
// 创建终端
|
||||
$terminal = Terminal::create([
|
||||
'name' => "{$beamline} 智慧屏",
|
||||
'code' => "SCREEN-{$beamline}",
|
||||
'ip_address' => $ipAddress,
|
||||
'station_id' => $beamline,
|
||||
'station_id' => $station->id,
|
||||
'diagram_url' => 'https://ssrf.9z.work/scada/demo.html',
|
||||
'is_online' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U']),
|
||||
'last_online_at' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U'])
|
||||
@@ -49,7 +60,6 @@ PROMPT;
|
||||
: now()->subHours(rand(1, 24)),
|
||||
]);
|
||||
|
||||
// 为每个终端创建提示词
|
||||
TerminalPrompt::create([
|
||||
'terminal_id' => $terminal->id,
|
||||
'prompt_template' => $defaultPrompt,
|
||||
@@ -57,12 +67,9 @@ PROMPT;
|
||||
]);
|
||||
}
|
||||
|
||||
$this->command->info('终端数据创建完成!');
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的终端摘要 ===');
|
||||
$this->command->info('总终端数量: ' . Terminal::count());
|
||||
$this->command->info(' - 在线终端: ' . Terminal::where('is_online', true)->count());
|
||||
$this->command->info(' - 离线终端: ' . Terminal::where('is_online', false)->count());
|
||||
$this->command->info(' - 配置提示词的终端: ' . TerminalPrompt::count());
|
||||
$this->command->info('线站/知识库/终端创建完成!');
|
||||
$this->command->info(' - 线站: ' . Station::count());
|
||||
$this->command->info(' - 知识库: ' . KnowledgeBase::count());
|
||||
$this->command->info(' - 终端: ' . Terminal::count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user