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