db = \Config\Database::connect(); $this->naverClient = new NaverApiClient(); $this->rawStagingModel = new NaverRawStagingModel(); $this->typeSHandler = new TypeSHandler(); $this->typeV2Handler = new TypeV2Handler(); helper('log'); } /** * 메인 프로세스: 네이버 API 호출 및 타입별 처리 * * @param array $payload 요청 페이로드 (articleNumber, requestType 등) * @return int 처리된 ID (rcpt_sq 또는 vr_sq) * @throws Exception */ public function processArticle(array $payload): int { $articleNumber = $payload['articleNumber']; $requestType = $payload['requestType'] ?? ''; CLI::write(CLI::color('🟢 getArticleInfo Start :: ' . $articleNumber, 'green')); try { // 1. 네이버 API 호출 $response = $this->naverClient->getArticleInfo($articleNumber); if (!$response || $response['code'] !== 'success') { throw new Exception("네이버 API 응답 에러: $articleNumber"); } $rawData = $response['data']; $vType = $rawData['verificationTypeCode'] ?? ''; // 2. 원본 데이터 Staging 저장 $this->rawStagingModel->insert([ 'atcl_no' => $articleNumber, 'verification_type' => $vType, 'request_type' => $requestType, 'raw_json' => $rawData ]); CLI::write(CLI::color('🟢 임시테이블 저장 완료', 'green')); // 3. 타입별 분기 처리 if ($vType === 'S') { return $this->typeSHandler->handle($articleNumber, $rawData, $payload); } else { return $this->typeV2Handler->handle($articleNumber, $rawData, $payload); } } catch (Exception $e) { write_custom_log("processArticle 실패: " . $e->getMessage(), 'ERROR', 'service'); throw $e; } } }