shjEightService = $shjEightService; } /** * コンソールコマンドを実行 * * 処理フロー: * 1. ShjEightServiceを呼び出して処理を実行 * 2. 処理結果を返却する * * @return int */ public function handle() { try { // 開始ログ出力 $startTime = now(); $this->info('SHJ-8 バッチ処理ログ登録を開始します。'); // 引数取得 $deviceId = (int) $this->argument('device_id'); $processName = $this->argument('process_name'); $jobName = $this->argument('job_name'); $status = $this->argument('status'); $statusComment = $this->argument('status_comment'); $createdDate = $this->argument('created_date'); $updatedDate = $this->argument('updated_date'); Log::info('SHJ-8 バッチ処理ログ登録開始', [ 'start_time' => $startTime, 'device_id' => $deviceId, 'process_name' => $processName, 'job_name' => $jobName, 'status' => $status, 'status_comment' => $statusComment, 'created_date' => $createdDate, 'updated_date' => $updatedDate ]); // ShjEightServiceを呼び出して処理を実行 $result = $this->shjEightService->execute( $deviceId, $processName, $jobName, $status, $statusComment, $createdDate, $updatedDate ); $endTime = now(); // 処理結果に応じた出力 if ($result['result'] === 0) { // 正常終了 $this->info('SHJ-8 バッチ処理ログ登録が正常に完了しました。'); $this->info("処理時間: {$startTime->diffInSeconds($endTime)}秒"); // 標準出力形式 (SHJ-8仕様書準拠) $this->line('処理結果: 0'); $this->line('異常情報: '); Log::info('SHJ-8 バッチ処理ログ登録完了', [ 'end_time' => $endTime, 'duration_seconds' => $startTime->diffInSeconds($endTime) ]); return self::SUCCESS; } else { // 異常終了 $errorMessage = $result['error_message'] ?? '不明なエラー'; $this->error('SHJ-8 バッチ処理ログ登録エラー: ' . $errorMessage); // 標準出力形式 (SHJ-8仕様書準拠) $this->line('処理結果: 1'); $this->line('異常情報: ' . $errorMessage); Log::error('SHJ-8 バッチ処理ログ登録エラー', [ 'error_message' => $errorMessage, 'error_code' => $result['error_code'] ?? null ]); return self::FAILURE; } } catch (\Exception $e) { $this->error('SHJ-8 バッチ処理ログ登録で予期しないエラーが発生しました: ' . $e->getMessage()); // 標準出力形式 (SHJ-8仕様書準拠 - 例外時) $this->line('処理結果: 1'); $this->line('異常情報: ' . $e->getMessage()); Log::error('SHJ-8 バッチ処理ログ登録例外エラー', [ 'exception' => $e->getMessage(), 'trace' => $e->getTraceAsString() ]); return self::FAILURE; } } }