feat(webstatement): tambahkan kolom baru dan perbaiki kode job sinkronisasi ATM card
- Menambahkan kolom `crdate` pada tabel `atmcards` di database. - Memperbaiki struktur dan penyesuaian format kode pada file `BiayaKartu.php`. - Menyelaraskan alignment konstanta, parameter, dan body fungsi untuk meningkatkan keterbacaan. - Menambahkan pengelolaan data `crdate` dalam proses sinkronisasi kartu ATM. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -1,153 +1,163 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Modules\Webstatement\Jobs;
|
namespace Modules\Webstatement\Jobs;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Support\Facades\Http;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Modules\Webstatement\Models\Atmcard;
|
use Illuminate\Support\Facades\Http;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Modules\Webstatement\Models\Atmcard;
|
||||||
|
|
||||||
class BiayaKartu implements ShouldQueue
|
class BiayaKartu implements ShouldQueue
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* API dan database constants
|
|
||||||
*/
|
|
||||||
private const API_BASE_PATH = '/restgateway/services/IGATEToCoreBankingServices';
|
|
||||||
private const API_INQUIRY_PATH = '/InquiryBalanceService';
|
|
||||||
private const DB_TABLE = 'IST77.VW_CMS_VCARD';
|
|
||||||
private const BATCH_SIZE = 100;
|
|
||||||
private const MAX_EXECUTION_TIME = 86400; // 24 jam dalam detik
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*/
|
|
||||||
public function handle(): void
|
|
||||||
{
|
{
|
||||||
set_time_limit(self::MAX_EXECUTION_TIME);
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
$this->syncAtmCards();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get account information from the API
|
* API dan database constants
|
||||||
*
|
*/
|
||||||
* @param string $accountNumber
|
private const API_BASE_PATH = '/restgateway/services/IGATEToCoreBankingServices';
|
||||||
* @return array
|
private const API_INQUIRY_PATH = '/InquiryBalanceService';
|
||||||
*/
|
private const DB_TABLE = 'IST77.VW_CMS_VCARD';
|
||||||
private function getAccountInfo(string $accountNumber): array
|
private const BATCH_SIZE = 100;
|
||||||
{
|
private const MAX_EXECUTION_TIME = 86400; // 24 jam dalam detik
|
||||||
$url = env('FIORANO_URL') . self::API_BASE_PATH;
|
|
||||||
$path = self::API_INQUIRY_PATH;
|
|
||||||
$data = [
|
|
||||||
'accountNo' => $accountNumber
|
|
||||||
];
|
|
||||||
|
|
||||||
$response = Http::post($url . $path, $data);
|
/**
|
||||||
|
* Execute the job.
|
||||||
return $response->json();
|
*/
|
||||||
}
|
public function handle()
|
||||||
|
: void
|
||||||
/**
|
{
|
||||||
* Synchronize ATM cards data from Oracle database
|
set_time_limit(self::MAX_EXECUTION_TIME);
|
||||||
*
|
$this->syncAtmCards();
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function syncAtmCards(): void
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$offset = 0;
|
|
||||||
$hasMoreRecords = true;
|
|
||||||
|
|
||||||
while ($hasMoreRecords) {
|
|
||||||
$cards = $this->fetchCardBatch($offset);
|
|
||||||
$this->processCardBatch($cards);
|
|
||||||
|
|
||||||
$hasMoreRecords = count($cards) === self::BATCH_SIZE;
|
|
||||||
$offset += self::BATCH_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log::info('Sinkronisasi kartu ATM berhasil diselesaikan');
|
|
||||||
} catch (Exception $e) {
|
|
||||||
Log::error('BiayaKartu: syncAtmCards: ' . $e->getMessage(), [
|
|
||||||
'file' => $e->getFile(),
|
|
||||||
'line' => $e->getLine()
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a batch of ATM cards from the database
|
* Synchronize ATM cards data from Oracle database
|
||||||
*
|
*
|
||||||
* @param int $offset
|
* @return void
|
||||||
* @return \Illuminate\Support\Collection
|
*/
|
||||||
*/
|
private function syncAtmCards()
|
||||||
private function fetchCardBatch(int $offset)
|
: void
|
||||||
{
|
{
|
||||||
return DB::connection('oracle')
|
|
||||||
->table(self::DB_TABLE)
|
|
||||||
->where('crsts', 1)
|
|
||||||
->whereNotNull('ACCFLAG')
|
|
||||||
->where('ACCFLAG', '>', 0)
|
|
||||||
->skip($offset)
|
|
||||||
->take(self::BATCH_SIZE)
|
|
||||||
->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Process a batch of ATM cards
|
|
||||||
*
|
|
||||||
* @param \Illuminate\Support\Collection $cards
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
private function processCardBatch($cards): void
|
|
||||||
{
|
|
||||||
foreach ($cards as $card) {
|
|
||||||
try {
|
try {
|
||||||
$accountInfo = $this->getAccountInfo($card->accflag);
|
$offset = 0;
|
||||||
$this->updateOrCreateAtmCard($card, $accountInfo);
|
$hasMoreRecords = true;
|
||||||
|
|
||||||
|
while ($hasMoreRecords) {
|
||||||
|
$cards = $this->fetchCardBatch($offset);
|
||||||
|
$this->processCardBatch($cards);
|
||||||
|
|
||||||
|
$hasMoreRecords = count($cards) === self::BATCH_SIZE;
|
||||||
|
$offset += self::BATCH_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info('Sinkronisasi kartu ATM berhasil diselesaikan');
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
Log::warning("Gagal memproses kartu {$card->crdno}: " . $e->getMessage());
|
Log::error('BiayaKartu: syncAtmCards: ' . $e->getMessage(), [
|
||||||
|
'file' => $e->getFile(),
|
||||||
|
'line' => $e->getLine()
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update or create ATM card record
|
* Fetch a batch of ATM cards from the database
|
||||||
*
|
*
|
||||||
* @param object $card
|
* @param int $offset
|
||||||
* @param array $accountInfo
|
*
|
||||||
* @return void
|
* @return \Illuminate\Support\Collection
|
||||||
*/
|
*/
|
||||||
private function updateOrCreateAtmCard(object $card, array $accountInfo): void
|
private function fetchCardBatch(int $offset)
|
||||||
{
|
{
|
||||||
Atmcard::updateOrCreate(
|
return DB::connection('oracle')
|
||||||
['crdno' => $card->crdno],
|
->table(self::DB_TABLE)
|
||||||
[
|
->where('crsts', 1)
|
||||||
'accflag' => $card->accflag,
|
->whereNotNull('ACCFLAG')
|
||||||
'cracc1' => $card->cracc1,
|
->where('ACCFLAG', '>', 0)
|
||||||
'cracc2' => $card->cracc2,
|
->skip($offset)
|
||||||
'cracc3' => $card->cracc3,
|
->take(self::BATCH_SIZE)
|
||||||
'cracc4' => $card->cracc4,
|
->get();
|
||||||
'cracc5' => $card->cracc5,
|
}
|
||||||
'craccnam1' => $card->craccnam1,
|
|
||||||
'craccnam2' => $card->craccnam2,
|
/**
|
||||||
'craccnam3' => $card->craccnam3,
|
* Process a batch of ATM cards
|
||||||
'craccnam4' => $card->craccnam4,
|
*
|
||||||
'craccnam5' => $card->craccnam5,
|
* @param \Illuminate\Support\Collection $cards
|
||||||
'crsts' => $card->crsts,
|
*
|
||||||
'cttype' => $card->cttype,
|
* @return void
|
||||||
'ctdesc' => $card->ctdesc,
|
*/
|
||||||
'last_update' => $card->lastupdate,
|
private function processCardBatch($cards)
|
||||||
'branch' => $accountInfo['acctCompany'],
|
: void
|
||||||
'currency' => $accountInfo['acctCurrency'],
|
{
|
||||||
]
|
foreach ($cards as $card) {
|
||||||
);
|
try {
|
||||||
|
$accountInfo = $this->getAccountInfo($card->accflag);
|
||||||
|
$this->updateOrCreateAtmCard($card, $accountInfo);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::warning("Gagal memproses kartu {$card->crdno}: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get account information from the API
|
||||||
|
*
|
||||||
|
* @param string $accountNumber
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function getAccountInfo(string $accountNumber)
|
||||||
|
: array
|
||||||
|
{
|
||||||
|
$url = env('FIORANO_URL') . self::API_BASE_PATH;
|
||||||
|
$path = self::API_INQUIRY_PATH;
|
||||||
|
$data = [
|
||||||
|
'accountNo' => $accountNumber
|
||||||
|
];
|
||||||
|
|
||||||
|
$response = Http::post($url . $path, $data);
|
||||||
|
|
||||||
|
return $response->json();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update or create ATM card record
|
||||||
|
*
|
||||||
|
* @param object $card
|
||||||
|
* @param array $accountInfo
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
private function updateOrCreateAtmCard(object $card, array $accountInfo)
|
||||||
|
: void
|
||||||
|
{
|
||||||
|
Atmcard::updateOrCreate(
|
||||||
|
['crdno' => $card->crdno],
|
||||||
|
[
|
||||||
|
'accflag' => $card->accflag,
|
||||||
|
'cracc1' => $card->cracc1,
|
||||||
|
'cracc2' => $card->cracc2,
|
||||||
|
'cracc3' => $card->cracc3,
|
||||||
|
'cracc4' => $card->cracc4,
|
||||||
|
'cracc5' => $card->cracc5,
|
||||||
|
'craccnam1' => $card->craccnam1,
|
||||||
|
'craccnam2' => $card->craccnam2,
|
||||||
|
'craccnam3' => $card->craccnam3,
|
||||||
|
'craccnam4' => $card->craccnam4,
|
||||||
|
'craccnam5' => $card->craccnam5,
|
||||||
|
'crsts' => $card->crsts,
|
||||||
|
'cttype' => $card->cttype,
|
||||||
|
'ctdesc' => $card->ctdesc,
|
||||||
|
'last_update' => $card->lastupdate,
|
||||||
|
'crdate' => $card->crdate,
|
||||||
|
'branch' => $accountInfo['acctCompany'],
|
||||||
|
'currency' => $accountInfo['acctCurrency'],
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ return new class extends Migration
|
|||||||
$table->string('crsts')->nullable();
|
$table->string('crsts')->nullable();
|
||||||
$table->string('cttype')->nullable();
|
$table->string('cttype')->nullable();
|
||||||
$table->string('ctdesc')->nullable();
|
$table->string('ctdesc')->nullable();
|
||||||
|
$table->string('crdate')->nullable();
|
||||||
$table->string('branch')->nullable();
|
$table->string('branch')->nullable();
|
||||||
$table->string('currency')->nullable();
|
$table->string('currency')->nullable();
|
||||||
$table->decimal('fee', 10, 2)->nullable();
|
$table->decimal('fee', 10, 2)->nullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user