트랜젝션 실패시 처리

This commit is contained in:
2026-04-08 20:13:25 +09:00
parent a87fed538b
commit b0ec75ae56

View File

@@ -40,16 +40,25 @@ class TypeSHandler
{ {
CLI::write(CLI::color('🟢 Type S 처리 시작 :: ' . $articleNumber, 'green')); CLI::write(CLI::color('🟢 Type S 처리 시작 :: ' . $articleNumber, 'green'));
// CI 트랜잭션 strict 모드에서는 이전 실패 상태가 누적될 수 있으므로 시작 전에 초기화
if (method_exists($this->db, 'resetTransStatus')) {
$this->db->resetTransStatus();
}
$this->db->transBegin(); $this->db->transBegin();
try { try {
// 1. Receipt 데이터 저장 // 1. Receipt 데이터 저장
$receiptData = $this->parameterMapper->mapReceipt($articleNumber, $rawData, $payload); $receiptData = $this->parameterMapper->mapReceipt($articleNumber, $rawData, $payload);
write_custom_log("Result Insert 데이터: " . json_encode($receiptData, JSON_UNESCAPED_UNICODE), 'INFO', 'service');
if (!$this->receiptModel->insert($receiptData)) { if (!$this->receiptModel->insert($receiptData)) {
$lastQuery = (string)$this->receiptModel->getLastQuery();
$errors = json_encode($this->receiptModel->errors());
write_custom_log("Receipt Insert 실패 | SQL: $lastQuery | Errors: $errors", 'ERROR', 'service');
throw new Exception("Receipt Insert 실패: " . json_encode($this->receiptModel->errors())); throw new Exception("Receipt Insert 실패: " . json_encode($this->receiptModel->errors()));
} }
$rcptSq = $this->receiptModel->getInsertID(); $rcptSq = $this->receiptModel->getInsertID();
$receiptInsertSql = (string)$this->receiptModel->getLastQuery(); // Receipt SQL 캡처 $receiptInsertSql = (string)$this->receiptModel->getLastQuery(); // Receipt SQL 캡처
CLI::write(CLI::color("✅ Receipt 저장 성공 (ID: $rcptSq)", 'blue')); CLI::write(CLI::color("✅ Receipt 저장 성공 (ID: $rcptSq)", 'blue'));
@@ -71,7 +80,16 @@ class TypeSHandler
// 3. 트랜잭션 커밋 // 3. 트랜잭션 커밋
$this->db->transComplete(); $this->db->transComplete();
if ($this->db->transStatus() === false) { if ($this->db->transStatus() === false) {
write_custom_log("Type S DB 트랜잭션 최종 실패", 'ERROR', 'service'); $dbError = $this->db->error();
$errorJson = json_encode($dbError, JSON_UNESCAPED_UNICODE);
$receiptLastQuery = (string)$this->receiptModel->getLastQuery();
$resultLastQuery = (string)$this->resultModel->getLastQuery();
write_custom_log(
"Type S DB 트랜잭션 최종 실패 | DB Error: {$errorJson} | ReceiptLastQuery: {$receiptLastQuery} | ResultLastQuery: {$resultLastQuery}",
'ERROR',
'service'
);
throw new Exception("Type S DB 트랜잭션 최종 실패"); throw new Exception("Type S DB 트랜잭션 최종 실패");
} }