From e4b089b6957b236b3c4683daf24296958f5c3b17 Mon Sep 17 00:00:00 2001 From: Ariyutta Date: Mon, 28 Sep 2026 15:17:03 +0700 Subject: [PATCH] Penambahan Update nomor HP pimpinan --- .../Pegawai/UpdateNoHpPimpinanCommand.php | 100 ++++++++++++++++++ app/Services/SiskaService.php | 15 +++ 2 files changed, 115 insertions(+) create mode 100644 app/Console/Commands/Pegawai/UpdateNoHpPimpinanCommand.php diff --git a/app/Console/Commands/Pegawai/UpdateNoHpPimpinanCommand.php b/app/Console/Commands/Pegawai/UpdateNoHpPimpinanCommand.php new file mode 100644 index 00000000..5fd0869b --- /dev/null +++ b/app/Console/Commands/Pegawai/UpdateNoHpPimpinanCommand.php @@ -0,0 +1,100 @@ +info('Mengambil data pimpinan dari SISKA...'); + + $pimpinan = $siskaService->daftarPimpinan(); + + if ($pimpinan === null) { + $this->error('Gagal mengambil data dari SISKA'); + + return Command::FAILURE; + } + + $this->info('Total data pimpinan: '.count($pimpinan)); + + // NIP bisa muncul berkali-kali dengan no_hp berbeda, ambil yang terakhir + $noHpByNip = []; + foreach ($pimpinan as $item) { + $nip = $item['nip'] ?? null; + $noHp = $item['no_hp'] ?? null; + + if (! $nip || ! $noHp) { + continue; + } + + $noHpByNip[$nip] = $noHp; + } + + $this->info('Total NIP unik: '.count($noHpByNip)); + $this->newLine(); + + $updatedDosen = 0; + $updatedTendik = 0; + + try { + $nipList = array_keys($noHpByNip); + + $dosens = Dosen::whereIn('nip', $nipList)->get(['id', 'nip', 'no_hp']); + foreach ($dosens as $dosen) { + $noHp = $noHpByNip[$dosen->nip]; + if ($dosen->no_hp !== $noHp) { + $dosen->update(['no_hp' => $noHp]); + $updatedDosen++; + } + } + + $tendiks = Tendik::whereIn('nip', $nipList)->get(['id', 'nip', 'no_hp']); + foreach ($tendiks as $tendik) { + $noHp = $noHpByNip[$tendik->nip]; + if ($tendik->no_hp !== $noHp) { + $tendik->update(['no_hp' => $noHp]); + $updatedTendik++; + } + } + } catch (Exception $e) { + $this->error('Terjadi error: '.$e->getMessage()); + Log::error('Error saat update no_hp pimpinan', [ + 'error' => $e->getMessage(), + 'trace' => $e->getTraceAsString(), + ]); + + return Command::FAILURE; + } + + $this->info("Dosen diupdate: {$updatedDosen}"); + $this->info("Tendik diupdate: {$updatedTendik}"); + $this->info('Selesai.'); + + return Command::SUCCESS; + } +} diff --git a/app/Services/SiskaService.php b/app/Services/SiskaService.php index c9d17b2f..c2d11f37 100644 --- a/app/Services/SiskaService.php +++ b/app/Services/SiskaService.php @@ -685,6 +685,21 @@ class SiskaService return $sks; } + public function daftarPimpinan(): ?array + { + try { + $response = $this->client->get('api/v2/user/pimpinan'); + } catch (Throwable $th) { + Log::error('SISKA: '.$th->getMessage()); + + return null; + } + + $data = json_decode($response->getBody()->getContents(), true); + + return $data['data'] ?? null; + } + public function status(string $status) { $result = [