刪除舊程式的DB 與相關功能 20250512
This commit is contained in:
parent
d61eee5d91
commit
b0325aef79
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire\Admin;
|
||||
|
||||
use App\Models\Rooms;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use PowerComponents\LivewirePowerGrid\Button;
|
||||
use PowerComponents\LivewirePowerGrid\Column;
|
||||
use PowerComponents\LivewirePowerGrid\Facades\Filter;
|
||||
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
|
||||
use PowerComponents\LivewirePowerGrid\PowerGridFields;
|
||||
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
|
||||
|
||||
final class RoomsTable extends PowerGridComponent
|
||||
{
|
||||
public string $tableName = 'rooms-table-tsjlhj-table';
|
||||
|
||||
public function setUp(): array
|
||||
{
|
||||
$this->showCheckBox();
|
||||
|
||||
return [
|
||||
PowerGrid::header()
|
||||
->showSearchInput(),
|
||||
PowerGrid::footer()
|
||||
->showPerPage()
|
||||
->showRecordCount(),
|
||||
];
|
||||
}
|
||||
|
||||
public function datasource(): Builder
|
||||
{
|
||||
return Rooms::query();
|
||||
}
|
||||
|
||||
public function relationSearch(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function fields(): PowerGridFields
|
||||
{
|
||||
return PowerGrid::fields()
|
||||
->add('id')
|
||||
->add('branch_id')
|
||||
->add('name')
|
||||
->add('internal_ip')
|
||||
->add('port')
|
||||
->add('status')
|
||||
->add('started_at_formatted', fn (Rooms $model) => Carbon::parse($model->started_at)->format('d/m/Y H:i:s'))
|
||||
->add('ended_at_formatted', fn (Rooms $model) => Carbon::parse($model->ended_at)->format('d/m/Y H:i:s'))
|
||||
->add('created_at_formatted', fn (Rooms $model) => Carbon::parse($model->created_at)->format('d/m/Y H:i:s'));
|
||||
}
|
||||
|
||||
public function columns(): array
|
||||
{
|
||||
return [
|
||||
Column::make('Id', 'id'),
|
||||
Column::make('Branch id', 'branch_id'),
|
||||
Column::make('Name', 'name')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
Column::make('Internal ip', 'internal_ip')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
Column::make('Port', 'port'),
|
||||
Column::make('Status', 'status')
|
||||
->sortable()
|
||||
->searchable(),
|
||||
|
||||
Column::make('Started at', 'started_at_formatted', 'started_at')
|
||||
->sortable(),
|
||||
|
||||
Column::make('Ended at', 'ended_at_formatted', 'ended_at')
|
||||
->sortable(),
|
||||
|
||||
Column::make('Created at', 'created_at_formatted', 'created_at')
|
||||
->sortable(),
|
||||
|
||||
Column::action('Action')
|
||||
];
|
||||
}
|
||||
|
||||
public function filters(): array
|
||||
{
|
||||
return [
|
||||
Filter::datetimepicker('started_at'),
|
||||
Filter::datetimepicker('ended_at'),
|
||||
Filter::datetimepicker('created_at'),
|
||||
];
|
||||
}
|
||||
|
||||
#[\Livewire\Attributes\On('edit')]
|
||||
public function edit($rowId): void
|
||||
{
|
||||
$this->js('alert('.$rowId.')');
|
||||
}
|
||||
|
||||
public function actions(Rooms $row): array
|
||||
{
|
||||
return [
|
||||
Button::add('edit')
|
||||
->slot('Edit: '.$row->id)
|
||||
->id()
|
||||
->class('pg-btn-white dark:ring-pg-primary-600 dark:border-pg-primary-600 dark:hover:bg-pg-primary-700 dark:ring-offset-pg-primary-800 dark:text-pg-primary-300 dark:bg-pg-primary-700')
|
||||
->dispatch('edit', ['rowId' => $row->id])
|
||||
];
|
||||
}
|
||||
|
||||
/*
|
||||
public function actionRules($row): array
|
||||
{
|
||||
return [
|
||||
// Hide button edit for ID 1
|
||||
Rule::button('edit')
|
||||
->when(fn($row) => $row->id === 1)
|
||||
->hide(),
|
||||
];
|
||||
}
|
||||
*/
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class SongLibrary extends Model
|
||||
{ /** @use HasFactory<\Database\Factories\SongLanguageFactory> */
|
||||
use HasFactory;
|
||||
|
||||
// 指定使用的資料庫連線(SQLite)
|
||||
protected $connection = 'KTVsqlite';
|
||||
|
||||
// 指定表格名稱(如果不符合 Laravel 預設的複數形式,可手動指定)
|
||||
protected $table = 'SongLibrary';
|
||||
|
||||
// 設定主鍵欄位(如果不是 'id',例如這裡是 '歌曲編號')
|
||||
protected $primaryKey = '歌曲編號';
|
||||
|
||||
// 如果你的主鍵不是整數型別(如 `BIGINT`),需要指定
|
||||
public $incrementing = false; // 因為 '歌曲編號' 不是自動遞增的
|
||||
|
||||
// 如果你不需要用預設的時間戳記 (created_at, updated_at),可以設定如下:
|
||||
public $timestamps = false;
|
||||
|
||||
// 你可以指定哪些欄位是可以批量賦值的(防止批量賦值漏洞)
|
||||
protected $fillable = [
|
||||
'歌曲編號', '歌曲名稱', '歌星 A', '歌星 B', '路徑 1', '路徑 2', '歌曲檔名', '新增日期', '分類', '歌曲注音',
|
||||
'歌曲拼音', '語別', '點播次數', '版權01', '版權02', '版權03', '版權04', '版權05', '版權06', '狀態',
|
||||
'DB加減', 'Unnamed: 21', '歌名字數', '人聲', '狀態2', '情境', '歌星A注音', '歌星B注音', '歌星A分類',
|
||||
'歌星B分類', '歌星A簡體', '歌星B簡體', '歌名簡體', '歌星A拼音', '歌星B拼音'
|
||||
];
|
||||
|
||||
|
||||
}
|
Binary file not shown.
@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\SongLibrary;
|
||||
use App\Models\Song;
|
||||
use App\Models\Artist;
|
||||
use App\Enums\ArtistCategory;
|
||||
use App\Enums\SongLanguageType;
|
||||
use App\Enums\SongSituation;
|
||||
|
||||
class SqliteToMysqlSeeder extends Seeder
|
||||
{
|
||||
public function run(): void
|
||||
{
|
||||
$SongCategoryMap = \App\Models\SongCategory::pluck('id', 'code')->toArray();
|
||||
|
||||
$artistCache = [];
|
||||
$chunkSize = 100;
|
||||
$totalCount = 0;//51912
|
||||
SongLibrary::where('歌曲編號', '>', 0)->chunk($chunkSize, function ($songs) use ( $SongCategoryMap, &$artistCache, &$totalCount) {
|
||||
$songsToInsert = [];
|
||||
$pivotArtist = [];
|
||||
$pivotCategory = [];
|
||||
|
||||
foreach ($songs as $data) {
|
||||
$totalCount++; // 這裡計數
|
||||
$songId = $data->{'歌曲編號'};
|
||||
$artistAId = null;
|
||||
$artistBId = null;
|
||||
|
||||
// 處理 Artist A
|
||||
if (!empty($data->{'歌星 A'})) {
|
||||
$key = $data->{'歌星 A'} . '|' . ($data->{'歌星A分類'} ?? '未定義');
|
||||
if (!isset($artistCache[$key])) {
|
||||
|
||||
|
||||
$artist = Artist::firstOrCreate([
|
||||
'name' => $data->{'歌星 A'},
|
||||
'category' => ArtistCategory::tryFrom(trim($data->{'歌星A分類'} ?? '未定義')) ?? ArtistCategory::Unset,
|
||||
//'simplified' => $data->{'歌星A簡體'} ?? '',
|
||||
//'phonetic_abbr' => $data->{'歌星A注音'} ?? '',
|
||||
//'pinyin_abbr' => $data->{'歌星A拼音'} ?? '',
|
||||
//'strokes_abbr' =>
|
||||
]);
|
||||
$artistCache[$key] = $artist->id;
|
||||
}
|
||||
$artistAId = $artistCache[$key];
|
||||
}
|
||||
|
||||
// 處理 Artist B
|
||||
if (!empty($data->{'歌星 B'})) {
|
||||
$key = $data->{'歌星 B'} . '|' . ($data->{'歌星B分類'} ?? '未定義');
|
||||
if (!isset($artistCache[$key])) {
|
||||
$artist = Artist::firstOrCreate([
|
||||
'name' => $data->{'歌星 B'},
|
||||
'category' => ArtistCategory::tryFrom(trim($data->{'歌星B分類'} ?? '未定義')) ?? ArtistCategory::Unset,
|
||||
//'simplified' => $data->{'歌星B簡體'} ?? '',
|
||||
//'phonetic_abbr' => $data->{'歌星B注音'} ?? '',
|
||||
//'pinyin_abbr' => $data->{'歌星B拼音'} ?? '',
|
||||
//'strokes_abbr'
|
||||
]);
|
||||
$artistCache[$key] = $artist->id;
|
||||
}
|
||||
$artistBId = $artistCache[$key];
|
||||
}
|
||||
// 處理 Song 資料
|
||||
$songsToInsert[] = [
|
||||
'id' => $songId,
|
||||
'name' => $data->{'歌曲名稱'},
|
||||
'adddate' => $data->{'新增日期'},
|
||||
'filename' => $data->{'歌曲檔名'},
|
||||
'language_type' => SongLanguageType::tryFrom(trim($data->{'語別'} ?? '未定義')) ?? SongLanguageType::Unset,
|
||||
'db_change' => $data->{'DB加減'} ?? 0,
|
||||
'vocal' => $data->{'人聲'},
|
||||
'situation' => SongSituation::tryFrom(trim($data->{'情境'} ?? '未定義')) ?? SongSituation::Unset,
|
||||
'copyright01' => $data->{'版權01'},
|
||||
'copyright02' => $data->{'版權02'},
|
||||
'note01' => $data->{'版權03'},
|
||||
'note02' => $data->{'版權04'},
|
||||
'note03' => $data->{'版權05'},
|
||||
'note04' => $data->{'版權06'},
|
||||
'enable' => $data->{'狀態'},
|
||||
'simplified' => $data->{'歌名簡體'} ?? '',
|
||||
'phonetic_abbr' => $data->{'歌曲注音'} ?? '',
|
||||
'pinyin_abbr' => $data->{'歌曲拼音'} ?? '',
|
||||
'strokes_abbr' => $data->{'Unnamed: 21'} ?? 0,
|
||||
];
|
||||
|
||||
if ($artistAId) $pivotArtist[] = ['song_id' => $songId, 'artist_id' => $artistAId];
|
||||
if ($artistBId) $pivotArtist[] = ['song_id' => $songId, 'artist_id' => $artistBId];
|
||||
|
||||
// 處理分類
|
||||
|
||||
if (!empty($data->{'分類'})) {
|
||||
$categoryCodes = explode(',', $data->{'分類'});
|
||||
$addedCategoryIds = [];
|
||||
foreach ($categoryCodes as $code) {
|
||||
$code = trim($code);
|
||||
if (isset($SongCategoryMap[$code])) {
|
||||
$categoryId = $SongCategoryMap[$code];
|
||||
if (!in_array($categoryId, $addedCategoryIds)) {
|
||||
$pivotCategory[] = [
|
||||
'song_id' => $songId,
|
||||
'song_category_id' => $SongCategoryMap[$code]
|
||||
];
|
||||
$addedCategoryIds[] = $categoryId;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Song::insert($songsToInsert);
|
||||
DB::table('artist_song')->insert($pivotArtist);
|
||||
DB::table('song_song_category')->insert($pivotCategory);
|
||||
|
||||
$this->command->info("目前累計處理 {$totalCount} 筆歌曲資料");
|
||||
});
|
||||
$this->command->info("全部完成,共處理 {$totalCount} 筆歌曲資料。");
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user