shjFourCService = $shjFourCService; } /** * コンソールコマンドを実行 * * 処理フロー: * 1. パラメータ取得と検証 * 2. ゾーン情報取得処理 * 3. 割当判定処理 * 4. バッチログ作成 * 5. 処理結果返却 * * @return int */ public function handle() { try { // 開始ログ出力 $startTime = now(); $this->info('SHJ-4C 室割当処理を開始します。'); Log::info('SHJ-4C 室割当処理開始', [ 'start_time' => $startTime, 'park_id' => $this->argument('park_id'), 'ptype_id' => $this->argument('ptype_id'), 'psection_id' => $this->argument('psection_id') ]); // 引数取得 $parkId = $this->argument('park_id'); $ptypeId = $this->argument('ptype_id'); $psectionId = $this->argument('psection_id'); // パラメータ検証 if (!$this->validateParameters($parkId, $ptypeId, $psectionId)) { $this->error('パラメータが不正です。'); return self::FAILURE; } // SHJ-4C処理実行 $result = $this->shjFourCService->executeRoomAllocation($parkId, $ptypeId, $psectionId); // 処理結果確認 if ($result['success']) { $endTime = now(); $this->info('SHJ-4C 室割当処理が正常に完了しました。'); $this->info("処理時間: {$startTime->diffInSeconds($endTime)}秒"); Log::info('SHJ-4C 室割当処理完了', [ 'end_time' => $endTime, 'duration_seconds' => $startTime->diffInSeconds($endTime), 'result' => $result ]); return self::SUCCESS; } else { $this->error('SHJ-4C 室割当処理でエラーが発生しました: ' . $result['message']); Log::error('SHJ-4C 室割当処理エラー', [ 'error' => $result['message'], 'details' => $result['details'] ?? null ]); return self::FAILURE; } } catch (\Exception $e) { $this->error('SHJ-4C 室割当処理で予期しないエラーが発生しました: ' . $e->getMessage()); Log::error('SHJ-4C 室割当処理例外エラー', [ 'exception' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return self::FAILURE; } } /** * パラメータの妥当性を検証 * * @param mixed $parkId 駐輪場ID * @param mixed $ptypeId 駐輪分類ID * @param mixed $psectionId 車種区分ID * @return bool 検証結果 */ private function validateParameters($parkId, $ptypeId, $psectionId): bool { // 必須パラメータチェック if (empty($parkId) || empty($ptypeId) || empty($psectionId)) { $this->error('全てのパラメータは必須です。'); return false; } // 数値形式チェック if (!is_numeric($parkId) || !is_numeric($ptypeId) || !is_numeric($psectionId)) { $this->error('全てのパラメータは数値である必要があります。'); return false; } // 正の整数チェック if ($parkId <= 0 || $ptypeId <= 0 || $psectionId <= 0) { $this->error('全てのパラメータは正の整数である必要があります。'); return false; } return true; } }