where('tenant_id', $tenantId) ->where('name', 'AI 관리') ->whereNull('parent_id') ->whereNull('deleted_at') ->first(); if (! $aiGroup) { $aiGroup = Menu::withoutGlobalScopes()->create([ 'tenant_id' => $tenantId, 'parent_id' => null, 'name' => 'AI 관리', 'url' => null, 'icon' => 'brain-circuit', 'sort_order' => 12, 'is_active' => true, ]); $this->command->info("AI 관리 부모 그룹 생성 완료 (id: {$aiGroup->id})"); } else { $this->command->info("AI 관리 부모 그룹 이미 존재 (id: {$aiGroup->id})"); } // 2. AI 설정 메뉴를 AI 관리 그룹으로 이동 (다른 그룹에 있는 경우) $aiConfig = Menu::withoutGlobalScopes() ->where('tenant_id', $tenantId) ->where('name', 'AI 설정') ->whereNull('deleted_at') ->first(); if ($aiConfig && $aiConfig->parent_id !== $aiGroup->id) { $aiConfig->update([ 'parent_id' => $aiGroup->id, 'sort_order' => 1, ]); $this->command->info('AI 설정 메뉴를 AI 관리 그룹으로 이동 완료'); } elseif (! $aiConfig) { $this->command->warn('AI 설정 메뉴가 존재하지 않습니다. (건너뜀)'); } else { $this->command->info('AI 설정 메뉴가 이미 AI 관리 그룹에 있습니다.'); } // 3. AI 토큰 사용량 메뉴 생성 또는 이동 $aiToken = Menu::withoutGlobalScopes() ->where('tenant_id', $tenantId) ->where('name', 'AI 토큰 사용량') ->whereNull('deleted_at') ->first(); if ($aiToken && $aiToken->parent_id !== $aiGroup->id) { $aiToken->update([ 'parent_id' => $aiGroup->id, 'sort_order' => 2, ]); $this->command->info('AI 토큰 사용량 메뉴를 AI 관리 그룹으로 이동 완료'); } elseif (! $aiToken) { Menu::withoutGlobalScopes()->create([ 'tenant_id' => $tenantId, 'parent_id' => $aiGroup->id, 'name' => 'AI 토큰 사용량', 'url' => '/system/ai-token-usage', 'icon' => 'brain-circuit', 'sort_order' => 2, 'is_active' => true, ]); $this->command->info('AI 토큰 사용량 메뉴 생성 완료'); } else { $this->command->info('AI 토큰 사용량 메뉴가 이미 AI 관리 그룹에 있습니다.'); } // 4. AI 음성녹음 메뉴 생성 또는 이동 $aiVoice = Menu::withoutGlobalScopes() ->where('tenant_id', $tenantId) ->where('name', 'AI 음성녹음') ->whereNull('deleted_at') ->first(); if ($aiVoice && $aiVoice->parent_id !== $aiGroup->id) { $aiVoice->update([ 'parent_id' => $aiGroup->id, 'sort_order' => 3, ]); $this->command->info('AI 음성녹음 메뉴를 AI 관리 그룹으로 이동 완료'); } elseif (! $aiVoice) { Menu::withoutGlobalScopes()->create([ 'tenant_id' => $tenantId, 'parent_id' => $aiGroup->id, 'name' => 'AI 음성녹음', 'url' => '/system/ai-voice-recording', 'icon' => 'mic', 'sort_order' => 3, 'is_active' => true, ]); $this->command->info('AI 음성녹음 메뉴 생성 완료'); } else { $this->command->info('AI 음성녹음 메뉴가 이미 AI 관리 그룹에 있습니다.'); } // 결과 출력 $this->command->info(''); $this->command->info('=== AI 관리 하위 메뉴 ==='); $children = Menu::withoutGlobalScopes() ->where('parent_id', $aiGroup->id) ->whereNull('deleted_at') ->orderBy('sort_order') ->get(['name', 'url', 'sort_order']); foreach ($children as $child) { $this->command->info("{$child->sort_order}. {$child->name} ({$child->url})"); } } }