diff --git a/app/Jobs/ImportSongChunkJob.php b/app/Jobs/ImportSongChunkJob.php index 5f6d258..6810508 100644 --- a/app/Jobs/ImportSongChunkJob.php +++ b/app/Jobs/ImportSongChunkJob.php @@ -22,6 +22,7 @@ class ImportSongChunkJob implements ShouldQueue protected Collection $rows; protected array $categoryMap = []; + protected array $artistCache =[]; public function __construct(Collection $rows) { @@ -99,7 +100,19 @@ class ImportSongChunkJob implements ShouldQueue } } } + private function getOrCreateArtistId(string $name): int + { + if (isset($this->artistCache[$name])) { + return $this->artistCache[$name]; + } + $artist = Artist::firstOrCreate( + ['name' => $name], + ['category' => ArtistCategory::Unset] + ); + + return $this->artistCache[$name] = $artist->id; + } private function parseExcelDate($value): ?string { if (is_numeric($value)) { diff --git a/app/Models/Song.php b/app/Models/Song.php index 50a3319..a3a3258 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -13,6 +13,7 @@ class Song extends Model use HasFactory; protected $fillable = [ + 'id', 'name', 'adddate', 'filename', diff --git a/database/migrations/2025_04_23_031625_create_artists_table.php b/database/migrations/2025_04_23_031625_create_artists_table.php index 5777a35..cd73351 100644 --- a/database/migrations/2025_04_23_031625_create_artists_table.php +++ b/database/migrations/2025_04_23_031625_create_artists_table.php @@ -13,12 +13,12 @@ return new class extends Migration { Schema::create('artists', function (Blueprint $table) { $table->bigIncrements('id'); - $table->enum('category', ['未定義','男', '女','團','外', '其他'])->default('未定義')->comment('歌星類別'); - $table->string('name')->comment('歌星名稱'); - $table->string('simplified')->comment('歌星簡體'); - $table->string('phonetic_abbr')->comment('歌星注音'); - $table->string('pinyin_abbr')->comment('歌星拼音'); - $table->integer('strokes_abbr')->comment('歌星筆劃'); + $table->enum('category', ['未定義','男', '女','團','外', '其他'])->default('未定義')->index()->comment('歌星類別'); + $table->string('name')->unique()->comment('歌星名稱'); + $table->string('simplified')->index()->comment('歌星簡體'); + $table->string('phonetic_abbr')->index()->comment('歌星注音'); + $table->string('pinyin_abbr')->index()->comment('歌星拼音'); + $table->integer('strokes_abbr')->index()->comment('歌星筆劃'); $table->tinyInteger('enable')->default(1)->comment('狀態'); // 1,可看,0,不可看 $table->timestamps(); }); diff --git a/database/migrations/2025_04_23_031630_create_songs_table.php b/database/migrations/2025_04_23_031630_create_songs_table.php index 2ae2a76..cb084b6 100644 --- a/database/migrations/2025_04_23_031630_create_songs_table.php +++ b/database/migrations/2025_04_23_031630_create_songs_table.php @@ -13,13 +13,13 @@ return new class extends Migration { Schema::create('songs', function (Blueprint $table) { $table->bigIncrements('id')->comment('歌曲編號'); - $table->text('name')->nullable()->comment('歌曲檔名'); - $table->string('filename')->comment('歌曲檔名'); - $table->date('adddate')->comment('新增日期'); - $table->enum('language_type', ['未定義','國語','台語','英語','日語','粵語','韓語','越語','客語','其他'])->default('未定義')->comment('語別'); - $table->integer('db_change')->default(0)->comment('DB加減'); - $table->tinyInteger('vocal')->comment('人聲'); // 0,1 - $table->enum('situation', ['未定義','浪漫', '柔和','動感','明亮'])->default('未定義')->comment('情境'); + $table->string('name')->nullable()->index()->comment('歌曲檔名'); + $table->string('filename')->index()->comment('歌曲檔名'); + $table->date('adddate')->index()->comment('新增日期'); + $table->enum('language_type', ['未定義','國語','台語','英語','日語','粵語','韓語','越語','客語','其他'])->default('未定義')->index()->comment('語別'); + $table->integer('db_change')->default(0)->index()->comment('DB加減'); + $table->tinyInteger('vocal')->index()->comment('人聲'); // 0,1 + $table->enum('situation', ['未定義','浪漫', '柔和','動感','明亮'])->default('未定義')->index()->comment('情境'); $table->string('copyright01')->nullable()->comment('版權01'); $table->string('copyright02')->nullable()->comment('版權02'); $table->string('note01')->nullable()->comment('備註01'); @@ -27,12 +27,12 @@ return new class extends Migration $table->string('note03')->nullable()->comment('備註03'); $table->string('note04')->nullable()->comment('備註04'); $table->tinyInteger('enable')->default(1)->comment('狀態'); // 1,可看,0,不可看 - $table->string('simplified')->comment('歌曲簡體'); - $table->string('phonetic_abbr')->comment('歌曲注音'); - $table->string('pinyin_abbr')->comment('歌曲拼音'); - $table->integer('strokes_abbr')->default(0)->comment('歌曲筆劃'); - $table->integer('song_number')->default(0)->comment('歌曲字數'); - $table->integer('song_counts')->default(0)->comment('點播次數'); + $table->string('simplified')->index()->comment('歌曲簡體'); + $table->string('phonetic_abbr')->index()->comment('歌曲注音'); + $table->string('pinyin_abbr')->index()->comment('歌曲拼音'); + $table->integer('strokes_abbr')->default(0)->index()->comment('歌曲筆劃'); + $table->integer('song_number')->default(0)->index()->comment('歌曲字數'); + $table->integer('song_counts')->default(0)->index()->comment('點播次數'); $table->timestamps(); }); } diff --git a/database/migrations/2025_04_24_031630_create_songs_table.php b/database/migrations/2025_04_24_031630_create_song_library_cache_table.php similarity index 100% rename from database/migrations/2025_04_24_031630_create_songs_table.php rename to database/migrations/2025_04_24_031630_create_song_library_cache_table.php diff --git a/resources/views/livewire/admin/artist-import-data.blade.php b/resources/views/livewire/admin/artist-import-data.blade.php index 2d4cf55..a138377 100644 --- a/resources/views/livewire/admin/artist-import-data.blade.php +++ b/resources/views/livewire/admin/artist-import-data.blade.php @@ -48,6 +48,15 @@ {{-- 檔案上傳 --}} + +
+ 檔案上傳中,請稍候... +
+ + +
+ +
diff --git a/resources/views/livewire/admin/song-import-data.blade.php b/resources/views/livewire/admin/song-import-data.blade.php index 6583108..b268851 100644 --- a/resources/views/livewire/admin/song-import-data.blade.php +++ b/resources/views/livewire/admin/song-import-data.blade.php @@ -144,7 +144,15 @@
{{-- 檔案上傳 --}} - + +
+ 檔案上傳中,請稍候... +
+ + +
+ +