feat: 创建工厂类和种子数据
- SystemSettingFactory: 系统设置工厂 - TerminalFactory: 终端工厂 - SopTemplateFactory: SOP模板工厂 - SystemSettingSeeder: 系统设置种子数据 - TerminalSeeder: 终端种子数据 - SopTemplateSeeder: SOP模板种子数据 - 更新 DatabaseSeeder 注册新的种子类
This commit is contained in:
61
database/factories/SopTemplateFactory.php
Normal file
61
database/factories/SopTemplateFactory.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SopTemplate;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SopTemplate>
|
||||
*/
|
||||
class SopTemplateFactory extends Factory
|
||||
{
|
||||
protected $model = SopTemplate::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => fake()->randomElement([
|
||||
'设备启动操作规程',
|
||||
'产品质检标准流程',
|
||||
'安全生产检查清单',
|
||||
'设备维护保养流程',
|
||||
'应急处理操作指南',
|
||||
]) . '-' . fake()->numberBetween(1, 100),
|
||||
'description' => fake()->sentence(20),
|
||||
'category' => fake()->randomElement(['生产操作', '质量管理', '安全管理', '设备维护', '应急处理']),
|
||||
'tags' => fake()->randomElements(['标准作业', '安全', '质量', '效率', '培训'], fake()->numberBetween(1, 3)),
|
||||
'version' => '1.0.0',
|
||||
'status' => fake()->randomElement(['draft', 'published', 'archived']),
|
||||
'applicable_departments' => fake()->randomElements(['生产部', '质检部', '设备部', '安全部'], fake()->numberBetween(1, 2)),
|
||||
'applicable_positions' => fake()->randomElements(['操作员', '质检员', '班组长', '技术员'], fake()->numberBetween(1, 2)),
|
||||
'published_at' => fake()->optional(0.6)->dateTimeBetween('-6 months', 'now'),
|
||||
'created_by' => User::factory(),
|
||||
];
|
||||
}
|
||||
|
||||
public function draft(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'draft',
|
||||
'published_at' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function published(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'published',
|
||||
'published_at' => now(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function archived(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'status' => 'archived',
|
||||
'published_at' => fake()->dateTimeBetween('-1 year', '-1 month'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
104
database/factories/SystemSettingFactory.php
Normal file
104
database/factories/SystemSettingFactory.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\SystemSetting;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\SystemSetting>
|
||||
*/
|
||||
class SystemSettingFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = SystemSetting::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'key' => fake()->unique()->word(),
|
||||
'value' => [
|
||||
'enabled' => fake()->boolean(),
|
||||
'value' => fake()->word(),
|
||||
],
|
||||
'group' => fake()->randomElement(['general', 'embedding', 'chunking', 'system']),
|
||||
'description' => fake()->sentence(),
|
||||
'is_public' => fake()->boolean(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为嵌入模型配置
|
||||
*/
|
||||
public function embedding(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'embedding',
|
||||
'value' => [
|
||||
'model_name' => fake()->randomElement(['text-embedding-ada-002', 'text-embedding-3-small', 'text-embedding-3-large']),
|
||||
'api_key' => 'sk-' . fake()->uuid(),
|
||||
'endpoint_url' => fake()->url(),
|
||||
'dimensions' => fake()->randomElement([1536, 3072]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为分块参数配置
|
||||
*/
|
||||
public function chunking(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'chunking',
|
||||
'value' => [
|
||||
'chunk_size' => fake()->numberBetween(500, 2000),
|
||||
'chunk_overlap' => fake()->numberBetween(50, 200),
|
||||
'separator' => fake()->randomElement(["\n\n", "\n", " "]),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为系统全局配置
|
||||
*/
|
||||
public function system(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'group' => 'system',
|
||||
'value' => [
|
||||
'system_name' => fake()->company(),
|
||||
'timeout' => fake()->numberBetween(30, 300),
|
||||
'max_retries' => fake()->numberBetween(1, 5),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为公开配置
|
||||
*/
|
||||
public function public(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_public' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定配置为私有配置
|
||||
*/
|
||||
public function private(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'is_public' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
113
database/factories/TerminalFactory.php
Normal file
113
database/factories/TerminalFactory.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?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('####'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user