refactor: kb & station & terminal
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\Group;
|
||||
use App\Models\KnowledgeBase;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
@@ -12,40 +12,21 @@ use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
*/
|
||||
class DocumentFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Document::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
// 使用中文 Faker 生成器
|
||||
$faker = \Faker\Factory::create('zh_CN');
|
||||
|
||||
// 生成中文文档标题
|
||||
|
||||
$titles = [
|
||||
'项目管理规范',
|
||||
'技术文档模板',
|
||||
'员工手册',
|
||||
'产品需求文档',
|
||||
'系统设计方案',
|
||||
'测试报告',
|
||||
'会议纪要',
|
||||
'培训资料',
|
||||
'操作指南',
|
||||
'年度总结报告',
|
||||
'项目管理规范', '技术文档模板', '员工手册', '产品需求文档',
|
||||
'系统设计方案', '测试报告', '会议纪要', '培训资料',
|
||||
'操作指南', '年度总结报告',
|
||||
];
|
||||
|
||||
|
||||
$title = $faker->randomElement($titles) . ' - ' . $faker->word();
|
||||
$fileName = $faker->word() . '_' . date('Ymd') . '.docx';
|
||||
|
||||
|
||||
return [
|
||||
'title' => $title,
|
||||
'description' => $faker->paragraph(3),
|
||||
@@ -53,38 +34,15 @@ class DocumentFactory extends Factory
|
||||
'file_name' => $fileName,
|
||||
'file_size' => fake()->numberBetween(10000, 5000000),
|
||||
'mime_type' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||
'type' => fake()->randomElement(['global', 'dedicated']),
|
||||
'group_id' => null,
|
||||
'knowledge_base_id' => KnowledgeBase::factory(),
|
||||
'uploaded_by' => User::factory(),
|
||||
'markdown_path' => null,
|
||||
'markdown_preview' => null,
|
||||
|
||||
'conversion_status' => 'pending',
|
||||
'conversion_error' => null,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定文档为全局类型
|
||||
*/
|
||||
public function global(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'global',
|
||||
'group_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定文档为专用类型
|
||||
*/
|
||||
public function dedicated(?int $groupId = null): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'type' => 'dedicated',
|
||||
'group_id' => $groupId ?? Group::factory(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定文档已完成转换
|
||||
*/
|
||||
@@ -92,10 +50,10 @@ class DocumentFactory extends Factory
|
||||
{
|
||||
$faker = \Faker\Factory::create('zh_CN');
|
||||
$uuid = fake()->uuid();
|
||||
|
||||
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'markdown_path' => 'markdown/' . date('Y/m/d') . '/' . $uuid . '.md',
|
||||
'markdown_preview' => $faker->text(500),
|
||||
|
||||
'conversion_status' => 'completed',
|
||||
'conversion_error' => null,
|
||||
]);
|
||||
@@ -108,7 +66,7 @@ class DocumentFactory extends Factory
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'markdown_path' => null,
|
||||
'markdown_preview' => null,
|
||||
|
||||
'conversion_status' => 'failed',
|
||||
'conversion_error' => 'Failed to convert document: Invalid file format',
|
||||
]);
|
||||
@@ -121,7 +79,7 @@ class DocumentFactory extends Factory
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'markdown_path' => null,
|
||||
'markdown_preview' => null,
|
||||
|
||||
'conversion_status' => 'processing',
|
||||
'conversion_error' => null,
|
||||
]);
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Document;
|
||||
use App\Models\DownloadLog;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\DownloadLog>
|
||||
*/
|
||||
class DownloadLogFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = DownloadLog::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'document_id' => Document::factory(),
|
||||
'user_id' => User::factory(),
|
||||
'downloaded_at' => fake()->dateTimeBetween('-1 year', 'now'),
|
||||
'ip_address' => fake()->ipv4(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定下载日志使用特定的文档
|
||||
*/
|
||||
public function forDocument(Document|int $document): static
|
||||
{
|
||||
$documentId = $document instanceof Document ? $document->id : $document;
|
||||
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'document_id' => $documentId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定下载日志使用特定的用户
|
||||
*/
|
||||
public function forUser(User|int $user): static
|
||||
{
|
||||
$userId = $user instanceof User ? $user->id : $user;
|
||||
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定下载日志使用最近的时间
|
||||
*/
|
||||
public function recent(): static
|
||||
{
|
||||
return $this->state(fn (array $attributes) => [
|
||||
'downloaded_at' => fake()->dateTimeBetween('-7 days', 'now'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Group>
|
||||
*/
|
||||
class GroupFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Group::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
// 使用中文 Faker 生成器
|
||||
$faker = \Faker\Factory::create('zh_CN');
|
||||
|
||||
// 生成中文分组名称(使用公司名或部门名)
|
||||
$groupNames = [
|
||||
'技术部',
|
||||
'市场部',
|
||||
'人力资源部',
|
||||
'财务部',
|
||||
'运营部',
|
||||
'产品部',
|
||||
'设计部',
|
||||
'客服部',
|
||||
'研发中心',
|
||||
'销售部',
|
||||
];
|
||||
|
||||
return [
|
||||
'name' => $faker->randomElement($groupNames) . ' - ' . $faker->company(),
|
||||
'description' => $faker->sentence(10),
|
||||
];
|
||||
}
|
||||
}
|
||||
22
database/factories/StationFactory.php
Normal file
22
database/factories/StationFactory.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Station;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Station>
|
||||
*/
|
||||
class StationFactory extends Factory
|
||||
{
|
||||
protected $model = Station::class;
|
||||
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'BL' . fake()->unique()->numerify('##') . fake()->randomElement(['U', 'B', 'W', 'HB']),
|
||||
'description' => null,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class TerminalFactory extends Factory
|
||||
'name' => fake()->randomElement(['生产线A', '生产线B', '生产线C', '质检站', '包装站']) . '-' . fake()->randomElement(['工位1', '工位2', '工位3']),
|
||||
'code' => 'TERM-' . fake()->unique()->numerify('####'),
|
||||
'ip_address' => fake()->localIpv4(),
|
||||
'station_id' => null, // 需要关联实际的线站ID
|
||||
'station_id' => null,
|
||||
'diagram_url' => fake()->imageUrl(1920, 1080, 'diagram', true),
|
||||
'voice_wakeup_enabled' => false,
|
||||
'voice_wakeup_word' => null,
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Terminal;
|
||||
use App\Models\TerminalPrompt;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\TerminalPrompt>
|
||||
*/
|
||||
class TerminalPromptFactory extends Factory
|
||||
{
|
||||
protected $model = TerminalPrompt::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
'terminal_id' => Terminal::factory(),
|
||||
'prompt_template' => '你是{station_id}光束线的AI助手。当前时间是{time}。请根据用户{user}的问题提供帮助。',
|
||||
'variables' => [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user