shjFiveService = $shjFiveService; } /** * コンソールコマンドを実行 * * 処理フロー: * 1. バッチログ開始記録 * 2. 駐輪場の空き状況を取得する * 3. 空き状況判定 * 4. 空き待ち者の情報を取得する * 5. 取得件数判定 * 6. 空き待ち者への通知、またはオペレーターキュー追加処理 * 7. バッチ処理ログを作成する * 8. 処理結果返却 * * @return int */ public function handle() { $batchLog = null; try { // 開始ログ出力 $startTime = now(); $this->info('SHJ-5 空き待ち通知処理を開始します。'); Log::info('SHJ-5 空き待ち通知処理開始', [ 'start_time' => $startTime ]); // SHJ-8共通処理呼び出し - 仕様書準拠 $batchLog = BatchLog::createBatchLog( 'SHJ-5空き待ち通知処理', BatchLog::STATUS_START, [ 'device_id' => 1, // 仕様書:device_id=1 'process_code' => 1, // 仕様書:process_code=1 'status_comment' => '処理開始' // 仕様書:内部変数.ステータスコメント ], 'SHJ-5処理開始: 駐輪場空き状況確認と空き待ち通知処理' ); // SHJ-5メイン処理実行 $result = $this->shjFiveService->executeParkVacancyNotification(); $endTime = now(); $this->info('SHJ-5 空き待ち通知処理が完了しました。'); $this->info("処理時間: {$startTime->diffInSeconds($endTime)}秒"); // 処理結果表示 $this->displayProcessResult($result); // SHJ-8共通処理 - バッチログ完了記録(仕様書準拠) $logStatus = $result['success'] ? BatchLog::STATUS_SUCCESS : BatchLog::STATUS_ERROR; // 仕様書準拠:サービス側で作成した完全なステータスコメントを使用 $statusComment = $result['success'] ? ($result['status_comment'] ?? 'ステータスコメント生成エラー') : sprintf('処理失敗: %s', $result['message'] ?? 'エラー'); $batchLog->update([ 'status' => $logStatus, 'end_time' => $endTime, 'message' => $result['message'], 'parameters' => [ 'device_id' => 1, // 仕様書:device_id=1 'process_code' => 1, // 仕様書:process_code=1 'status_comment' => $statusComment, // 仕様書:内部変数.ステータスコメント(完全版) 'processed_parks_count' => $result['processed_parks_count'] ?? 0, 'vacant_parks_count' => $result['vacant_parks_count'] ?? 0, 'total_waiting_users' => $result['total_waiting_users'] ?? 0, 'notification_success_count' => $result['notification_success_count'] ?? 0, 'operator_queue_count' => $result['operator_queue_count'] ?? 0, 'error_count' => $result['error_count'] ?? 0, 'duration_seconds' => $result['duration_seconds'] ?? 0 ], 'execution_count' => 1, 'success_count' => $result['notification_success_count'] ?? 0, 'error_count' => $result['error_count'] ?? 0 ]); 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()); // SHJ-8共通処理 - エラーログ記録(仕様書準拠) if ($batchLog) { $statusComment = sprintf( 'メール正常終了件数:0/メール異常終了件数:1/キュー登録正常終了件数:0/キュー登録異常終了件数:1 - 処理エラー: %s', $e->getMessage() ); $batchLog->update([ 'status' => BatchLog::STATUS_ERROR, 'end_time' => now(), 'message' => 'SHJ-5処理中にエラーが発生: ' . $e->getMessage(), 'parameters' => [ 'device_id' => 1, // 仕様書:device_id=1 'process_code' => 1, // 仕様書:process_code=1 'status_comment' => $statusComment // 仕様書:内部変数.ステータスコメント(完全版) ], 'error_details' => $e->getMessage(), 'error_count' => 1 ]); } 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); } } } }