shjFiveService = $shjFiveService; } /** * コンソールコマンドを実行 * * 処理フロー: * 1. バッチログ開始記録 * 2. 駐輪場の空き状況を取得する * 3. 空き状況判定 * 4. 空き待ち者の情報を取得する * 5. 取得件数判定 * 6. 空き待ち者への通知、またはオペレーターキュー追加処理 * 7. バッチ処理ログを作成する * 8. 処理結果返却 * * @return int */ public function handle() { try { // 開始ログ出力 $startTime = now(); $this->info('SHJ-5 空き待ち通知処理を開始します。'); Log::info('SHJ-5 空き待ち通知処理開始', [ 'start_time' => $startTime ]); // SHJ-5メイン処理実行 $result = $this->shjFiveService->executeParkVacancyNotification(); $endTime = now(); $this->info('SHJ-5 空き待ち通知処理が完了しました。'); $this->info("処理時間: {$startTime->diffInSeconds($endTime)}秒"); // 処理結果表示 $this->displayProcessResult($result); // バッチログはShjFiveServiceが自動的にSHJ-8経由で作成 Log::info('SHJ-5 空き待ち通知処理完了', [ 'end_time' => $endTime, 'duration_seconds' => $startTime->diffInSeconds($endTime), 'result' => $result ]); return $result['success'] ? self::SUCCESS : self::FAILURE; } catch (\Exception $e) { $this->error('SHJ-5 空き待ち通知処理で予期しないエラーが発生しました: ' . $e->getMessage()); // エラー時もShjFiveServiceが自動的にバッチログを作成 Log::error('SHJ-5 空き待ち通知処理例外エラー', [ 'exception' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return self::FAILURE; } } /** * 処理結果を表示 * * @param array $result 処理結果 * @return void */ private function displayProcessResult(array $result): void { $this->line(''); $this->info('=== 処理結果 ==='); if ($result['success']) { $this->info("✓ 処理実行成功: " . $result['message']); } else { $this->error("✗ 処理実行失敗: " . $result['message']); } $this->line(''); $this->info('=== 処理統計 ==='); $this->line(" 処理対象駐輪場数: " . ($result['processed_parks_count'] ?? 0)); $this->line(" 空きあり駐輪場数: " . ($result['vacant_parks_count'] ?? 0)); $this->line(" 空き待ち者総数: " . ($result['total_waiting_users'] ?? 0)); $this->line(" 通知送信成功: " . ($result['notification_success_count'] ?? 0) . "件"); $this->line(" オペレーターキュー追加: " . ($result['operator_queue_count'] ?? 0) . "件"); $this->line(" エラー件数: " . ($result['error_count'] ?? 0) . "件"); $this->line(" 処理時間: " . ($result['duration_seconds'] ?? 0) . "秒"); // エラー詳細があれば表示 if (!empty($result['errors'])) { $this->line(''); $this->warn('=== エラー詳細 ==='); foreach ($result['errors'] as $index => $error) { $this->line(" " . ($index + 1) . ". " . $error); } } } }