set cron job update no sjp

This commit is contained in:
Fadila
2025-09-22 09:04:00 +07:00
parent b27682f5b3
commit a29c39086a
2 changed files with 49 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
<?php
namespace App\Console\Commands;
use App\Models\OLDLMS\Livechat;
use Carbon\Carbon;
use Illuminate\Console\Command;
use GuzzleHttp\Client;
class UpdateNoSJP extends Command {
protected $signature = 'update:no-sjp';
protected $description = 'Cek data Livechat yang sNoSpj kosong lalu generate SJP lewat API';
public function handle() {
$this->info('Checking Data ...');
$client = new Client([ 'base_uri' => 'https://api.linksehat.dev', 'headers' => ['Content-Type' => 'application/json'], 'timeout' => 10, ]);
$liveChats = Livechat::query()
->join('tx_livechat_summary', 'tx_livechat_summary.nIDLiveChat', '=', 'tx_livechat.nID')
->whereNull('tx_livechat.sNoSpj')
->whereDate('tx_livechat.dCreateOn', Carbon::today())
->select('tx_livechat.nID', 'tx_livechat_summary.nID as summary_id')
->get();
foreach ($liveChats as $row) {
try {
$prescriptionData = [
'nIDLivechats' => [$row->nID]
];
$response = $client->post('/api/rujukan-dan-sjp', [
'json' => $prescriptionData,
]);
$body = json_decode($response->getBody()->getContents(), true);
$this->info('Jumlah Livechat dikirim: ' . $liveChats->count());
$this->info("Nomor SJP berhasil dibuat untuk Livechat {$row->nID}");
} catch (\Exception $e) {
$this->error("Gagal generate Nomor SJP Livechat {$row->nID}: " . $e->getMessage());
}
}
$this->info('Proses selesai.');
return Command::SUCCESS;
}
}

View File

@@ -17,6 +17,7 @@ class Kernel extends ConsoleKernel
{
// $schedule->command('inspire')->hourly();
$schedule->command('log:auto-update-status')->dailyAt('01:00');
$schedule->command('update:no-sjp')->everyThirtyMinutes();
}
/**