feat: multi diagrams
This commit is contained in:
@@ -29,7 +29,7 @@ class TerminalFactory extends Factory
|
||||
'code' => 'TERM-' . fake()->unique()->numerify('####'),
|
||||
'ip_address' => fake()->localIpv4(),
|
||||
'station_id' => null,
|
||||
'diagram_url' => fake()->imageUrl(1920, 1080, 'diagram', true),
|
||||
'diagram_urls' => [['title' => '组态', 'url' => fake()->url()]],
|
||||
'voice_wakeup_enabled' => false,
|
||||
'voice_wakeup_word' => null,
|
||||
'is_online' => fake()->boolean(70), // 70%概率在线
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('terminals', function (Blueprint $table) {
|
||||
$table->renameColumn('diagram_url', 'diagram_urls');
|
||||
});
|
||||
|
||||
// Migrate existing string URLs to JSON array format
|
||||
DB::table('terminals')->whereNotNull('diagram_urls')->orderBy('id')->each(function ($terminal) {
|
||||
$decoded = json_decode($terminal->diagram_urls, true);
|
||||
if (is_array($decoded)) {
|
||||
return; // Already JSON, skip
|
||||
}
|
||||
|
||||
DB::table('terminals')->where('id', $terminal->id)->update([
|
||||
'diagram_urls' => json_encode([['title' => '默认组态', 'url' => $terminal->diagram_urls]]),
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::table('terminals', function (Blueprint $table) {
|
||||
$table->json('diagram_urls')->nullable()->comment('组态界面地址')->change();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
// Extract first URL back to string
|
||||
DB::table('terminals')->whereNotNull('diagram_urls')->orderBy('id')->each(function ($terminal) {
|
||||
$decoded = json_decode($terminal->diagram_urls, true);
|
||||
$url = is_array($decoded) ? ($decoded[0]['url'] ?? null) : $terminal->diagram_urls;
|
||||
|
||||
DB::table('terminals')->where('id', $terminal->id)->update([
|
||||
'diagram_urls' => $url,
|
||||
]);
|
||||
});
|
||||
|
||||
Schema::table('terminals', function (Blueprint $table) {
|
||||
$table->string('diagram_urls', 500)->nullable()->comment('组态界面地址')->change();
|
||||
});
|
||||
|
||||
Schema::table('terminals', function (Blueprint $table) {
|
||||
$table->renameColumn('diagram_urls', 'diagram_url');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -53,7 +53,10 @@ PROMPT;
|
||||
'code' => "SCREEN-{$beamline}",
|
||||
'ip_address' => $ipAddress,
|
||||
'station_id' => $station->id,
|
||||
'diagram_url' => 'https://ssrf.9z.work/scada/demo.html',
|
||||
'diagram_urls' => [
|
||||
['title' => 'BL16U1', 'url' => 'https://ssrf.9z.work/scada/BL16U1.svg'],
|
||||
['title' => 'BL16U1前端布局图', 'url' => 'https://ssrf.9z.work/scada/BL16U1-1.svg']
|
||||
],
|
||||
'is_online' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U']),
|
||||
'last_online_at' => in_array($beamline, ['BL02U1', 'BL07U', 'BL08U', 'BL13U', 'BL15U'])
|
||||
? now()
|
||||
|
||||
Reference in New Issue
Block a user