현장 확인 > 처리 가능 수량 관리 api 및 수정
This commit is contained in:
@@ -107,44 +107,70 @@ class Processible extends BaseController
|
|||||||
|
|
||||||
|
|
||||||
// 지역별 수량 저장
|
// 지역별 수량 저장
|
||||||
public function saveArea()
|
public function saveArea()
|
||||||
{
|
{
|
||||||
try {
|
log_message('info', '[Processible::saveArea] 진입');
|
||||||
|
try {
|
||||||
|
$rows = $this->request->getPost('rows');
|
||||||
|
$rows = json_decode($rows, true);
|
||||||
|
|
||||||
$rows = $this->request->getPost('rows');
|
if (count($rows) > 0) {
|
||||||
$rows = json_decode($rows, true);
|
// API 형식으로 변환 및 DB 저장을 한 번에 처리
|
||||||
|
$syncSlotData = [];
|
||||||
// dd($rows);
|
foreach ($rows as $row) {
|
||||||
// exit;
|
// DB 저장
|
||||||
|
$this->model->saveArea($row);
|
||||||
if (count($rows) > 0) {
|
// 동시에 API 데이터 구성
|
||||||
|
$syncSlotData[] = [
|
||||||
foreach ($rows as $row):
|
'baseDate' => $row['sc_date'],
|
||||||
$this->model->saveArea($row);
|
'legalDivisionNumber' => $row['region_cd'],
|
||||||
endforeach;
|
'slots' => [
|
||||||
|
'am' => [
|
||||||
return $this->response->setJSON([
|
'max' => (int) $row['am_cnt'],
|
||||||
'code' => '0',
|
'reserved' => 0
|
||||||
'msg' => 'success'
|
],
|
||||||
]);
|
'pm' => [
|
||||||
|
'max' => (int) $row['pm_cnt'],
|
||||||
} else {
|
'reserved' => 0
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
log_message('info', '[Processible::saveArea] 슬롯 동기화 시작 | Count: ' . count($syncSlotData));
|
||||||
|
$naverClient = new \App\Libraries\NaverApiClient();
|
||||||
|
$apiResponse = $naverClient->syncSiteSlot($syncSlotData);
|
||||||
|
// API 응답 처리
|
||||||
|
if ($apiResponse === null) {
|
||||||
|
log_message('error', '[Processible::saveArea] Naver API 슬롯 동기화 실패 | Data: ' . json_encode($syncSlotData, 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',
|
||||||
|
'syncData' => $syncSlotData,
|
||||||
|
'apiResponse' => $apiResponse
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
log_message('info', '[Processible::saveArea] 저장가능한 데이터가 없습니다.');
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'code' => '9',
|
||||||
|
'msg' => '저장가능한 데이터가 없습니다.'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
log_message('error', '[Processible::saveArea] 예외: ' . $e->getMessage());
|
||||||
return $this->response->setJSON([
|
return $this->response->setJSON([
|
||||||
'code' => '9',
|
'code' => '9',
|
||||||
'msg' => '저장가능한 데이터가 없습니다.'
|
'msg' => $e->getMessage(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
return $this->response->setJSON([
|
|
||||||
'code' => '9',
|
|
||||||
'msg' => $e->getMessage(),
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 기본 수량 저장
|
|
||||||
public function saveCount()
|
public function saveCount()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -518,11 +518,19 @@ class NaverApiClient
|
|||||||
|
|
||||||
$response = curl_exec($ch);
|
$response = curl_exec($ch);
|
||||||
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||||
|
$curlError = curl_error($ch);
|
||||||
|
$curlErrno = curl_errno($ch);
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
|
// CURL 오류 체크
|
||||||
|
if ($curlErrno !== 0) {
|
||||||
|
log_message('error', "[Naver API $method CURL ERROR] URL: $url | Error ($curlErrno): $curlError");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
// 결과 로그 기록 (성공/실패 모두 기록하여 추적 가능하게 함)
|
// 결과 로그 기록 (성공/실패 모두 기록하여 추적 가능하게 함)
|
||||||
if ($httpCode === 200 || $httpCode === 202) {
|
if ($httpCode === 200 || $httpCode === 202) {
|
||||||
log_message('info', "[Naver API $method SUCCESS] URL: $url | Response: $response");
|
log_message('info', "[Naver API $method SUCCESS] URL: $url | Code: $httpCode | Response: $response");
|
||||||
} else {
|
} else {
|
||||||
log_message('error', "[Naver API $method FAIL] URL: $url | Code: $httpCode | Response: $response");
|
log_message('error', "[Naver API $method FAIL] URL: $url | Code: $httpCode | Response: $response");
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -303,4 +303,21 @@ class ProcessibleModel extends Model
|
|||||||
'affected_rows' => $this->db->affectedRows()
|
'affected_rows' => $this->db->affectedRows()
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 슬롯 동기화
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function getSyncSlotData($baseDate, $region_cd)
|
||||||
|
{
|
||||||
|
|
||||||
|
$sql = "SELECT sc_date, region_cd, am_cnt, pm_cnt, day_cnt FROM service_count WHERE sc_date = ? AND region_cd IN ?";
|
||||||
|
$datas = [
|
||||||
|
$baseDate,
|
||||||
|
$region_cd
|
||||||
|
];
|
||||||
|
$query = $this->db->query($sql, $datas);
|
||||||
|
return $query->getResultArray();
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
|
|
||||||
<div class="d-flex gap-1 ms-auto">
|
<div class="d-flex gap-1 ms-auto">
|
||||||
<button class="btn btn-sm btn-outline-success" id="excel-download" type="button">
|
<button class="btn btn-sm btn-outline-success" id="excel-download" type="button">
|
||||||
<i class="fa fa-fw" aria-hidden="true" title="file-excel-o"></i> 엑셀다운로드
|
<i class="fa fa-fw" aria-hidden="true" title="file-excel-o"></i> 엑셀다운로드
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-sm btn-outline-light" type="button" id="btnSearch">
|
<button class="btn btn-sm btn-outline-light" type="button" id="btnSearch">
|
||||||
조회
|
조회
|
||||||
|
|||||||
Reference in New Issue
Block a user