diff --git a/app/Helpers/log_helper.php b/app/Helpers/log_helper.php index b054581..c5cac8c 100644 --- a/app/Helpers/log_helper.php +++ b/app/Helpers/log_helper.php @@ -6,7 +6,7 @@ if (! function_exists('write_custom_log')) { */ function write_custom_log($message, $level = 'INFO', $type = 'service') { - $logDir = WRITEPATH . 'logs/worker'; + $logDir = WRITEPATH . 'logs'; if (!is_dir($logDir)) { @mkdir($logDir, 0777, true); } @@ -31,8 +31,8 @@ if (! function_exists('write_custom_log')) { } // ---------------------------- - $suffix = ($type === 'failed') ? '_failed' : ''; - $logFile = $logDir . '/' . date('Y-m-d') . $suffix . '.log'; + $suffix = ($type === 'failed') ? '-failed' : ''; + $logFile = $logDir . '/log-' . date('Y-m-d') . $suffix . '.log'; $timestamp = date('Y-m-d H:i:s'); $singleLine = str_replace(["\r", "\n", "\t"], " ", $message); diff --git a/app/Services/Handlers/TypeV2Handler.php b/app/Services/Handlers/TypeV2Handler.php index 8e2aca7..9ec0ee8 100644 --- a/app/Services/Handlers/TypeV2Handler.php +++ b/app/Services/Handlers/TypeV2Handler.php @@ -46,9 +46,11 @@ class TypeV2Handler public function handle(string $articleNumber, array $rawData, array $payload): int { CLI::write(CLI::color('🟒 Type V2 처리 μ‹œμž‘ :: ' . $articleNumber, 'green')); + write_custom_log("TypeV2Handler μ§„μž… | Atcl: $articleNumber | Payload: " . json_encode($payload), 'INFO', 'service'); try { $requestType = $payload['requestType'] ?? 'REG'; + CLI::write(CLI::color("πŸ”΅ RequestType: $requestType", 'cyan')); switch ($requestType) { case 'REG': @@ -62,7 +64,9 @@ class TypeV2Handler } } catch (Exception $e) { - write_custom_log("Type V2 처리 μ‹€νŒ¨: " . $e->getMessage(), 'ERROR', 'service'); + $errorDetail = "Type V2 처리 μ‹€νŒ¨ | Atcl: $articleNumber | Error: " . $e->getMessage() . " | File: " . $e->getFile() . ":" . $e->getLine(); + write_custom_log($errorDetail, 'ERROR', 'service'); + CLI::write(CLI::color("❌ " . $errorDetail, 'red')); throw $e; } } @@ -136,7 +140,9 @@ class TypeV2Handler // κΈ°μ‘΄ 검증 μš”μ²­ 확인 $existing = $this->vrfcReqModel->where('atcl_no', $articleNumber)->first(); if (!$existing) { - throw new Exception("μˆ˜μ •ν•  κΈ°μ‘΄ 데이터가 μ—†μŠ΅λ‹ˆλ‹€. Atcl: $articleNumber"); + CLI::write(CLI::color("⚠️ μˆ˜μ •ν•  κΈ°μ‘΄ 데이터가 μ—†μŒ β†’ μ‹ κ·œ λ“±λ‘μœΌλ‘œ μ „ν™˜ (Atcl: $articleNumber)", 'yellow')); + write_custom_log("MOD β†’ REG μžλ™ μ „ν™˜ | Atcl: $articleNumber | μ‚¬μœ : κΈ°μ‘΄ 데이터 μ—†μŒ", 'WARNING', 'service'); + return $this->handleRegister($articleNumber, $rawData, $payload); } $vrSq = $existing['vr_sq']; $stat_cd = $existing['stat_cd']; @@ -199,7 +205,9 @@ class TypeV2Handler // κΈ°μ‘΄ 검증 μš”μ²­ 확인 $existing = $this->vrfcReqModel->where('atcl_no', $articleNumber)->first(); if (!$existing) { - throw new Exception("μ·¨μ†Œν•  κΈ°μ‘΄ 데이터가 μ—†μŠ΅λ‹ˆλ‹€. Atcl: $articleNumber"); + CLI::write(CLI::color("⚠️ μ·¨μ†Œν•  데이터가 μ—†μŒ β†’ λ¬΄μ‹œ (Atcl: $articleNumber)", 'yellow')); + write_custom_log("CNC λ¬΄μ‹œ | Atcl: $articleNumber | μ‚¬μœ : κΈ°μ‘΄ 데이터 μ—†μŒ", 'WARNING', 'service'); + return 0; // μ·¨μ†Œν•  데이터가 μ—†μœΌλ―€λ‘œ 0 λ°˜ν™˜ } $vrSq = $existing['vr_sq']; diff --git a/app/Services/NaverService.php b/app/Services/NaverService.php index 24ae3ce..773480a 100644 --- a/app/Services/NaverService.php +++ b/app/Services/NaverService.php @@ -59,19 +59,33 @@ class NaverService $vType = $rawData['verificationTypeCode'] ?? ''; // 2. 원본 데이터 Staging μ €μž₯ - $this->rawStagingModel->insert([ + $insertResult = $this->rawStagingModel->insert([ 'atcl_no' => $articleNumber, 'verification_type' => $vType, 'request_type' => $requestType, 'raw_json' => $rawData ]); + + if (!$insertResult) { + $dbError = $this->db->error(); + write_custom_log("naver_raw_staging Insert μ‹€νŒ¨ | Atcl: $articleNumber | Error: " . json_encode($dbError), 'ERROR', 'service'); + throw new Exception("naver_raw_staging μ €μž₯ μ‹€νŒ¨: " . json_encode($dbError)); + } + CLI::write(CLI::color('🟒 μž„μ‹œν…Œμ΄λΈ” μ €μž₯ μ™„λ£Œ', 'green')); // 3. νƒ€μž…λ³„ λΆ„κΈ° 처리 + CLI::write(CLI::color("πŸ”΅ κ²€μ¦νƒ€μž… 확인: vType = $vType", 'cyan')); + write_custom_log("νƒ€μž…λ³„ λΆ„κΈ° | Atcl: $articleNumber | vType: $vType | requestType: $requestType", 'INFO', 'service'); + if ($vType === 'S' || $vType === 'S_VR') { + CLI::write(CLI::color('🟒 Type S Handler 호좜', 'green')); return $this->typeSHandler->handle($articleNumber, $rawData, $payload); } else { - return $this->typeV2Handler->handle($articleNumber, $rawData, $payload); + CLI::write(CLI::color('🟒 Type V2 Handler 호좜', 'green')); + $result = $this->typeV2Handler->handle($articleNumber, $rawData, $payload); + write_custom_log("TypeV2Handler μ™„λ£Œ | Atcl: $articleNumber | Result: $result", 'INFO', 'service'); + return $result; } } catch (Exception $e) {