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.

96 lines
3.2 KiB

5 months ago
<?php
namespace Database\Seeders;
use App\Models\Competition;
use App\Models\CompetitionTrack;
2 months ago
use App\Support\DefaultTrackScoringSheets;
5 months ago
use Illuminate\Database\Seeder;
/**
1 month ago
* 与最新原型 user-form / event-site 四个细分赛道对齐。
5 months ago
*
* php artisan db:seed --class=CompetitionDefaultTracksSeeder
*/
class CompetitionDefaultTracksSeeder extends Seeder
{
/** @var list<array{track_code: string, title: string, description: string, sort: int}> */
private const ROWS = [
[
1 month ago
'track_code' => 'guang_xinpian',
'title' => '芯片与组件',
'description' => '光芯片、光电元器件、光模块等核心芯片与组件研发创新',
5 months ago
'sort' => 1,
],
[
1 month ago
'track_code' => 'zhizao_fengzhuang',
'title' => '制造与封装',
'description' => '光电子精密制造、器件封装耦合、量产工艺优化等制造封装技术攻关',
5 months ago
'sort' => 2,
],
[
1 month ago
'track_code' => 'guangdian_cailiao',
'title' => '材料与设备',
'description' => '光电功能新材料、光纤基材及光刻、镀膜、精密测试等专用设备研发',
5 months ago
'sort' => 3,
],
[
1 month ago
'track_code' => 'guangtongxin_yingyong',
'title' => '场景与应用',
'description' => '面向算力网络、移动通信、车载互联、工业传感、航空航天、医疗等领域的系统方案与应用创新',
5 months ago
'sort' => 4,
],
];
1 month ago
/** 历史赛道编码,同步时停用 */
private const LEGACY_TRACK_CODES = [
'tese_xiaofei',
'jiankang_xiaofei',
'shang_wen_lv',
'xiaofei_ai',
];
5 months ago
public function run(): void
{
2 months ago
$envId = (int) env('DEFAULT_TRACKS_COMPETITION_ID', 0);
$competitions = $envId > 0
? Competition::query()->whereKey($envId)->get()
: Competition::query()->orderBy('id')->get();
if ($competitions->isEmpty()) {
$this->command?->warn('No competition found, skip tracks seed.');
5 months ago
return;
}
2 months ago
foreach ($competitions as $competition) {
1 month ago
CompetitionTrack::query()
->where('competition_id', $competition->id)
->whereIn('track_code', self::LEGACY_TRACK_CODES)
->update(['is_enabled' => false]);
2 months ago
foreach (self::ROWS as $row) {
$sheet = DefaultTrackScoringSheets::forTrackCode($row['track_code'], $row['title']);
CompetitionTrack::query()->updateOrCreate(
[
'competition_id' => $competition->id,
'track_code' => $row['track_code'],
],
[
'title' => $row['title'],
'description' => $row['description'],
'sort' => $row['sort'],
'is_enabled' => true,
'scoring_sheet_json' => $sheet,
]
);
}
$this->command?->info(
1 month ago
'Synced '.count(self::ROWS)." tracks for competition #{$competition->id}."
5 months ago
);
}
}
}