처리가능 수량관리 수정
This commit is contained in:
@@ -110,17 +110,26 @@ class Processible extends BaseController
|
|||||||
public function saveArea()
|
public function saveArea()
|
||||||
{
|
{
|
||||||
log_message('info', '[Processible::saveArea] 진입');
|
log_message('info', '[Processible::saveArea] 진입');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$rows = $this->request->getPost('rows');
|
$rows = $this->request->getPost('rows');
|
||||||
$rows = json_decode($rows, true);
|
$rows = json_decode($rows, true);
|
||||||
|
|
||||||
if (count($rows) > 0) {
|
if (empty($rows)) {
|
||||||
// API 형식으로 변환 및 DB 저장을 한 번에 처리
|
log_message('info', '[Processible::saveArea] 저장가능한 데이터가 없습니다.');
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'code' => '9',
|
||||||
|
'msg' => '저장가능한 데이터가 없습니다.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// API 형식으로 변환 및 DB 저장
|
||||||
$syncSlotData = [];
|
$syncSlotData = [];
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
// DB 저장
|
// DB 저장 (API 실패와 무관하게 저장됨)
|
||||||
$this->model->saveArea($row);
|
$this->model->saveArea($row);
|
||||||
// 동시에 API 데이터 구성
|
|
||||||
|
// API 데이터 구성
|
||||||
$syncSlotData[] = [
|
$syncSlotData[] = [
|
||||||
'baseDate' => $row['sc_date'],
|
'baseDate' => $row['sc_date'],
|
||||||
'legalDivisionNumber' => $row['region_cd'],
|
'legalDivisionNumber' => $row['region_cd'],
|
||||||
@@ -136,38 +145,61 @@ class Processible extends BaseController
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log_message('info', '[Processible::saveArea] DB 저장 완료 | Count: ' . count($rows));
|
||||||
|
|
||||||
|
// 네이버 API 슬롯 동기화 시도
|
||||||
log_message('info', '[Processible::saveArea] 슬롯 동기화 시작 | Count: ' . count($syncSlotData));
|
log_message('info', '[Processible::saveArea] 슬롯 동기화 시작 | Count: ' . count($syncSlotData));
|
||||||
$naverClient = new \App\Libraries\NaverApiClient();
|
$naverClient = new \App\Libraries\NaverApiClient();
|
||||||
$apiResponse = $naverClient->syncSiteSlot($syncSlotData);
|
$apiResponse = $naverClient->syncSiteSlot($syncSlotData);
|
||||||
// API 응답 처리
|
|
||||||
|
// API 응답 에러 체크
|
||||||
|
$hasError = false;
|
||||||
|
$errorMessage = '';
|
||||||
|
|
||||||
if ($apiResponse === null) {
|
if ($apiResponse === null) {
|
||||||
log_message('error', '[Processible::saveArea] Naver API 슬롯 동기화 실패 | Data: ' . json_encode($syncSlotData, JSON_UNESCAPED_UNICODE));
|
$hasError = true;
|
||||||
|
$errorMessage = 'API 응답 없음 (null)';
|
||||||
|
} elseif (!empty($apiResponse['error'])) {
|
||||||
|
$hasError = true;
|
||||||
|
$errorType = $apiResponse['error_type'] ?? 'UNKNOWN';
|
||||||
|
$httpCode = $apiResponse['http_code'] ?? 'N/A';
|
||||||
|
$errorMessage = "API Error: {$errorType} (HTTP {$httpCode})";
|
||||||
|
} elseif (isset($apiResponse['http_code']) && $apiResponse['http_code'] >= 400) {
|
||||||
|
$hasError = true;
|
||||||
|
$errorMessage = "HTTP Error: {$apiResponse['http_code']}";
|
||||||
|
}
|
||||||
|
|
||||||
|
// API 에러 발생 시 (DB는 이미 저장됨)
|
||||||
|
if ($hasError) {
|
||||||
|
log_message('error', "[Processible::saveArea] {$errorMessage} | Response: " . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
'code' => '1',
|
'code' => '1',
|
||||||
'msg' => '저장은 완료되었으나 네이버 슬롯 동기화에 실패했습니다. 로그를 확인하세요.',
|
'msg' => 'DB 저장은 완료되었으나 네이버 슬롯 동기화에 실패했습니다. 관리자에게 문의하세요.',
|
||||||
'syncData' => $syncSlotData,
|
'error' => $errorMessage,
|
||||||
'hint' => '로그 위치: writable/logs/ 에서 ERROR 확인'
|
'dbSaved' => true,
|
||||||
]);
|
|
||||||
}
|
|
||||||
log_message('info', '[Processible::saveArea] Naver API 슬롯 동기화 성공 | Response: ' . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
|
||||||
return $this->response->setJSON([
|
|
||||||
'code' => '0',
|
|
||||||
'msg' => 'success',
|
|
||||||
'syncData' => $syncSlotData,
|
'syncData' => $syncSlotData,
|
||||||
'apiResponse' => $apiResponse
|
'apiResponse' => $apiResponse
|
||||||
]);
|
]);
|
||||||
} else {
|
|
||||||
log_message('info', '[Processible::saveArea] 저장가능한 데이터가 없습니다.');
|
|
||||||
return $this->response->setJSON([
|
|
||||||
'code' => '9',
|
|
||||||
'msg' => '저장가능한 데이터가 없습니다.'
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 성공
|
||||||
|
log_message('info', '[Processible::saveArea] Naver API 슬롯 동기화 성공 | Response: ' . json_encode($apiResponse, JSON_UNESCAPED_UNICODE));
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'code' => '0',
|
||||||
|
'msg' => 'success',
|
||||||
|
'dbSaved' => true,
|
||||||
|
'syncData' => $syncSlotData,
|
||||||
|
'apiResponse' => $apiResponse
|
||||||
|
]);
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
log_message('error', '[Processible::saveArea] 예외: ' . $e->getMessage());
|
log_message('error', '[Processible::saveArea] 예외 발생: ' . $e->getMessage());
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
'code' => '9',
|
'code' => '9',
|
||||||
'msg' => $e->getMessage(),
|
'msg' => '처리 중 오류가 발생했습니다: ' . $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -212,71 +212,49 @@ class ProcessibleModel extends Model
|
|||||||
// 지역별 수량 저장
|
// 지역별 수량 저장
|
||||||
public function saveArea($data)
|
public function saveArea($data)
|
||||||
{
|
{
|
||||||
$this->db->transStart();
|
|
||||||
|
|
||||||
$usr_sq = session('usr_sq');
|
$usr_sq = session('usr_sq');
|
||||||
|
$now = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
$sql = "INSERT INTO service_count
|
$insertData = [
|
||||||
(sc_date, region_cd, am_cnt, pm_cnt, day_cnt, insert_usr, insert_tm, update_usr, update_tm)
|
'sc_date' => $data['sc_date'],
|
||||||
VALUES
|
'region_cd' => $data['region_cd'],
|
||||||
(?, ?, ?, ?, ?, ?, NOW(), ?, NOW())
|
'am_cnt' => $data['am_cnt'],
|
||||||
ON DUPLICATE KEY UPDATE am_cnt=values(am_cnt), pm_cnt=values(pm_cnt), day_cnt=values(day_cnt), update_usr=values(update_usr)
|
'pm_cnt' => $data['pm_cnt'],
|
||||||
";
|
'day_cnt' => (int)$data['am_cnt'] + (int)$data['pm_cnt'],
|
||||||
|
'insert_usr' => $usr_sq,
|
||||||
$datas = [
|
'insert_tm' => $now,
|
||||||
$data['sc_date'],
|
'update_usr' => $usr_sq,
|
||||||
$data['region_cd'],
|
'update_tm' => $now
|
||||||
$data['am_cnt'],
|
|
||||||
$data['pm_cnt'],
|
|
||||||
((int) $data['am_cnt'] + (int) $data['pm_cnt']),
|
|
||||||
$usr_sq,
|
|
||||||
$usr_sq
|
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->db->query($sql, $datas) === false) {
|
// CI4 Query Builder upsert (INSERT ... ON DUPLICATE KEY UPDATE)
|
||||||
return [
|
$result = $this->db->table('service_count')->upsert($insertData);
|
||||||
'success' => false,
|
|
||||||
'msg' => '저장실패',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->db->transComplete();
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => $result !== false,
|
||||||
|
'msg' => $result !== false ? '성공' : '저장실패'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function saveCount($data)
|
public function saveCount($data)
|
||||||
{
|
{
|
||||||
// $this->db->transStart();
|
|
||||||
|
|
||||||
$usr_sq = session('usr_sq');
|
$usr_sq = session('usr_sq');
|
||||||
|
$now = date('Y-m-d H:i:s');
|
||||||
|
|
||||||
$sql = "INSERT INTO service_count
|
$insertData = [
|
||||||
(sc_date, region_cd, am_cnt, pm_cnt, day_cnt, insert_usr, insert_tm, update_usr, update_tm)
|
'sc_date' => '0000-00-00',
|
||||||
VALUES
|
'region_cd' => $data['region_cd'],
|
||||||
(?, ?, ?, ?, ?, ?, NOW(), ?, NOW())
|
'am_cnt' => $data['am_cnt'],
|
||||||
ON DUPLICATE KEY UPDATE
|
'pm_cnt' => $data['pm_cnt'],
|
||||||
am_cnt = VALUES(am_cnt),
|
'day_cnt' => (int)$data['am_cnt'] + (int)$data['pm_cnt'],
|
||||||
pm_cnt = VALUES(pm_cnt),
|
'insert_usr' => $usr_sq,
|
||||||
day_cnt = VALUES(day_cnt),
|
'insert_tm' => $now,
|
||||||
update_usr = VALUES(update_usr),
|
'update_usr' => $usr_sq,
|
||||||
update_tm = NOW()
|
'update_tm' => $now
|
||||||
";
|
|
||||||
|
|
||||||
$datas = [
|
|
||||||
'0000-00-00',
|
|
||||||
$data['region_cd'],
|
|
||||||
$data['am_cnt'],
|
|
||||||
$data['pm_cnt'],
|
|
||||||
((int) $data['am_cnt'] + (int) $data['pm_cnt']),
|
|
||||||
$usr_sq,
|
|
||||||
$usr_sq
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// 쿼리 실행
|
// CI4 Query Builder upsert
|
||||||
$result = $this->db->query($sql, $datas);
|
$result = $this->db->table('service_count')->upsert($insertData);
|
||||||
|
|
||||||
// 실행된 쿼리 로그 출력
|
// 실행된 쿼리 로그 출력
|
||||||
$lastQuery = $this->db->getLastQuery();
|
$lastQuery = $this->db->getLastQuery();
|
||||||
@@ -295,8 +273,6 @@ class ProcessibleModel extends Model
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// $this->db->transComplete();
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'success' => true,
|
'success' => true,
|
||||||
'query' => (string) $lastQuery,
|
'query' => (string) $lastQuery,
|
||||||
|
|||||||
@@ -16,3 +16,5 @@ echo "테스트 파일: " . $testFile . "<br>";
|
|||||||
if (file_exists($testFile)) {
|
if (file_exists($testFile)) {
|
||||||
echo "파일 내용:<pre>" . file_get_contents($testFile) . "</pre>";
|
echo "파일 내용:<pre>" . file_get_contents($testFile) . "</pre>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 파일 변경
|
||||||
Reference in New Issue
Block a user