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' => '
检查设备周围环境,确保无障碍物和安全隐患。
检查电源系统状态。
按照正确顺序启动设备。
确认设备正常运行。
使用扫码枪扫描产品条码,获取产品信息。
', 'sort_order' => 1, 'is_required' => true, ], [ 'step_number' => 2, 'title' => '外观检查', 'content' => '检查产品外观质量。
使用量具测量关键尺寸。
', 'sort_order' => 3, 'is_required' => true, ], [ 'step_number' => 4, 'title' => '质检结果录入', 'content' => '在系统中录入质检结果。
', '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()); } }