- SystemSettingFactory: 系统设置工厂 - TerminalFactory: 终端工厂 - SopTemplateFactory: SOP模板工厂 - SystemSettingSeeder: 系统设置种子数据 - TerminalSeeder: 终端种子数据 - SopTemplateSeeder: SOP模板种子数据 - 更新 DatabaseSeeder 注册新的种子类
114 lines
3.4 KiB
PHP
114 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Terminal;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Terminal>
|
|
*/
|
|
class TerminalFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Terminal::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'name' => fake()->randomElement(['生产线A', '生产线B', '生产线C', '质检站', '包装站']) . '-' . fake()->randomElement(['工位1', '工位2', '工位3']),
|
|
'code' => 'TERM-' . fake()->unique()->numerify('####'),
|
|
'ip_address' => fake()->localIpv4(),
|
|
'station_id' => null, // 需要关联实际的线站ID
|
|
'diagram_url' => fake()->imageUrl(1920, 1080, 'diagram', true),
|
|
'display_config' => [
|
|
'resolution' => fake()->randomElement(['1920x1080', '2560x1440', '3840x2160']),
|
|
'refresh_rate' => fake()->randomElement([30, 60, 120]),
|
|
'orientation' => fake()->randomElement(['landscape', 'portrait']),
|
|
'brightness' => fake()->numberBetween(50, 100),
|
|
],
|
|
'is_online' => fake()->boolean(70), // 70%概率在线
|
|
'last_online_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* 指定终端为在线状态
|
|
*/
|
|
public function online(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_online' => true,
|
|
'last_online_at' => now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定终端为离线状态
|
|
*/
|
|
public function offline(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'is_online' => false,
|
|
'last_online_at' => fake()->dateTimeBetween('-30 days', '-1 day'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定终端为高分辨率配置
|
|
*/
|
|
public function highResolution(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'display_config' => [
|
|
'resolution' => '3840x2160',
|
|
'refresh_rate' => 60,
|
|
'orientation' => 'landscape',
|
|
'brightness' => 80,
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定终端为生产线终端
|
|
*/
|
|
public function productionLine(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'name' => '生产线' . fake()->randomElement(['A', 'B', 'C', 'D']) . '-工位' . fake()->numberBetween(1, 10),
|
|
'code' => 'PROD-' . fake()->unique()->numerify('####'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定终端为质检站终端
|
|
*/
|
|
public function qualityControl(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'name' => '质检站-' . fake()->randomElement(['入库检', '出库检', '过程检']) . '-' . fake()->numberBetween(1, 5),
|
|
'code' => 'QC-' . fake()->unique()->numerify('####'),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 指定终端为包装站终端
|
|
*/
|
|
public function packaging(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'name' => '包装站-工位' . fake()->numberBetween(1, 8),
|
|
'code' => 'PKG-' . fake()->unique()->numerify('####'),
|
|
]);
|
|
}
|
|
}
|