You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\TestData\CourseContentEvaluationTestDataGenerator;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SeedCourseContentEvaluations extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'seed:course-evaluations
|
|
{--evaluations=20 : 生成评价问卷数量}
|
|
{--users=50 : 最少用户数量}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '生成课程内容评价模块的测试数据,包括问卷、问题字段和用户提交数据';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return int
|
|
*/
|
|
public function handle()
|
|
{
|
|
$evaluationCount = (int) $this->option('evaluations');
|
|
$minUsers = (int) $this->option('users');
|
|
|
|
$this->info("开始生成课程内容评价测试数据...");
|
|
$this->info("计划生成 {$evaluationCount} 个评价问卷,确保至少 {$minUsers} 个用户");
|
|
|
|
$generator = new CourseContentEvaluationTestDataGenerator();
|
|
|
|
$startTime = microtime(true);
|
|
|
|
try {
|
|
$generator->generate($evaluationCount, $minUsers, function (string $message) {
|
|
$this->line(" → {$message}");
|
|
});
|
|
|
|
$duration = round(microtime(true) - $startTime, 2);
|
|
$this->info("✅ 数据生成完成!耗时 {$duration} 秒");
|
|
|
|
return Command::SUCCESS;
|
|
|
|
} catch (\Exception $e) {
|
|
$this->error("❌ 数据生成失败:" . $e->getMessage());
|
|
return Command::FAILURE;
|
|
}
|
|
}
|
|
}
|