feat: add article and production modules

This commit is contained in:
2026-08-31 13:16:46 +08:00
parent ac3da246b2
commit 5c586a1a95
334 changed files with 34419 additions and 1 deletions
@@ -0,0 +1,144 @@
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_process')) {
$schema->create('produce_process', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('process_code', 50)->comment('工序编码');
$table->string('process_name', 100)->comment('工序名称');
$table->text('description')->nullable()->comment('工序描述');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:1启用,0禁用');
$table->integer('step_count')->default(0)->comment('步骤数');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['process_code', 'deleted_at'], 'uk_process_code');
$table->index('status', 'idx_status');
$table->index('sort', 'idx_sort');
});
}
if (!$schema->hasTable('produce_process_step')) {
$schema->create('produce_process_step', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('process_id')->comment('工序ID');
$table->string('step_code', 50)->comment('步骤编码');
$table->string('step_name', 100)->comment('步骤名称');
$table->text('description')->nullable()->comment('步骤描述');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:1启用,0禁用');
$table->json('prerequisite_steps')->nullable()->comment('前置必要步骤ID数组');
$table->string('prerequisite_mode', 20)->default('all')->comment('前置步骤验证模式:all=全部完成,any=任意完成,none=无需验证');
$table->tinyInteger('prerequisite_require_final')->default(1)->comment('前置步骤是否要求终态:0否1是');
$table->tinyInteger('allow_repeat_scan')->default(0)->comment('是否允许重复扫码:0否1是');
$table->json('repeat_scan_statuses')->nullable()->comment('允许重复扫码的状态数组');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['step_code', 'process_id', 'deleted_at'], 'uk_step_code');
$table->index('process_id', 'idx_process_id');
$table->index('status', 'idx_status');
$table->index('sort', 'idx_sort');
});
}
if (!$schema->hasTable('produce_step_status')) {
$schema->create('produce_step_status', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('step_id')->comment('所属步骤ID');
$table->string('status_code', 50)->comment('状态编码');
$table->string('status_name', 100)->comment('状态名称');
$table->tinyInteger('is_initial')->default(0)->comment('是否初始状态:0否1是');
$table->tinyInteger('is_final')->default(0)->comment('是否终态:0否1是');
$table->text('description')->nullable()->comment('状态描述');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:0禁用1启用');
$table->bigInteger('created_by')->nullable()->comment('创建人');
$table->bigInteger('updated_by')->nullable()->comment('更新人');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['step_id', 'status_code', 'deleted_at'], 'uk_step_status_code');
$table->index('step_id', 'idx_step_id');
$table->index('status', 'idx_status');
$table->index('sort', 'idx_sort');
$table->index('deleted_at', 'idx_deleted_at');
});
}
if (!$schema->hasTable('produce_step_relation')) {
$schema->create('produce_step_relation', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('from_step_id')->comment('源步骤ID');
$table->bigInteger('to_step_id')->comment('目标步骤ID');
$table->string('relation_type', 20)->default('normal')->comment('关系类型:normal-正常流转,exception-异常流转');
$table->text('flow_condition')->nullable()->comment('流转条件(JSON格式)');
$table->integer('priority')->default(0)->comment('优先级(数字越小优先级越高)');
$table->text('description')->nullable()->comment('描述');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:0-禁用,1-启用');
$table->bigInteger('created_by')->nullable()->comment('创建人');
$table->bigInteger('updated_by')->nullable()->comment('更新人');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['from_step_id', 'to_step_id', 'relation_type', 'deleted_at'], 'uk_step_relation');
$table->index('from_step_id', 'idx_from_step_id');
$table->index('to_step_id', 'idx_to_step_id');
$table->index('relation_type', 'idx_relation_type');
$table->index('status', 'idx_status');
$table->index('priority', 'idx_priority');
$table->index('deleted_at', 'idx_deleted_at');
});
}
if (!$schema->hasTable('produce_status_transition')) {
$schema->create('produce_status_transition', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('step_id')->comment('所属步骤ID');
$table->bigInteger('from_status_id')->comment('源状态ID');
$table->bigInteger('to_status_id')->comment('目标状态ID');
$table->string('trigger_event', 100)->comment('触发事件');
$table->text('event_config')->nullable()->comment('事件配置(JSON)');
$table->tinyInteger('auto_trigger')->default(0)->comment('是否自动触发:0否1是');
$table->integer('priority')->default(0)->comment('优先级(数字越大优先级越高)');
$table->string('transition_type', 20)->default('primary')->comment('转换类型:primary-主转换,side_effect-副作用');
$table->string('side_effect_type', 50)->nullable()->comment('副作用类型');
$table->text('side_effect_config')->nullable()->comment('副作用配置(JSON)');
$table->text('description')->nullable()->comment('描述');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('status')->default(1)->comment('状态:0禁用1启用');
$table->bigInteger('created_by')->nullable()->comment('创建人');
$table->bigInteger('updated_by')->nullable()->comment('更新人');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('step_id', 'idx_step_id');
$table->index('from_status_id', 'idx_from_status_id');
$table->index('to_status_id', 'idx_to_status_id');
$table->index('trigger_event', 'idx_trigger_event');
$table->index('status', 'idx_status');
$table->index('deleted_at', 'idx_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_status_transition');
$schema->dropIfExists('produce_step_relation');
$schema->dropIfExists('produce_step_status');
$schema->dropIfExists('produce_process_step');
$schema->dropIfExists('produce_process');
}
};
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_transition_log')) {
$schema->create('produce_transition_log', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('work_order_id')->nullable()->comment('工单ID');
$table->string('work_order_no', 100)->nullable()->comment('工单编号');
$table->bigInteger('step_id')->comment('所属步骤ID');
$table->bigInteger('transition_id')->nullable()->comment('转换规则ID');
$table->bigInteger('from_status_id')->comment('源状态ID');
$table->bigInteger('to_status_id')->comment('目标状态ID');
$table->string('trigger_event', 100)->comment('触发事件');
$table->text('trigger_data')->nullable()->comment('触发数据(JSON)');
$table->string('trigger_user', 100)->nullable()->comment('触发用户');
$table->string('trigger_ip', 50)->nullable()->comment('触发IP');
$table->tinyInteger('is_auto')->default(0)->comment('是否自动触发:0否1是');
$table->tinyInteger('is_success')->default(1)->comment('是否成功:0失败1成功');
$table->text('error_message')->nullable()->comment('错误信息');
$table->integer('duration')->default(0)->comment('执行时长(毫秒)');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('work_order_id', 'idx_work_order_id');
$table->index('work_order_no', 'idx_work_order_no');
$table->index('step_id', 'idx_step_id');
$table->index('transition_id', 'idx_transition_id');
$table->index('from_status_id', 'idx_from_status_id');
$table->index('to_status_id', 'idx_to_status_id');
$table->index('trigger_event', 'idx_trigger_event');
$table->index('is_success', 'idx_is_success');
$table->index('created_at', 'idx_created_at');
$table->index('deleted_at', 'idx_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_transition_log');
}
};
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_config')) {
$schema->create('produce_config', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('group_code', 64)->comment('配置组代码');
$table->string('code', 64)->comment('配置代码');
$table->string('name', 255)->comment('配置名称');
$table->text('content')->nullable()->comment('配置内容');
$table->integer('sort')->default(0)->comment('排序');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['group_code', 'code', 'deleted_at'], 'uk_group_code_code');
$table->index('group_code', 'idx_group_code');
$table->index('sort', 'idx_sort');
$table->index('deleted_at', 'idx_deleted_at');
});
}
if (!$schema->hasTable('produce_specific_rule')) {
$schema->create('produce_specific_rule', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('rule_name', 255)->comment('规则名称');
$table->text('rule_pattern')->comment('规则表达式');
$table->tinyInteger('rule_type')->default(1)->comment('规则类型');
$table->tinyInteger('is_enabled')->default(1)->comment('是否启用:0否1是');
$table->json('step_ids')->nullable()->comment('关联步骤ID数组');
$table->integer('sort')->default(0)->comment('排序');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('rule_name', 'idx_rule_name');
$table->index('rule_type', 'idx_rule_type');
$table->index('is_enabled', 'idx_is_enabled');
$table->index('sort', 'idx_sort');
$table->index('deleted_at', 'idx_deleted_at');
});
}
if (!$schema->hasTable('produce_scan_data')) {
$schema->create('produce_scan_data', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('order_no', 100)->comment('订单号');
$table->string('user_code', 50)->comment('用户编码');
$table->string('operator', 100)->nullable()->comment('操作人员');
$table->bigInteger('operator_id')->nullable()->comment('操作人员ID');
$table->bigInteger('process_id')->comment('工序ID');
$table->bigInteger('step_id')->comment('步骤ID');
$table->bigInteger('status_id')->nullable()->comment('步骤状态ID');
$table->tinyInteger('scan_result')->default(1)->comment('扫码结果:0失败1成功');
$table->bigInteger('scan_time')->nullable()->comment('扫码时间');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('order_no', 'idx_order_no');
$table->index('user_code', 'idx_user_code');
$table->index('process_id', 'idx_process_id');
$table->index('step_id', 'idx_step_id');
$table->index('status_id', 'idx_status_id');
$table->index('scan_result', 'idx_scan_result');
$table->index('scan_time', 'idx_scan_time');
$table->index('deleted_at', 'idx_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_scan_data');
$schema->dropIfExists('produce_specific_rule');
$schema->dropIfExists('produce_config');
}
};
@@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_product_record')) {
$schema->create('produce_product_record', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('process_order_no', 100)->comment('加工单号');
$table->string('product_code', 100)->comment('商品编码');
$table->integer('quantity')->default(1)->comment('数量');
$table->bigInteger('process_id')->nullable()->comment('工序ID');
$table->bigInteger('step_id')->nullable()->comment('步骤ID');
$table->bigInteger('status_id')->nullable()->comment('状态ID');
$table->string('user_code', 50)->nullable()->comment('用户编码');
$table->string('operator', 100)->nullable()->comment('操作人员');
$table->bigInteger('operator_id')->nullable()->comment('操作人员ID');
$table->tinyInteger('scan_result')->default(1)->comment('扫码结果:0失败1成功');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('process_order_no', 'idx_process_order_no');
$table->index('product_code', 'idx_product_code');
$table->index('process_id', 'idx_process_id');
$table->index('step_id', 'idx_step_id');
$table->index('status_id', 'idx_status_id');
$table->index('user_code', 'idx_user_code');
$table->index('operator_id', 'idx_operator_id');
$table->index('scan_result', 'idx_scan_result');
$table->index('created_at', 'idx_created_at');
$table->index('deleted_at', 'idx_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_product_record');
}
};
@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class
{
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_specific_rule')) {
return;
}
$hasApplyMode = $schema->hasColumn('produce_specific_rule', 'apply_mode');
$hasMatchField = $schema->hasColumn('produce_specific_rule', 'match_field');
if ($hasApplyMode && $hasMatchField) {
return;
}
$schema->table('produce_specific_rule', function (Blueprint $table) use ($hasApplyMode, $hasMatchField) {
if (!$hasApplyMode) {
$table->string('apply_mode', 20)->default('order')->after('rule_type')->comment('适用模式:order订单 machine整机 both全部');
}
if (!$hasMatchField) {
$table->string('match_field', 30)->default('order_no')->after('apply_mode')->comment('匹配字段:order_no process_order_no product_code user_code');
}
});
}
public function down(Builder $schema): void
{
if (!$schema->hasTable('produce_specific_rule')) {
return;
}
$hasApplyMode = $schema->hasColumn('produce_specific_rule', 'apply_mode');
$hasMatchField = $schema->hasColumn('produce_specific_rule', 'match_field');
if (!$hasApplyMode && !$hasMatchField) {
return;
}
$schema->table('produce_specific_rule', function (Blueprint $table) use ($hasApplyMode, $hasMatchField) {
if ($hasMatchField) {
$table->dropColumn('match_field');
}
if ($hasApplyMode) {
$table->dropColumn('apply_mode');
}
});
}
};
@@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use core\uuid\Snowflake;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
$createdExceptionSettingTable = false;
if (!$schema->hasTable('produce_exception_setting')) {
$createdExceptionSettingTable = true;
$schema->create('produce_exception_setting', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('parent_id')->nullable()->comment('父级ID');
$table->string('setting_type', 20)->comment('设置类型:type处理类型、reason异常原因、issue具体问题');
$table->string('code', 64)->comment('设置编码');
$table->string('name', 100)->comment('设置名称');
$table->integer('sort')->default(0)->comment('排序,值越小越靠前');
$table->tinyInteger('is_enabled')->default(1)->comment('是否启用:0否1是');
$table->text('remark')->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['parent_id', 'code', 'deleted_at'], 'uk_exception_setting_parent_code');
$table->index('setting_type', 'idx_exception_setting_type');
$table->index('parent_id', 'idx_exception_setting_parent');
$table->index(['is_enabled', 'sort'], 'idx_exception_setting_enabled_sort');
$table->index('deleted_at', 'idx_exception_setting_deleted');
});
}
if ($createdExceptionSettingTable) {
$this->seedExceptionSettings($schema);
}
if (!$schema->hasTable('produce_exception_record')) {
$schema->create('produce_exception_record', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('order_no', 100)->comment('单号或条码');
$table->string('user_code', 50)->nullable()->comment('提报人工号');
$table->string('reporter', 100)->nullable()->comment('提报人');
$table->bigInteger('reporter_id')->nullable()->comment('提报人ID');
$table->bigInteger('type_id')->nullable()->comment('处理类型设置ID');
$table->string('type_code', 64)->comment('处理类型编码');
$table->string('type_name', 100)->comment('处理类型名称');
$table->bigInteger('reason_id')->nullable()->comment('异常原因设置ID');
$table->string('reason_code', 64)->comment('异常原因编码');
$table->string('reason_name', 100)->comment('异常原因名称');
$table->bigInteger('issue_id')->nullable()->comment('具体问题设置ID');
$table->string('issue_code', 64)->nullable()->comment('具体问题编码');
$table->string('issue_name', 100)->nullable()->comment('具体问题名称');
$table->json('images')->nullable()->comment('现场图片');
$table->text('remark')->nullable()->comment('补充说明');
$table->tinyInteger('status')->default(0)->comment('处理状态:0待处理1处理中2已处理');
$table->string('handler', 100)->nullable()->comment('处理人');
$table->bigInteger('handler_id')->nullable()->comment('处理人ID');
$table->bigInteger('handled_at')->nullable()->comment('处理时间');
$table->bigInteger('reported_at')->nullable()->comment('提报时间');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->index('order_no', 'idx_exception_record_order_no');
$table->index('user_code', 'idx_exception_record_user_code');
$table->index('type_code', 'idx_exception_record_type_code');
$table->index('reason_code', 'idx_exception_record_reason_code');
$table->index('issue_code', 'idx_exception_record_issue_code');
$table->index('status', 'idx_exception_record_status');
$table->index('reported_at', 'idx_exception_record_reported_at');
$table->index('deleted_at', 'idx_exception_record_deleted');
});
}
}
private function seedExceptionSettings(Builder $schema): void
{
$timestamp = time();
$rows = [];
$add = static function (?string $parentId, string $type, string $code, string $name, int $sort) use (&$rows, $timestamp): string {
$id = (string) Snowflake::generate();
$rows[] = [
'id' => $id,
'parent_id' => $parentId,
'setting_type' => $type,
'code' => $code,
'name' => $name,
'sort' => $sort,
'is_enabled' => 1,
'created_at' => $timestamp,
'updated_at' => $timestamp,
];
return $id;
};
$repairTypeId = $add(null, 'type', 'defective_repair', '不良维修', 1);
$returnTypeId = $add(null, 'type', 'return_reconfigure', '退料重配', 2);
$testReasonId = $add($repairTypeId, 'reason', 'test_defect', '测试不良', 1);
$agingReasonId = $add($repairTypeId, 'reason', 'aging_defect', '老化不良', 2);
foreach ([
['configuration_error', '配置错误'],
['order_review_error', '审单错误'],
['picking_error', '配货错误'],
['order_change', '改单'],
['return_refund', '退货退款'],
] as $sort => [$code, $name]) {
$add($returnTypeId, 'reason', $code, $name, $sort + 1);
}
$testIssues = ['不亮', '不进', '不通电', '死机', '卡logo', '机箱风扇不良', 'USB接口不良', '面板LED异常', '异响', '少配件', '配置不符', '风扇灯光异常', '机箱不良', '炸电源', '水冷坏', '声卡异常', '网卡异常', '不读硬盘', '硬盘超时', '掉盘', '机械格式化失败', '硬盘坏', '硬盘容量不对', '掉驱动', '打不上驱动', '不断电', '不认无线', '内存不识别', '闪屏', '断电', '花屏', '烤黑', '高温', '短路', '蓝屏', 'AIDA红', '烤断电', '灰屏', '烤机重启', '卡顿', '机械共振', '烤机使用核显', 'CPU主频低', '自动重启', '显存不符'];
foreach ($testIssues as $sort => $name) {
$add($testReasonId, 'issue', 'test_issue_' . str_pad((string) ($sort + 1), 2, '0', STR_PAD_LEFT), $name, $sort + 1);
}
$agingIssues = ['烤花屏', '烤黑屏', 'CPU高温', '显卡高温', '烤蓝屏', 'AIDA红', '烤断电', '烤灰屏', '烤重启', '烤机使用核显', 'CPU主频低', '显卡掉帧', '掉驱动'];
foreach ($agingIssues as $sort => $name) {
$add($agingReasonId, 'issue', 'aging_issue_' . str_pad((string) ($sort + 1), 2, '0', STR_PAD_LEFT), $name, $sort + 1);
}
$schema->getConnection()->table('produce_exception_setting')->insert($rows);
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_exception_record');
$schema->dropIfExists('produce_exception_setting');
}
};
@@ -0,0 +1,51 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_material_category')) {
$schema->create('produce_material_category', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('category_name', 100)->comment('分类名称');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique('category_name', 'uk_material_category_name');
$table->index('deleted_at', 'idx_material_category_deleted_at');
});
}
if (!$schema->hasTable('produce_material')) {
$schema->create('produce_material', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('category_id')->nullable()->comment('分类ID');
$table->string('product_code', 100)->comment('商品编码');
$table->string('product_name', 200)->comment('商品名称');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique('product_code', 'uk_material_product_code');
$table->index('category_id', 'idx_material_category_id');
$table->index('product_name', 'idx_material_product_name');
$table->index('deleted_at', 'idx_material_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_material');
$schema->dropIfExists('produce_material_category');
}
};
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if (!$schema->hasTable('produce_repair_setting')) {
$schema->create('produce_repair_setting', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('setting_type', 50)->comment('设置类型');
$table->string('setting_name', 100)->comment('设置名称');
$table->string('setting_value', 255)->nullable()->comment('设置值');
$table->integer('sort')->default(0)->comment('排序');
$table->tinyInteger('is_enabled')->default(1)->comment('是否启用');
$table->string('remark', 500)->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['setting_type', 'setting_name'], 'uk_repair_setting_type_name');
$table->index(['setting_type', 'is_enabled'], 'idx_repair_setting_type_enabled');
$table->index('deleted_at', 'idx_repair_setting_deleted_at');
});
}
if (!$schema->hasTable('produce_hardware_fault_description')) {
$schema->create('produce_hardware_fault_description', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->bigInteger('category_id')->comment('物料分类ID');
$table->string('description', 500)->comment('硬件故障描述');
$table->unsignedInteger('use_count')->default(0)->comment('使用次数');
$table->tinyInteger('is_enabled')->default(1)->comment('是否启用');
$table->string('remark', 500)->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique(['category_id', 'description'], 'uk_hardware_fault_category_description');
$table->index(['category_id', 'is_enabled'], 'idx_hardware_fault_category_enabled');
$table->index('use_count', 'idx_hardware_fault_use_count');
$table->index('deleted_at', 'idx_hardware_fault_deleted_at');
});
}
if (!$schema->hasTable('produce_repair_record')) {
$schema->create('produce_repair_record', function (Blueprint $table) {
$table->bigInteger('id')->primary()->comment('主键ID');
$table->string('repair_no', 100)->comment('维修单号');
$table->string('order_no', 100)->nullable()->comment('订单号');
$table->string('product_code', 100)->nullable()->comment('商品编码');
$table->string('product_name', 200)->nullable()->comment('商品名称');
$table->bigInteger('category_id')->nullable()->comment('物料分类ID');
$table->string('category_name', 100)->nullable()->comment('物料分类名称快照');
$table->bigInteger('fault_description_id')->nullable()->comment('硬件故障描述ID');
$table->string('fault_description', 500)->nullable()->comment('硬件故障描述快照');
$table->string('repair_result', 50)->nullable()->comment('维修判定');
$table->json('parts')->nullable()->comment('更换备件');
$table->string('operator', 100)->nullable()->comment('维修人员');
$table->bigInteger('repaired_at')->nullable()->comment('维修时间');
$table->string('remark', 1000)->nullable()->comment('备注');
$table->bigInteger('created_by')->nullable()->comment('创建人ID');
$table->bigInteger('updated_by')->nullable()->comment('更新人ID');
$table->bigInteger('created_at')->nullable()->comment('创建时间');
$table->bigInteger('updated_at')->nullable()->comment('更新时间');
$table->bigInteger('deleted_at')->nullable()->comment('删除时间');
$table->unique('repair_no', 'uk_repair_record_repair_no');
$table->index('order_no', 'idx_repair_record_order_no');
$table->index('product_code', 'idx_repair_record_product_code');
$table->index('category_id', 'idx_repair_record_category_id');
$table->index('fault_description_id', 'idx_repair_record_fault_description_id');
$table->index('repaired_at', 'idx_repair_record_repaired_at');
$table->index('deleted_at', 'idx_repair_record_deleted_at');
});
}
}
public function down(Builder $schema): void
{
$schema->dropIfExists('produce_repair_record');
$schema->dropIfExists('produce_hardware_fault_description');
$schema->dropIfExists('produce_repair_setting');
}
};
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
$table = 'produce_repair_record';
if (!$schema->hasTable($table)) {
return;
}
$schema->table($table, function (Blueprint $table) use ($schema) {
if (!$schema->hasColumn('produce_repair_record', 'exception_id')) {
$table->bigInteger('exception_id')->nullable()->comment('关联异常记录ID');
$table->index('exception_id', 'idx_repair_record_exception_id');
}
if (!$schema->hasColumn('produce_repair_record', 'exception_reason')) {
$table->string('exception_reason', 100)->nullable()->comment('异常原因快照');
}
if (!$schema->hasColumn('produce_repair_record', 'exception_issue')) {
$table->string('exception_issue', 100)->nullable()->comment('具体问题快照');
}
});
}
public function down(Builder $schema): void
{
$table = 'produce_repair_record';
if (!$schema->hasTable($table)) {
return;
}
$schema->table($table, function (Blueprint $table) use ($schema) {
if ($schema->hasColumn('produce_repair_record', 'exception_id')) {
$table->dropIndex('idx_repair_record_exception_id');
$table->dropColumn('exception_id');
}
if ($schema->hasColumn('produce_repair_record', 'exception_reason')) {
$table->dropColumn('exception_reason');
}
if ($schema->hasColumn('produce_repair_record', 'exception_issue')) {
$table->dropColumn('exception_issue');
}
});
}
};
@@ -0,0 +1,85 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
$table = 'produce_repair_setting';
if (!$schema->hasTable($table)) {
return;
}
$hasParentId = $schema->hasColumn($table, 'parent_id');
$hasCode = $schema->hasColumn($table, 'code');
$hasName = $schema->hasColumn($table, 'name');
$hasSettingType = $schema->hasColumn($table, 'setting_type');
$hasSettingName = $schema->hasColumn($table, 'setting_name');
$schema->table($table, function (Blueprint $table) use ($hasParentId, $hasCode, $hasName) {
if (!$hasParentId) {
$table->bigInteger('parent_id')->nullable()->comment('父级ID');
$table->index('parent_id', 'idx_repair_setting_parent');
}
if (!$hasCode) {
$table->string('code', 64)->nullable()->comment('设置编码');
}
if (!$hasName) {
$table->string('name', 100)->nullable()->comment('设置名称');
}
});
$connection = $schema->getConnection();
if (!$hasCode && $hasSettingType) {
$connection->table($table)->whereNull('code')->update([
'code' => $connection->raw('setting_type'),
]);
}
if (!$hasName && $hasSettingName) {
$connection->table($table)->whereNull('name')->update([
'name' => $connection->raw('setting_name'),
]);
}
if ($hasSettingType) {
$connection->table($table)
->whereNotIn('setting_type', ['type', 'reason', 'issue'])
->update(['setting_type' => 'type']);
}
$schema->table($table, function (Blueprint $table) use ($hasCode, $hasName) {
if (!$hasCode) {
$table->string('code', 64)->nullable(false)->change();
}
if (!$hasName) {
$table->string('name', 100)->nullable(false)->change();
}
});
}
public function down(Builder $schema): void
{
$table = 'produce_repair_setting';
if (!$schema->hasTable($table)) {
return;
}
$hasLegacySettingType = $schema->hasColumn($table, 'setting_type');
$hasLegacySettingName = $schema->hasColumn($table, 'setting_name');
$schema->table($table, function (Blueprint $table) use ($schema, $hasLegacySettingType, $hasLegacySettingName) {
if ($hasLegacySettingType && $schema->hasColumn('produce_repair_setting', 'parent_id')) {
$table->dropIndex('idx_repair_setting_parent');
$table->dropColumn('parent_id');
}
if ($hasLegacySettingType && $schema->hasColumn('produce_repair_setting', 'code')) {
$table->dropColumn('code');
}
if ($hasLegacySettingName && $schema->hasColumn('produce_repair_setting', 'name')) {
$table->dropColumn('name');
}
});
}
};
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
$table = 'produce_repair_record';
if (!$schema->hasTable($table)) {
return;
}
$schema->table($table, function (Blueprint $table) use ($schema) {
if (!$schema->hasColumn('produce_repair_record', 'operation_fault_steps')) {
$table->json('operation_fault_steps')->nullable()->comment('作业不良责任步骤快照');
}
if (!$schema->hasColumn('produce_repair_record', 'responsible_operators')) {
$table->json('responsible_operators')->nullable()->comment('作业不良责任人员快照');
}
});
}
public function down(Builder $schema): void
{
$table = 'produce_repair_record';
if (!$schema->hasTable($table)) {
return;
}
$schema->table($table, function (Blueprint $table) use ($schema) {
if ($schema->hasColumn('produce_repair_record', 'operation_fault_steps')) {
$table->dropColumn('operation_fault_steps');
}
if ($schema->hasColumn('produce_repair_record', 'responsible_operators')) {
$table->dropColumn('responsible_operators');
}
});
}
};
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if ($schema->hasTable('produce_repair_record') && !$schema->hasColumn('produce_repair_record', 'category_ids')) {
$schema->table('produce_repair_record', function (Blueprint $table) {
$table->json('category_ids')->nullable()->after('category_id')->comment('物料分类ID集合');
$table->json('category_names')->nullable()->after('category_name')->comment('物料分类名称快照集合');
});
}
}
public function down(Builder $schema): void
{
if ($schema->hasTable('produce_repair_record') && $schema->hasColumn('produce_repair_record', 'category_ids')) {
$schema->table('produce_repair_record', function (Blueprint $table) {
$table->dropColumn(['category_ids', 'category_names']);
});
}
}
};
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if ($schema->hasTable('produce_scan_data') && !$schema->hasColumn('produce_scan_data', 'quantity')) {
$schema->table('produce_scan_data', function (Blueprint $table) {
$table->integer('quantity')->default(1)->after('order_no')->comment('本次数量');
});
}
}
public function down(Builder $schema): void
{
if ($schema->hasTable('produce_scan_data') && $schema->hasColumn('produce_scan_data', 'quantity')) {
$schema->table('produce_scan_data', function (Blueprint $table) {
$table->dropColumn('quantity');
});
}
}
};
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder;
return new class {
public function up(Builder $schema): void
{
if ($schema->hasTable('produce_repair_record') && !$schema->hasColumn('produce_repair_record', 'images')) {
$schema->table('produce_repair_record', function (Blueprint $table) {
$table->json('images')->nullable()->after('parts')->comment('维修现场图片');
});
}
}
public function down(Builder $schema): void
{
if ($schema->hasTable('produce_repair_record') && $schema->hasColumn('produce_repair_record', 'images')) {
$schema->table('produce_repair_record', function (Blueprint $table) {
$table->dropColumn('images');
});
}
}
};
@@ -0,0 +1,630 @@
<?php
declare(strict_types=1);
namespace plugin\produce\resource\database\seeds;
use core\uuid\Snowflake;
use Illuminate\Database\Seeder;
use plugin\produce\app\model\Process;
use plugin\produce\app\model\ProcessStep;
use plugin\produce\app\model\StatusTransition;
use plugin\produce\app\model\StepRelation;
use plugin\produce\app\model\StepStatus;
class ProduceDemoDataSeeder extends Seeder
{
public function run(): void
{
$now = time();
$adminId = 1;
StatusTransition::withTrashed()->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,
]);
}
}
}