186 lines
6.4 KiB
PHP
186 lines
6.4 KiB
PHP
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
|
|
// 헬퍼 로드 (app/Helpers/log_helper.php 가 있어야 함 autoload 설정 넣어놓았음)
|
|
|
|
class NaverWorker extends BaseCommand
|
|
{
|
|
protected $group = 'Workers';
|
|
protected $name = 'naver:worker';
|
|
protected $description = 'Redis에서 데이터를 꺼내 DB에 저장하고 네이버 API를 호출합니다.';
|
|
|
|
public function run(array $params)
|
|
{
|
|
$redis = new \Redis();
|
|
try {
|
|
$redis->connect('redis', 6379);
|
|
$redis->select(9);
|
|
CLI::write(CLI::color('🟢 Naver Worker running...', 'green'));
|
|
} catch (\Exception $e) {
|
|
CLI::error("Redis 연결 불가: " . $e->getMessage());
|
|
return;
|
|
}
|
|
|
|
while (true) {
|
|
try {
|
|
// 1. Redis에서 데이터를 꺼냄
|
|
$result = $redis->brPop(['naver:raw_queue'], 30);
|
|
|
|
if ($result) {
|
|
$rawData = $result[1];
|
|
try {
|
|
$payload = json_decode($rawData, true);
|
|
|
|
// 2. 실제 작업 수행
|
|
$this->processTask($payload);
|
|
|
|
CLI::write("✅ Success: " . ($payload['articleNumber'] ?? 'Unknown'), 'cyan');
|
|
|
|
} catch (\Exception $e) {
|
|
// 3. 실패 시: Helper 함수 사용
|
|
$errorMsg = $e->getMessage();
|
|
|
|
CLI::error("❌ Task Failed: $errorMsg");
|
|
|
|
// 공통 헬퍼 함수 호출
|
|
write_custom_log("FAILED_DATA | Error: $errorMsg | Data: $rawData", 'ERROR', 'failed');
|
|
}
|
|
}
|
|
} catch (\Exception $e) {
|
|
CLI::error("Worker Loop Error: " . $e->getMessage());
|
|
sleep(1);
|
|
}
|
|
}
|
|
}
|
|
|
|
private function processTask($payload)
|
|
{
|
|
// 실제 비즈니스 로직
|
|
// {
|
|
// "articleNumber": "2500000001",
|
|
// "reqeustType": "REG",
|
|
// "requestDatetime": "2025-12-22 19:20:12"
|
|
// }
|
|
|
|
// 1. 필수 데이터 검증
|
|
if (empty($payload['articleNumber']) || empty($payload['reqeustType'])) {
|
|
throw new \Exception("필수 파라미터 누락");
|
|
}
|
|
|
|
$articleNumber = $payload['articleNumber'];
|
|
/*
|
|
REG : 수동검증요청 ,
|
|
MOD 매물정보수정 - 매물제공업체의 매물정보 수정으로 재검증요청 1차 실패 후 재검증 요청 ,
|
|
CNC : 사용자취소 ,
|
|
FIN : 서비스 노출/대기 검수완료 상태(필요한 상태인지 확인 필요)
|
|
*/
|
|
$requestType = $payload['reqeustType'];
|
|
|
|
// 2. 네이버 API 클라이언트 초기화
|
|
$naverClient = new \App\Libraries\NaverApiClient();
|
|
// 3. 요청 유형에 따른 처리
|
|
if (in_array($requestType, ['REG', 'MOD'])) {
|
|
// 매물 정보 조회
|
|
$articleInfojson = $naverClient->getArticleInfo($articleNumber);
|
|
if (!$articleInfojson || !isset($articleInfojson['data']) || empty($articleInfojson['code'] !== 'success')) {
|
|
throw new \Exception("매물 정보 조회 실패: $articleNumber ::: message : " . ($articleInfojson['message'] ?? 'No response'));
|
|
}
|
|
// 받아온 정보 로그 기록
|
|
write_custom_log("ARTICLE_INFO | ArticleNumber: $articleNumber | Info: " . json_encode($articleInfo , JSON_UNESCAPED_UNICODE), 'INFO', 'service');
|
|
CLI::write("Fetched Article Info: " . json_encode($articleInfo));
|
|
|
|
$articleInfo = $articleInfojson['data'];
|
|
|
|
/**
|
|
* $articleInfo['verificationTypeCode']
|
|
* S : 현장확인매물
|
|
* D : 홍보확인서
|
|
* N : 신홍보확인서
|
|
* M : 모바일
|
|
* T : 전화
|
|
* O : 모바일확인V2
|
|
*
|
|
* S - reciept , result 테이블 사용
|
|
* D,N,M,T,O - v2_vrfc_req , v2_article_info , v2_article_info_etc , v2_article_fail 테이블 사용
|
|
*/
|
|
|
|
// 공통 정보
|
|
"articleNumber":"2500016420",
|
|
"verificationTypeCode":"S",
|
|
"cpId": "naver",
|
|
"cpArticleNumber":"nv-2025052201",
|
|
"realEstateTypeCode":"A01",
|
|
"realEstateType": "아파트",
|
|
"tradeTypeCode":"A1",
|
|
"tradeType": "매매",
|
|
"isUnregisteredVerificationRequested": false,
|
|
"isBuildingRegisterAreaCheckRequested":false,
|
|
"isAutoVerificationRequested": false,
|
|
|
|
// $comp_sq = '2';
|
|
// $rcpt_rating = '3';
|
|
// $rcpt_key = $articleInfo['articleNumber']; // 매물 번호와 동일
|
|
// $rcpt_cpid = $articleInfo['cpId'];
|
|
// $rcpt_atclno = $articleInfo['articleNumber'];
|
|
// $cpArticleNumber = $articleInfo['cpArticleNumber'];
|
|
|
|
// $rcpt_deal_type
|
|
// $rcpt_product_info1
|
|
// $rcpt_product_info2
|
|
|
|
// $rcpt_living_yn
|
|
// $rcpt_sido
|
|
// $rcpt_gugun
|
|
// $rcpt_dong
|
|
// $rcpt_x
|
|
// $rcpt_y
|
|
|
|
// $rcpt_hscp_nm
|
|
// $rcpt_hscp_no
|
|
// $rcpt_ptp_nm
|
|
// $rcpt_ptp_no
|
|
|
|
// $rcpt_dtl_addr
|
|
// $rcpt_li_addr
|
|
// $rcpt_jibun_addr
|
|
// $rcpt_etc_addr
|
|
// $rcpt_ref_addr
|
|
|
|
// $rcpt_floor
|
|
// $rcpt_floor2
|
|
// $rcpt_product
|
|
// $rcpt_product_nm
|
|
// $agent_id
|
|
// $agent_nm
|
|
// $agent_contact_tel
|
|
// $agent_head_tel
|
|
// $agent_fax
|
|
// $rsrv_date
|
|
// $rsrv_tm_ap
|
|
|
|
|
|
|
|
|
|
if ($articleInfo['verificationTypeCode'] == 'S') { // 현장확인매물
|
|
// 현장확인매물 처리 로직
|
|
$receiptModel = new ReceiptModel();
|
|
|
|
|
|
} else { // 그외 일반매물
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CLI::write("Processing: " . ($payload['articleNumber'] ?? 'Unknown'));
|
|
}
|
|
} |