feat: 创建工厂类和种子数据
- SystemSettingFactory: 系统设置工厂 - TerminalFactory: 终端工厂 - SopTemplateFactory: SOP模板工厂 - SystemSettingSeeder: 系统设置种子数据 - TerminalSeeder: 终端种子数据 - SopTemplateSeeder: SOP模板种子数据 - 更新 DatabaseSeeder 注册新的种子类
This commit is contained in:
61
database/factories/SopTemplateFactory.php
Normal file
61
database/factories/SopTemplateFactory.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SopTemplate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SopTemplate>
|
||||
*/
|
||||
class SopTemplateFactory extends Factory
|
||||
{
|
||||
protected $model = SopTemplate::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->randomElement([
|
||||
'设备启动操作规程',
|
||||
'产品质检标准流程',
|
||||
'安全生产检查清单',
|
||||
'设备维护保养流程',
|
||||
'应急处理操作指南',
|
||||
]) . '-' . fake()->numberBetween(1, 100),
|
||||
'description' => fake()->sentence(20),
|
||||
'category' => fake()->randomElement(['生产操作', '质量管理', '安全管理', '设备维护', '应急处理']),
|
||||
'tags' => fake()->randomElements(['标准作业', '安全', '质量', '效率', '培训'], fake()->numberBetween(1, 3)),
|
||||
'version' => '1.0.0',
|
||||
'status' => fake()->randomElement(['draft', 'published', 'archived']),
|
||||
'applicable_departments' => fake()->randomElements(['生产部', '质检部', '设备部', '安全部'], fake()->numberBetween(1, 2)),
|
||||
'applicable_positions' => fake()->randomElements(['操作员', '质检员', '班组长', '技术员'], fake()->numberBetween(1, 2)),
|
||||
'published_at' => fake()->optional(0.6)->dateTimeBetween('-6 months', 'now'),
|
||||
'created_by' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function draft(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'draft',
|
||||
'published_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function published(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function archived(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'archived',
|
||||
'published_at' => fake()->dateTimeBetween('-1 year', '-1 month'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
104
database/factories/SystemSettingFactory.php
Normal file
104
database/factories/SystemSettingFactory.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SystemSetting;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SystemSetting>
|
||||
*/
|
||||
class SystemSettingFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = SystemSetting::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'key' => fake()->unique()->word(),
|
||||
'value' => [
|
||||
'enabled' => fake()->boolean(),
|
||||
'value' => fake()->word(),
|
||||
],
|
||||
'group' => fake()->randomElement(['general', 'embedding', 'chunking', 'system']),
|
||||
'description' => fake()->sentence(),
|
||||
'is_public' => fake()->boolean(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为嵌入模型配置
|
||||
*/
|
||||
public function embedding(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'embedding',
|
||||
'value' => [
|
||||
'model_name' => fake()->randomElement(['text-embedding-ada-002', 'text-embedding-3-small', 'text-embedding-3-large']),
|
||||
'api_key' => 'sk-' . fake()->uuid(),
|
||||
'endpoint_url' => fake()->url(),
|
||||
'dimensions' => fake()->randomElement([1536, 3072]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为分块参数配置
|
||||
*/
|
||||
public function chunking(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'chunking',
|
||||
'value' => [
|
||||
'chunk_size' => fake()->numberBetween(500, 2000),
|
||||
'chunk_overlap' => fake()->numberBetween(50, 200),
|
||||
'separator' => fake()->randomElement(["\n\n", "\n", " "]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为系统全局配置
|
||||
*/
|
||||
public function system(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'system',
|
||||
'value' => [
|
||||
'system_name' => fake()->company(),
|
||||
'timeout' => fake()->numberBetween(30, 300),
|
||||
'max_retries' => fake()->numberBetween(1, 5),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为公开配置
|
||||
*/
|
||||
public function public(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_public' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为私有配置
|
||||
*/
|
||||
public function private(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_public' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
113
database/factories/TerminalFactory.php
Normal file
113
database/factories/TerminalFactory.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Terminal;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Terminal>
|
||||
*/
|
||||
class TerminalFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Terminal::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->randomElement(['生产线A', '生产线B', '生产线C', '质检站', '包装站']) . '-' . fake()->randomElement(['工位1', '工位2', '工位3']),
|
||||
'code' => 'TERM-' . fake()->unique()->numerify('####'),
|
||||
'ip_address' => fake()->localIpv4(),
|
||||
'station_id' => null, // 需要关联实际的线站ID
|
||||
'diagram_url' => fake()->imageUrl(1920, 1080, 'diagram', true),
|
||||
'display_config' => [
|
||||
'resolution' => fake()->randomElement(['1920x1080', '2560x1440', '3840x2160']),
|
||||
'refresh_rate' => fake()->randomElement([30, 60, 120]),
|
||||
'orientation' => fake()->randomElement(['landscape', 'portrait']),
|
||||
'brightness' => fake()->numberBetween(50, 100),
|
||||
],
|
||||
'is_online' => fake()->boolean(70), // 70%概率在线
|
||||
'last_online_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为在线状态
|
||||
*/
|
||||
public function online(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为离线状态
|
||||
*/
|
||||
public function offline(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_online' => false,
|
||||
'last_online_at' => fake()->dateTimeBetween('-30 days', '-1 day'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为高分辨率配置
|
||||
*/
|
||||
public function highResolution(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'display_config' => [
|
||||
'resolution' => '3840x2160',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 80,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为生产线终端
|
||||
*/
|
||||
public function productionLine(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'name' => '生产线' . fake()->randomElement(['A', 'B', 'C', 'D']) . '-工位' . fake()->numberBetween(1, 10),
|
||||
'code' => 'PROD-' . fake()->unique()->numerify('####'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为质检站终端
|
||||
*/
|
||||
public function qualityControl(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'name' => '质检站-' . fake()->randomElement(['入库检', '出库检', '过程检']) . '-' . fake()->numberBetween(1, 5),
|
||||
'code' => 'QC-' . fake()->unique()->numerify('####'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定终端为包装站终端
|
||||
*/
|
||||
public function packaging(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'name' => '包装站-工位' . fake()->numberBetween(1, 8),
|
||||
'code' => 'PKG-' . fake()->unique()->numerify('####'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,9 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->command->info('开始生成演示数据...');
|
||||
|
||||
// 0. 创建系统设置
|
||||
$this->call(SystemSettingSeeder::class);
|
||||
|
||||
// 1. 创建管理员用户
|
||||
$this->command->info('创建管理员用户...');
|
||||
$admin = User::factory()->create([
|
||||
@@ -200,6 +203,13 @@ class DatabaseSeeder extends Seeder
|
||||
]);
|
||||
|
||||
$this->command->info('演示数据生成完成!');
|
||||
|
||||
// 9. 创建终端数据
|
||||
$this->call(TerminalSeeder::class);
|
||||
|
||||
// 10. 创建SOP模板数据
|
||||
$this->call(SopTemplateSeeder::class);
|
||||
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的数据摘要 ===');
|
||||
$this->command->info('用户数量: ' . User::count());
|
||||
|
||||
236
database/seeders/SopTemplateSeeder.php
Normal file
236
database/seeders/SopTemplateSeeder.php
Normal file
@@ -0,0 +1,236 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\SopTemplate;
|
||||
use App\Models\SopStep;
|
||||
use App\Models\SopInteractiveTask;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SopTemplateSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('开始创建SOP模板数据...');
|
||||
|
||||
// 获取或创建一个用户作为创建者
|
||||
$user = User::first();
|
||||
if (!$user) {
|
||||
$this->command->warn('未找到用户,跳过SOP模板创建');
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. 设备启动操作规程
|
||||
$this->command->info('创建设备启动操作规程...');
|
||||
$template1 = SopTemplate::create([
|
||||
'name' => '生产设备标准启动流程',
|
||||
'description' => '本流程规定了生产设备启动前的检查项目、启动步骤和注意事项,确保设备安全、正常启动。',
|
||||
'category' => '生产操作',
|
||||
'tags' => ['标准作业', '设备操作', '安全'],
|
||||
'version' => '1.0.0',
|
||||
'status' => 'published',
|
||||
'applicable_departments' => ['生产部', '设备部'],
|
||||
'applicable_positions' => ['操作员', '班组长'],
|
||||
'published_at' => now()->subMonths(2),
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
$steps1 = [
|
||||
[
|
||||
'step_number' => 1,
|
||||
'title' => '启动前安全检查',
|
||||
'content' => '<p>检查设备周围环境,确保无障碍物和安全隐患。</p><ul><li>检查设备外观是否完好</li><li>检查安全防护装置是否到位</li><li>检查急停按钮是否正常</li></ul>',
|
||||
'sort_order' => 1,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 2,
|
||||
'title' => '电源系统检查',
|
||||
'content' => '<p>检查电源系统状态。</p><ul><li>确认电源开关处于关闭状态</li><li>检查电源线路连接</li><li>检查接地线</li></ul>',
|
||||
'sort_order' => 2,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 3,
|
||||
'title' => '启动设备',
|
||||
'content' => '<p>按照正确顺序启动设备。</p><ol><li>打开主电源开关</li><li>等待系统自检完成</li><li>按下启动按钮</li><li>观察设备运行状态</li></ol>',
|
||||
'sort_order' => 3,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 4,
|
||||
'title' => '运行状态确认',
|
||||
'content' => '<p>确认设备正常运行。</p><ul><li>检查仪表显示</li><li>听设备运行声音</li><li>观察有无异常振动</li></ul>',
|
||||
'sort_order' => 4,
|
||||
'is_required' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($steps1 as $stepData) {
|
||||
$step = SopStep::create(array_merge($stepData, ['sop_template_id' => $template1->id]));
|
||||
|
||||
// 为第1步添加确认任务
|
||||
if ($stepData['step_number'] == 1) {
|
||||
SopInteractiveTask::create([
|
||||
'sop_step_id' => $step->id,
|
||||
'task_type' => 'confirm',
|
||||
'task_config' => [
|
||||
'title' => '安全检查确认',
|
||||
'message' => '我已完成所有安全检查项目,确认无安全隐患',
|
||||
],
|
||||
'validation_rules' => [],
|
||||
'timeout_seconds' => 300,
|
||||
'is_required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
// 为第3步添加拍照任务
|
||||
if ($stepData['step_number'] == 3) {
|
||||
SopInteractiveTask::create([
|
||||
'sop_step_id' => $step->id,
|
||||
'task_type' => 'photo',
|
||||
'task_config' => [
|
||||
'title' => '拍摄设备启动状态',
|
||||
'message' => '请拍摄设备仪表盘照片',
|
||||
'min_photos' => 1,
|
||||
'max_photos' => 3,
|
||||
],
|
||||
'validation_rules' => [],
|
||||
'timeout_seconds' => 180,
|
||||
'is_required' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 产品质检标准流程
|
||||
$this->command->info('创建产品质检标准流程...');
|
||||
$template2 = SopTemplate::create([
|
||||
'name' => '成品出库质检流程',
|
||||
'description' => '本流程规定了成品出库前的质量检验项目、检验方法和判定标准。',
|
||||
'category' => '质量管理',
|
||||
'tags' => ['质量控制', '标准作业', '检验'],
|
||||
'version' => '1.0.0',
|
||||
'status' => 'published',
|
||||
'applicable_departments' => ['质检部'],
|
||||
'applicable_positions' => ['质检员', '质检组长'],
|
||||
'published_at' => now()->subMonth(),
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
$steps2 = [
|
||||
[
|
||||
'step_number' => 1,
|
||||
'title' => '扫描产品条码',
|
||||
'content' => '<p>使用扫码枪扫描产品条码,获取产品信息。</p>',
|
||||
'sort_order' => 1,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 2,
|
||||
'title' => '外观检查',
|
||||
'content' => '<p>检查产品外观质量。</p><ul><li>表面无划痕</li><li>颜色均匀</li><li>无变形</li></ul>',
|
||||
'sort_order' => 2,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 3,
|
||||
'title' => '尺寸测量',
|
||||
'content' => '<p>使用量具测量关键尺寸。</p>',
|
||||
'sort_order' => 3,
|
||||
'is_required' => true,
|
||||
],
|
||||
[
|
||||
'step_number' => 4,
|
||||
'title' => '质检结果录入',
|
||||
'content' => '<p>在系统中录入质检结果。</p>',
|
||||
'sort_order' => 4,
|
||||
'is_required' => true,
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($steps2 as $stepData) {
|
||||
$step = SopStep::create(array_merge($stepData, ['sop_template_id' => $template2->id]));
|
||||
|
||||
// 为第1步添加扫码任务
|
||||
if ($stepData['step_number'] == 1) {
|
||||
SopInteractiveTask::create([
|
||||
'sop_step_id' => $step->id,
|
||||
'task_type' => 'scan',
|
||||
'task_config' => [
|
||||
'title' => '扫描产品条码',
|
||||
'scan_type' => 'barcode',
|
||||
],
|
||||
'validation_rules' => [
|
||||
'pattern' => '^[A-Z0-9]{10,20}$',
|
||||
],
|
||||
'timeout_seconds' => 60,
|
||||
'is_required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
// 为第2步添加选择任务
|
||||
if ($stepData['step_number'] == 2) {
|
||||
SopInteractiveTask::create([
|
||||
'sop_step_id' => $step->id,
|
||||
'task_type' => 'select',
|
||||
'task_config' => [
|
||||
'title' => '外观检查结果',
|
||||
'options' => ['合格', '不合格'],
|
||||
],
|
||||
'validation_rules' => [],
|
||||
'timeout_seconds' => 120,
|
||||
'is_required' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
// 为第3步添加输入任务
|
||||
if ($stepData['step_number'] == 3) {
|
||||
SopInteractiveTask::create([
|
||||
'sop_step_id' => $step->id,
|
||||
'task_type' => 'input',
|
||||
'task_config' => [
|
||||
'title' => '输入测量数据',
|
||||
'fields' => [
|
||||
['name' => 'length', 'label' => '长度(mm)', 'type' => 'number'],
|
||||
['name' => 'width', 'label' => '宽度(mm)', 'type' => 'number'],
|
||||
['name' => 'height', 'label' => '高度(mm)', 'type' => 'number'],
|
||||
],
|
||||
],
|
||||
'validation_rules' => [
|
||||
'length' => ['required', 'numeric', 'min:0'],
|
||||
'width' => ['required', 'numeric', 'min:0'],
|
||||
'height' => ['required', 'numeric', 'min:0'],
|
||||
],
|
||||
'timeout_seconds' => 300,
|
||||
'is_required' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 创建一个草稿模板
|
||||
$this->command->info('创建草稿模板...');
|
||||
SopTemplate::create([
|
||||
'name' => '设备维护保养流程(草稿)',
|
||||
'description' => '设备日常维护保养操作流程,包括清洁、润滑、紧固等内容。',
|
||||
'category' => '设备维护',
|
||||
'tags' => ['维护', '保养'],
|
||||
'version' => '0.1.0',
|
||||
'status' => 'draft',
|
||||
'applicable_departments' => ['设备部'],
|
||||
'applicable_positions' => ['维修工', '技术员'],
|
||||
'published_at' => null,
|
||||
'created_by' => $user->id,
|
||||
]);
|
||||
|
||||
$this->command->info('SOP模板数据创建完成!');
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的SOP模板摘要 ===');
|
||||
$this->command->info('总模板数量: ' . SopTemplate::count());
|
||||
$this->command->info(' - 已发布: ' . SopTemplate::where('status', 'published')->count());
|
||||
$this->command->info(' - 草稿: ' . SopTemplate::where('status', 'draft')->count());
|
||||
$this->command->info(' - 已归档: ' . SopTemplate::where('status', 'archived')->count());
|
||||
$this->command->info('总步骤数量: ' . SopStep::count());
|
||||
$this->command->info('总交互任务数量: ' . SopInteractiveTask::count());
|
||||
}
|
||||
}
|
||||
206
database/seeders/SystemSettingSeeder.php
Normal file
206
database/seeders/SystemSettingSeeder.php
Normal file
@@ -0,0 +1,206 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\SystemSetting;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class SystemSettingSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$this->command->info('开始创建系统设置...');
|
||||
|
||||
// 1. 嵌入模型配置
|
||||
$this->command->info('创建嵌入模型配置...');
|
||||
SystemSetting::create([
|
||||
'key' => 'embedding.model_name',
|
||||
'value' => [
|
||||
'model_name' => 'text-embedding-3-small',
|
||||
],
|
||||
'group' => 'embedding',
|
||||
'description' => '嵌入模型名称',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'embedding.api_key',
|
||||
'value' => [
|
||||
'api_key' => '',
|
||||
],
|
||||
'group' => 'embedding',
|
||||
'description' => 'OpenAI API 密钥(敏感信息)',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'embedding.endpoint_url',
|
||||
'value' => [
|
||||
'endpoint_url' => 'https://api.openai.com/v1/embeddings',
|
||||
],
|
||||
'group' => 'embedding',
|
||||
'description' => '嵌入模型 API 端点 URL',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'embedding.dimensions',
|
||||
'value' => [
|
||||
'dimensions' => 1536,
|
||||
],
|
||||
'group' => 'embedding',
|
||||
'description' => '嵌入向量维度',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'embedding.batch_size',
|
||||
'value' => [
|
||||
'batch_size' => 100,
|
||||
],
|
||||
'group' => 'embedding',
|
||||
'description' => '批量处理大小',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
// 2. 分块参数配置
|
||||
$this->command->info('创建分块参数配置...');
|
||||
SystemSetting::create([
|
||||
'key' => 'chunking.chunk_size',
|
||||
'value' => [
|
||||
'chunk_size' => 1000,
|
||||
],
|
||||
'group' => 'chunking',
|
||||
'description' => '文档分块大小(字符数)',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'chunking.chunk_overlap',
|
||||
'value' => [
|
||||
'chunk_overlap' => 200,
|
||||
],
|
||||
'group' => 'chunking',
|
||||
'description' => '分块重叠大小(字符数)',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'chunking.separator',
|
||||
'value' => [
|
||||
'separator' => "\n\n",
|
||||
],
|
||||
'group' => 'chunking',
|
||||
'description' => '分块分隔符',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'chunking.min_chunk_size',
|
||||
'value' => [
|
||||
'min_chunk_size' => 100,
|
||||
],
|
||||
'group' => 'chunking',
|
||||
'description' => '最小分块大小(字符数)',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
// 3. 系统全局配置
|
||||
$this->command->info('创建系统全局配置...');
|
||||
SystemSetting::create([
|
||||
'key' => 'system.name',
|
||||
'value' => [
|
||||
'name' => '知识库管理系统',
|
||||
],
|
||||
'group' => 'system',
|
||||
'description' => '系统名称',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'system.timeout',
|
||||
'value' => [
|
||||
'timeout' => 60,
|
||||
],
|
||||
'group' => 'system',
|
||||
'description' => 'API 请求超时时间(秒)',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'system.max_retries',
|
||||
'value' => [
|
||||
'max_retries' => 3,
|
||||
],
|
||||
'group' => 'system',
|
||||
'description' => 'API 请求最大重试次数',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'system.max_upload_size',
|
||||
'value' => [
|
||||
'max_upload_size' => 10485760, // 10MB
|
||||
],
|
||||
'group' => 'system',
|
||||
'description' => '最大文件上传大小(字节)',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'system.allowed_file_types',
|
||||
'value' => [
|
||||
'allowed_file_types' => ['docx', 'pdf', 'txt', 'md'],
|
||||
],
|
||||
'group' => 'system',
|
||||
'description' => '允许上传的文件类型',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
// 4. 搜索配置
|
||||
$this->command->info('创建搜索配置...');
|
||||
SystemSetting::create([
|
||||
'key' => 'search.top_k',
|
||||
'value' => [
|
||||
'top_k' => 5,
|
||||
],
|
||||
'group' => 'search',
|
||||
'description' => '搜索返回的最大结果数',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'search.similarity_threshold',
|
||||
'value' => [
|
||||
'similarity_threshold' => 0.7,
|
||||
],
|
||||
'group' => 'search',
|
||||
'description' => '相似度阈值(0-1)',
|
||||
'is_public' => true,
|
||||
]);
|
||||
|
||||
SystemSetting::create([
|
||||
'key' => 'search.enable_rerank',
|
||||
'value' => [
|
||||
'enable_rerank' => false,
|
||||
],
|
||||
'group' => 'search',
|
||||
'description' => '是否启用重排序',
|
||||
'is_public' => false,
|
||||
]);
|
||||
|
||||
$this->command->info('系统设置创建完成!');
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的配置摘要 ===');
|
||||
$this->command->info('总配置数量: ' . SystemSetting::count());
|
||||
$this->command->info(' - 嵌入模型配置: ' . SystemSetting::where('group', 'embedding')->count());
|
||||
$this->command->info(' - 分块参数配置: ' . SystemSetting::where('group', 'chunking')->count());
|
||||
$this->command->info(' - 系统全局配置: ' . SystemSetting::where('group', 'system')->count());
|
||||
$this->command->info(' - 搜索配置: ' . SystemSetting::where('group', 'search')->count());
|
||||
$this->command->info(' - 公开配置: ' . SystemSetting::where('is_public', true)->count());
|
||||
$this->command->info(' - 私有配置: ' . SystemSetting::where('is_public', false)->count());
|
||||
}
|
||||
}
|
||||
183
database/seeders/TerminalSeeder.php
Normal file
183
database/seeders/TerminalSeeder.php
Normal file
@@ -0,0 +1,183 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
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('开始创建终端数据...');
|
||||
|
||||
// 1. 创建生产线终端
|
||||
$this->command->info('创建生产线终端...');
|
||||
$productionTerminals = [
|
||||
[
|
||||
'name' => '生产线A-工位1',
|
||||
'code' => 'PROD-A001',
|
||||
'ip_address' => '192.168.1.101',
|
||||
'diagram_url' => 'https://example.com/diagrams/prod-a-1.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 80,
|
||||
],
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '生产线A-工位2',
|
||||
'code' => 'PROD-A002',
|
||||
'ip_address' => '192.168.1.102',
|
||||
'diagram_url' => 'https://example.com/diagrams/prod-a-2.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 80,
|
||||
],
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '生产线B-工位1',
|
||||
'code' => 'PROD-B001',
|
||||
'ip_address' => '192.168.1.201',
|
||||
'diagram_url' => 'https://example.com/diagrams/prod-b-1.png',
|
||||
'display_config' => [
|
||||
'resolution' => '2560x1440',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 75,
|
||||
],
|
||||
'is_online' => false,
|
||||
'last_online_at' => now()->subHours(2),
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($productionTerminals as $terminalData) {
|
||||
$terminal = Terminal::create($terminalData);
|
||||
|
||||
// 为每个终端创建默认提示词
|
||||
TerminalPrompt::create([
|
||||
'terminal_id' => $terminal->id,
|
||||
'prompt_template' => "你是{station}的AI助手。当前时间是{time}。请根据用户{user}的问题,提供准确的技术支持和操作指导。",
|
||||
'variables' => [
|
||||
'station' => $terminalData['name'],
|
||||
'time' => '{current_time}',
|
||||
'user' => '{current_user}',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// 2. 创建质检站终端
|
||||
$this->command->info('创建质检站终端...');
|
||||
$qcTerminals = [
|
||||
[
|
||||
'name' => '质检站-入库检-1',
|
||||
'code' => 'QC-IN001',
|
||||
'ip_address' => '192.168.2.101',
|
||||
'diagram_url' => 'https://example.com/diagrams/qc-in-1.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 85,
|
||||
],
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '质检站-出库检-1',
|
||||
'code' => 'QC-OUT001',
|
||||
'ip_address' => '192.168.2.102',
|
||||
'diagram_url' => 'https://example.com/diagrams/qc-out-1.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 85,
|
||||
],
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($qcTerminals as $terminalData) {
|
||||
$terminal = Terminal::create($terminalData);
|
||||
|
||||
TerminalPrompt::create([
|
||||
'terminal_id' => $terminal->id,
|
||||
'prompt_template' => "你是{station}的质检AI助手。请协助操作员{user}完成质检工作,提供质检标准、操作流程和异常处理建议。",
|
||||
'variables' => [
|
||||
'station' => $terminalData['name'],
|
||||
'user' => '{current_user}',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
// 3. 创建包装站终端
|
||||
$this->command->info('创建包装站终端...');
|
||||
$packagingTerminals = [
|
||||
[
|
||||
'name' => '包装站-工位1',
|
||||
'code' => 'PKG-001',
|
||||
'ip_address' => '192.168.3.101',
|
||||
'diagram_url' => 'https://example.com/diagrams/pkg-1.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 80,
|
||||
],
|
||||
'is_online' => true,
|
||||
'last_online_at' => now(),
|
||||
],
|
||||
[
|
||||
'name' => '包装站-工位2',
|
||||
'code' => 'PKG-002',
|
||||
'ip_address' => '192.168.3.102',
|
||||
'diagram_url' => 'https://example.com/diagrams/pkg-2.png',
|
||||
'display_config' => [
|
||||
'resolution' => '1920x1080',
|
||||
'refresh_rate' => 60,
|
||||
'orientation' => 'landscape',
|
||||
'brightness' => 80,
|
||||
],
|
||||
'is_online' => false,
|
||||
'last_online_at' => now()->subDays(1),
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($packagingTerminals as $terminalData) {
|
||||
$terminal = Terminal::create($terminalData);
|
||||
|
||||
TerminalPrompt::create([
|
||||
'terminal_id' => $terminal->id,
|
||||
'prompt_template' => "你是{station}的包装AI助手。请协助操作员{user}完成包装作业,提供包装规范、材料使用和质量要求指导。",
|
||||
'variables' => [
|
||||
'station' => $terminalData['name'],
|
||||
'user' => '{current_user}',
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
$this->command->info('终端数据创建完成!');
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 生成的终端摘要 ===');
|
||||
$this->command->info('总终端数量: ' . Terminal::count());
|
||||
$this->command->info(' - 生产线终端: ' . Terminal::where('code', 'like', 'PROD-%')->count());
|
||||
$this->command->info(' - 质检站终端: ' . Terminal::where('code', 'like', 'QC-%')->count());
|
||||
$this->command->info(' - 包装站终端: ' . Terminal::where('code', 'like', 'PKG-%')->count());
|
||||
$this->command->info(' - 在线终端: ' . Terminal::where('is_online', true)->count());
|
||||
$this->command->info(' - 离线终端: ' . Terminal::where('is_online', false)->count());
|
||||
$this->command->info(' - 配置提示词的终端: ' . TerminalPrompt::count());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user