refactor: 修复知识库和操作指引

This commit is contained in:
2026-03-13 14:32:37 +08:00
parent bbe8e60646
commit 58f42de9df
88 changed files with 3387 additions and 2472 deletions

View File

@@ -16,7 +16,7 @@ return new class extends Migration
$table->string('name')->comment('终端名称');
$table->string('code', 100)->unique()->comment('终端编码');
$table->string('ip_address', 45)->nullable()->comment('IP地址');
$table->unsignedBigInteger('station_id')->nullable()->comment('线站ID');
$table->string('station_id', 50)->nullable()->comment('线站ID');
$table->string('diagram_url', 500)->nullable()->comment('组态图URL');
$table->json('display_config')->nullable()->comment('显示配置');
$table->boolean('is_online')->default(false)->comment('在线状态');

View File

@@ -1,42 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sop_templates', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('模板名称');
$table->text('description')->nullable()->comment('模板描述');
$table->string('category', 100)->nullable()->comment('分类');
$table->json('tags')->nullable()->comment('标签');
$table->string('version', 50)->default('1.0.0')->comment('版本号');
$table->enum('status', ['draft', 'published', 'archived'])->default('draft')->comment('状态');
$table->json('applicable_departments')->nullable()->comment('适用部门');
$table->json('applicable_positions')->nullable()->comment('适用岗位');
$table->timestamp('published_at')->nullable()->comment('发布时间');
$table->unsignedBigInteger('created_by')->nullable()->comment('创建人');
$table->timestamps();
$table->softDeletes();
// 添加索引
$table->index('status', 'idx_sop_templates_status');
$table->index('category', 'idx_sop_templates_category');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sop_templates');
}
};

View File

@@ -1,42 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sop_steps', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('sop_template_id')->comment('模板ID');
$table->integer('step_number')->comment('步骤序号');
$table->string('title')->comment('步骤标题');
$table->text('content')->nullable()->comment('步骤内容');
$table->integer('sort_order')->default(0)->comment('排序');
$table->boolean('is_required')->default(true)->comment('是否必需');
$table->timestamps();
// 添加外键约束
$table->foreign('sop_template_id')
->references('id')
->on('sop_templates')
->onDelete('cascade');
// 添加索引
$table->index(['sop_template_id', 'sort_order'], 'idx_template_sort');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sop_steps');
}
};

View File

@@ -1,39 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sop_interactive_tasks', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('sop_step_id')->comment('步骤ID');
$table->enum('task_type', ['confirm', 'input', 'select', 'photo', 'scan'])->comment('任务类型');
$table->json('task_config')->nullable()->comment('任务配置');
$table->json('validation_rules')->nullable()->comment('验证规则');
$table->integer('timeout_seconds')->nullable()->comment('超时时间');
$table->boolean('is_required')->default(true)->comment('是否必需');
$table->timestamps();
// 添加外键约束
$table->foreign('sop_step_id')
->references('id')
->on('sop_steps')
->onDelete('cascade');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sop_interactive_tasks');
}
};

View File

@@ -1,41 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('sop_template_versions', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('sop_template_id')->comment('模板ID');
$table->string('version', 50)->comment('版本号');
$table->text('change_log')->nullable()->comment('变更说明');
$table->json('content_snapshot')->nullable()->comment('内容快照');
$table->unsignedBigInteger('created_by')->nullable()->comment('创建人');
$table->timestamp('created_at')->nullable();
// 添加外键约束
$table->foreign('sop_template_id')
->references('id')
->on('sop_templates')
->onDelete('cascade');
// 添加索引
$table->index(['sop_template_id', 'version'], 'idx_template_version');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('sop_template_versions');
}
};

View File

@@ -24,8 +24,8 @@ return new class extends Migration
// 终端管理
'terminal.viewAny' => 'terminal.view',
// SOP模板
'sop-template.viewAny' => 'sop-template.view',
// 操作指引
'guide.viewAny' => 'guide.view',
// 分组管理
'group.viewAny' => 'group.view',
@@ -78,7 +78,7 @@ return new class extends Migration
'system-setting.view',
'activity-log.view',
'terminal.view',
'sop-template.view',
'guide.view',
'group.view',
'user.view',
'role.view',

View File

@@ -0,0 +1,60 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::create('guides', function (Blueprint $table) {
$table->id();
$table->string('name')->comment('指引名称');
$table->text('description')->nullable()->comment('指引描述');
$table->string('category', 50)->default('operation')->comment('分类: operation/fault_handling/training');
$table->json('tags')->nullable()->comment('标签');
$table->string('status', 20)->default('draft')->comment('状态: draft/published/archived');
$table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
$table->timestamp('published_at')->nullable();
$table->timestamps();
$table->softDeletes();
$table->index('category');
$table->index('status');
});
Schema::create('guide_pages', function (Blueprint $table) {
$table->id();
$table->foreignId('guide_id')->constrained()->cascadeOnDelete();
$table->unsignedInteger('page_number')->comment('页码');
$table->string('title')->comment('页面标题');
$table->string('html_url', 500)->comment('HTML页面链接');
$table->integer('parent_id')->default(-1);
$table->unsignedInteger('sort_order')->default(0)->comment('排序');
$table->json('options')->nullable();
$table->string('branch_option', 100)->nullable();
$table->timestamps();
$table->index('parent_id');
$table->index(['guide_id', 'sort_order']);
});
Schema::create('terminal_guides', function (Blueprint $table) {
$table->id();
$table->foreignId('terminal_id')->constrained()->cascadeOnDelete();
$table->foreignId('guide_id')->constrained()->cascadeOnDelete();
$table->integer('priority')->default(0);
$table->timestamps();
$table->unique(['terminal_id', 'guide_id'], 'uk_terminal_guide');
});
}
public function down(): void
{
Schema::dropIfExists('terminal_guides');
Schema::dropIfExists('guide_pages');
Schema::dropIfExists('guides');
}
};

View File

@@ -0,0 +1,27 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('terminals', function (Blueprint $table) {
$table->string('mac_address', 17)->nullable()->unique()->after('ip_address')
->comment('MAC地址 (AA:BB:CC:DD:EE:FF)');
$table->string('scada_data_url', 500)->nullable()->after('diagram_url')
->comment('OPC UA网关数据查询地址');
$table->string('scada_tags_url', 500)->nullable()->after('scada_data_url')
->comment('OPC UA网关点位定义查询地址');
});
}
public function down(): void
{
Schema::table('terminals', function (Blueprint $table) {
$table->dropColumn(['mac_address', 'scada_data_url', 'scada_tags_url']);
});
}
};

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
public function up(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->foreignId('knowledge_base_id')
->nullable()
->after('group_id')
->constrained('knowledge_bases')
->nullOnDelete();
$table->index('knowledge_base_id');
});
}
public function down(): void
{
Schema::table('documents', function (Blueprint $table) {
$table->dropForeign(['knowledge_base_id']);
$table->dropColumn('knowledge_base_id');
});
}
};