shjOneService = $shjOneService; } /** * Execute the console command. */ public function handle() { $startTime = now(); $processName = config('shj1.batch_log.process_name'); // 【処理0】パラメーターを取得する $userId = $this->argument('user_id'); $parkId = $this->argument('park_id'); $parameters = [ 'user_id' => $userId, 'park_id' => $parkId ]; $this->info("=== SHJ-1 本人確認自動処理 開始 ==="); $this->info("利用者ID: {$userId}"); $this->info("駐輪場ID: {$parkId}"); try { // バッチログ開始 - SHJ-8共通処理 $batchLog = BatchLog::createBatchLog( 'SHJ-1本人確認自動処理', BatchLog::STATUS_START, $parameters, 'SHJ-1処理開始: 利用者ID=' . $userId . ', 駐輪場ID=' . $parkId ); // SHJ-1 メイン処理を実行 $result = $this->shjOneService->execute($userId, $parkId); // 処理結果の表示 $this->displayResult($result); // バッチログ完了 - 実際の処理結果に基づく $logStatus = $result['log_status'] ?? ($result['system_success'] ? BatchLog::STATUS_SUCCESS : BatchLog::STATUS_ERROR); $batchLog->update([ 'status' => $logStatus, 'end_time' => now(), 'message' => $result['message'], 'success_count' => $result['stats']['success_count'] ?? 0, 'error_count' => $result['stats']['error_count'] ?? 0, 'execution_count' => $result['stats']['processed_count'] ?? 1 ]); $this->info("=== SHJ-1 本人確認自動処理 完了 ==="); // システムエラーまたは身元確認失敗の場合は exit code 1 $isSuccess = $result['system_success'] && ($result['identity_result'] ?? '') === 'OK'; return $isSuccess ? 0 : 1; } catch (Exception $e) { $this->error("SHJ-1処理中にエラーが発生しました: " . $e->getMessage()); // エラーログ記録 if (isset($batchLog)) { $batchLog->update([ 'status' => BatchLog::STATUS_ERROR, 'end_time' => now(), 'message' => $e->getMessage(), 'error_details' => $e->getMessage(), 'error_count' => 1 ]); } return 1; } } /** * 処理結果を表示 */ private function displayResult(array $result): void { $this->line(''); $this->info('=== 処理結果 ==='); if ($result['system_success']) { $this->info("✓ 処理実行成功: " . $result['message']); if (isset($result['identity_result'])) { $identityStatus = $result['identity_result'] === 'OK' ? '✓ 本人確認OK' : '✗ 本人確認NG'; $this->line(" 本人確認結果: " . $identityStatus); } } else { $this->error("✗ 処理実行失敗: " . $result['message']); } if (isset($result['details'])) { foreach ($result['details'] as $key => $value) { $this->line(" {$key}: {$value}"); } } if (isset($result['stats'])) { $this->line(''); $this->info('=== 統計情報 ==='); foreach ($result['stats'] as $key => $value) { $this->line(" {$key}: {$value}"); } } } }