diff --git a/app/Console/Commands/UpdateNoSjp.php b/app/Console/Commands/UpdateNoSjp.php new file mode 100644 index 00000000..50c690bc --- /dev/null +++ b/app/Console/Commands/UpdateNoSjp.php @@ -0,0 +1,48 @@ +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; + } +} \ No newline at end of file diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 5489a453..46ff531f 100755 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -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(); } /**