forceDelete(); StepRelation::withTrashed()->forceDelete(); StepStatus::withTrashed()->forceDelete(); ProcessStep::withTrashed()->forceDelete(); Process::withTrashed()->forceDelete(); $processes = [ 'production' => Process::create([ 'id' => Snowflake::generate(), 'process_code' => 'L1SC', 'process_name' => '生产工序', 'description' => '生产主流程示例数据', 'sort' => 0, 'status' => 1, 'step_count' => 3, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'addon' => Process::create([ 'id' => Snowflake::generate(), 'process_code' => 'L1JZ', 'process_name' => '加装工序', 'description' => '加装分支示例数据', 'sort' => 10, 'status' => 1, 'step_count' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'repair' => Process::create([ 'id' => Snowflake::generate(), 'process_code' => 'L1WX', 'process_name' => '异常工序', 'description' => '维修/异常处理示例数据', 'sort' => 20, 'status' => 1, 'step_count' => 3, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), ]; $steps = [ 'panel' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['production']->id, 'step_code' => 'PB001', 'step_name' => '拼板', 'description' => '生产起始步骤', 'sort' => 0, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'none', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 1, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'assemble' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['production']->id, 'step_code' => 'ZZ001', 'step_name' => '组装', 'description' => '生产主流程第二步', 'sort' => 10, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'all', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 1, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'test' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['production']->id, 'step_code' => 'CS001', 'step_name' => '测试', 'description' => '生产主流程第三步', 'sort' => 20, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'any', 'prerequisite_require_final' => 0, 'allow_repeat_scan' => 1, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'addon' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['addon']->id, 'step_code' => 'JZ001', 'step_name' => '加装', 'description' => '加装支线步骤', 'sort' => 0, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'all', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 0, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'repair' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['repair']->id, 'step_code' => 'WX001', 'step_name' => '维修', 'description' => '异常维修步骤', 'sort' => 0, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'all', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 1, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'rework' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['repair']->id, 'step_code' => 'CP001', 'step_name' => '重配', 'description' => '异常重配步骤', 'sort' => 10, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'all', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 0, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'cancel' => ProcessStep::create([ 'id' => Snowflake::generate(), 'process_id' => $processes['repair']->id, 'step_code' => 'TD001', 'step_name' => '退单', 'description' => '异常退单步骤', 'sort' => 20, 'status' => 1, 'prerequisite_steps' => [], 'prerequisite_mode' => 'all', 'prerequisite_require_final' => 1, 'allow_repeat_scan' => 0, 'repeat_scan_statuses' => [], 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), ]; $statuses = [ 'panel_processing' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['panel']->id, 'status_code' => 'PB_PROCESSING', 'status_name' => '拼板中', 'is_initial' => 1, 'is_final' => 0, 'description' => '拼板初始状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'panel_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['panel']->id, 'status_code' => 'PB_COMPLETED', 'status_name' => '拼板完成', 'is_initial' => 0, 'is_final' => 1, 'description' => '拼板完成状态', 'sort' => 10, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'panel_exception' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['panel']->id, 'status_code' => 'PB_EXCEPTION', 'status_name' => '拼板异常', 'is_initial' => 0, 'is_final' => 1, 'description' => '拼板异常状态', 'sort' => 20, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'assemble_processing' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['assemble']->id, 'status_code' => 'ZZ_PROCESSING', 'status_name' => '组装中', 'is_initial' => 1, 'is_final' => 0, 'description' => '组装初始状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'assemble_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['assemble']->id, 'status_code' => 'ZZ_COMPLETED', 'status_name' => '组装完成', 'is_initial' => 0, 'is_final' => 1, 'description' => '组装完成状态', 'sort' => 10, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'assemble_exception' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['assemble']->id, 'status_code' => 'ZZ_EXCEPTION', 'status_name' => '组装异常', 'is_initial' => 0, 'is_final' => 1, 'description' => '组装异常状态', 'sort' => 20, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'test_processing' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['test']->id, 'status_code' => 'CS_PROCESSING', 'status_name' => '测试中', 'is_initial' => 1, 'is_final' => 0, 'description' => '测试初始状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'test_passed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['test']->id, 'status_code' => 'CS_PASSED', 'status_name' => '测试通过', 'is_initial' => 0, 'is_final' => 1, 'description' => '测试通过状态', 'sort' => 10, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'test_failed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['test']->id, 'status_code' => 'CS_FAILED', 'status_name' => '测试不通过', 'is_initial' => 0, 'is_final' => 1, 'description' => '测试失败状态', 'sort' => 20, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'addon_processing' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['addon']->id, 'status_code' => 'JZ_PROCESSING', 'status_name' => '加装中', 'is_initial' => 1, 'is_final' => 0, 'description' => '加装初始状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'addon_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['addon']->id, 'status_code' => 'JZ_COMPLETED', 'status_name' => '加装完成', 'is_initial' => 0, 'is_final' => 1, 'description' => '加装完成状态', 'sort' => 10, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'repair_processing' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['repair']->id, 'status_code' => 'WX_PROCESSING', 'status_name' => '维修中', 'is_initial' => 1, 'is_final' => 0, 'description' => '维修初始状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'repair_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['repair']->id, 'status_code' => 'WX_COMPLETED', 'status_name' => '维修完成', 'is_initial' => 0, 'is_final' => 1, 'description' => '维修完成状态', 'sort' => 10, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'rework_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['rework']->id, 'status_code' => 'CP_COMPLETED', 'status_name' => '重配完成', 'is_initial' => 1, 'is_final' => 1, 'description' => '重配完成状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), 'cancel_completed' => StepStatus::create([ 'id' => Snowflake::generate(), 'step_id' => $steps['cancel']->id, 'status_code' => 'TD_COMPLETED', 'status_name' => '退单完成', 'is_initial' => 1, 'is_final' => 1, 'description' => '退单完成状态', 'sort' => 0, 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]), ]; $steps['assemble']->update([ 'prerequisite_steps' => [$steps['panel']->id], 'repeat_scan_statuses' => [$statuses['panel_processing']->id], ]); $steps['test']->update([ 'prerequisite_steps' => [$steps['assemble']->id, $steps['addon']->id], 'repeat_scan_statuses' => [$statuses['assemble_processing']->id], ]); $steps['panel']->update([ 'repeat_scan_statuses' => [$statuses['rework_completed']->id, $statuses['cancel_completed']->id], ]); $relations = [ [ 'from_step_id' => $steps['panel']->id, 'to_step_id' => $steps['assemble']->id, 'relation_type' => 'normal', 'flow_condition' => [], 'priority' => 0, 'description' => '拼板完成后进入组装', 'sort' => 0, ], [ 'from_step_id' => $steps['assemble']->id, 'to_step_id' => $steps['test']->id, 'relation_type' => 'normal', 'flow_condition' => [], 'priority' => 0, 'description' => '组装完成后进入测试', 'sort' => 10, ], [ 'from_step_id' => $steps['addon']->id, 'to_step_id' => $steps['test']->id, 'relation_type' => 'normal', 'flow_condition' => [], 'priority' => 0, 'description' => '加装完成后可进入测试', 'sort' => 20, ], [ 'from_step_id' => $steps['test']->id, 'to_step_id' => $steps['assemble']->id, 'relation_type' => 'exception', 'flow_condition' => ['reason' => 'assembly_rework'], 'priority' => 0, 'description' => '测试失败后回流组装', 'sort' => 30, ], [ 'from_step_id' => $steps['assemble']->id, 'to_step_id' => $steps['repair']->id, 'relation_type' => 'exception', 'flow_condition' => ['reason' => 'repair_required'], 'priority' => 0, 'description' => '组装异常进入维修', 'sort' => 40, ], [ 'from_step_id' => $steps['test']->id, 'to_step_id' => $steps['repair']->id, 'relation_type' => 'exception', 'flow_condition' => ['reason' => 'repair_required'], 'priority' => 0, 'description' => '测试异常进入维修', 'sort' => 50, ], [ 'from_step_id' => $steps['panel']->id, 'to_step_id' => $steps['rework']->id, 'relation_type' => 'exception', 'flow_condition' => ['reason' => 'rework_required'], 'priority' => 0, 'description' => '拼板异常进入重配', 'sort' => 60, ], [ 'from_step_id' => $steps['assemble']->id, 'to_step_id' => $steps['cancel']->id, 'relation_type' => 'exception', 'flow_condition' => ['reason' => 'cancel_required'], 'priority' => 0, 'description' => '组装异常进入退单', 'sort' => 70, ], ]; foreach ($relations as $relation) { StepRelation::create([ 'id' => Snowflake::generate(), 'from_step_id' => $relation['from_step_id'], 'to_step_id' => $relation['to_step_id'], 'relation_type' => $relation['relation_type'], 'flow_condition' => $relation['flow_condition'], 'priority' => $relation['priority'], 'description' => $relation['description'], 'sort' => $relation['sort'], 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]); } $transitions = [ [ 'step_id' => $steps['panel']->id, 'from_status_id' => $statuses['panel_processing']->id, 'to_status_id' => $statuses['panel_completed']->id, 'trigger_event' => 'next_step_scan', 'event_config' => null, 'auto_trigger' => 1, 'priority' => 0, 'transition_type' => 'primary', 'side_effect_type' => null, 'side_effect_config' => null, 'description' => '拼板完成后推进下一步', 'sort' => 0, ], [ 'step_id' => $steps['assemble']->id, 'from_status_id' => $statuses['assemble_processing']->id, 'to_status_id' => $statuses['assemble_completed']->id, 'trigger_event' => 'next_step_scan', 'event_config' => null, 'auto_trigger' => 1, 'priority' => 0, 'transition_type' => 'primary', 'side_effect_type' => null, 'side_effect_config' => null, 'description' => '组装完成后推进下一步', 'sort' => 10, ], [ 'step_id' => $steps['assemble']->id, 'from_status_id' => $statuses['assemble_processing']->id, 'to_status_id' => $statuses['assemble_exception']->id, 'trigger_event' => 'exception_trigger', 'event_config' => ['source' => 'manual'], 'auto_trigger' => 1, 'priority' => 5, 'transition_type' => 'primary', 'side_effect_type' => null, 'side_effect_config' => null, 'description' => '组装异常时转异常态', 'sort' => 20, ], [ 'step_id' => $steps['test']->id, 'from_status_id' => $statuses['test_processing']->id, 'to_status_id' => $statuses['test_passed']->id, 'trigger_event' => 'scan_trigger', 'event_config' => null, 'auto_trigger' => 1, 'priority' => 0, 'transition_type' => 'primary', 'side_effect_type' => null, 'side_effect_config' => null, 'description' => '测试通过', 'sort' => 30, ], [ 'step_id' => $steps['test']->id, 'from_status_id' => $statuses['test_processing']->id, 'to_status_id' => $statuses['test_failed']->id, 'trigger_event' => 'exception_trigger', 'event_config' => ['source' => 'manual'], 'auto_trigger' => 1, 'priority' => 5, 'transition_type' => 'primary', 'side_effect_type' => null, 'side_effect_config' => null, 'description' => '测试失败', 'sort' => 40, ], ]; foreach ($transitions as $transition) { StatusTransition::create([ 'id' => Snowflake::generate(), 'step_id' => $transition['step_id'], 'from_status_id' => $transition['from_status_id'], 'to_status_id' => $transition['to_status_id'], 'trigger_event' => $transition['trigger_event'], 'event_config' => $transition['event_config'], 'auto_trigger' => $transition['auto_trigger'], 'priority' => $transition['priority'], 'transition_type' => $transition['transition_type'], 'side_effect_type' => $transition['side_effect_type'], 'side_effect_config' => $transition['side_effect_config'], 'description' => $transition['description'], 'sort' => $transition['sort'], 'status' => 1, 'created_by' => $adminId, 'updated_by' => $adminId, 'created_at' => $now, 'updated_at' => $now, ]); } } }