feat: 實作機台日誌核心功能與 IoT 高併發處理架構
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 36s
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 36s
This commit is contained in:
23
database/factories/Machine/MachineFactory.php
Normal file
23
database/factories/Machine/MachineFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Machine;
|
||||
|
||||
use App\Models\Machine\Machine;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class MachineFactory extends Factory
|
||||
{
|
||||
protected $model = Machine::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'Machine-' . $this->faker->unique()->numberBetween(100, 999),
|
||||
'location' => $this->faker->address(),
|
||||
'status' => $this->faker->randomElement(['online', 'offline', 'error']),
|
||||
'temperature' => $this->faker->randomFloat(2, 2, 10),
|
||||
'firmware_version' => 'v' . $this->faker->randomElement(['1.0.0', '1.1.2', '2.0.1']),
|
||||
'last_heartbeat_at' => $this->faker->dateTimeBetween('-1 day', 'now'),
|
||||
];
|
||||
}
|
||||
}
|
||||
26
database/factories/Machine/MachineLogFactory.php
Normal file
26
database/factories/Machine/MachineLogFactory.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories\Machine;
|
||||
|
||||
use App\Models\Machine\Machine;
|
||||
use App\Models\Machine\MachineLog;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class MachineLogFactory extends Factory
|
||||
{
|
||||
protected $model = MachineLog::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'machine_id' => Machine::factory(),
|
||||
'level' => $this->faker->randomElement(['info', 'warning', 'error']),
|
||||
'message' => $this->faker->sentence(),
|
||||
'context' => [
|
||||
'ip' => $this->faker->ipv4(),
|
||||
'uptime' => $this->faker->numberBetween(1000, 100000),
|
||||
],
|
||||
'created_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\System\User>
|
||||
*/
|
||||
class UserFactory extends Factory
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\System\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
||||
|
||||
21
database/seeders/MachineSeeder.php
Normal file
21
database/seeders/MachineSeeder.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Machine\Machine;
|
||||
use App\Models\Machine\MachineLog;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class MachineSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
// 建立 50 台機台
|
||||
Machine::factory()->count(50)->create()->each(function ($machine) {
|
||||
// 每台機台隨機建立 5-10 筆初始日誌
|
||||
MachineLog::factory()->count(rand(5, 10))->create([
|
||||
'machine_id' => $machine->id,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user