Merge pull request 'Penambahan Update nomor HP pimpinan' (#31) from development into main

Reviewed-on: #31
This commit is contained in:
2026-09-28 15:17:35 +07:00
2 changed files with 115 additions and 0 deletions
@@ -0,0 +1,100 @@
<?php
namespace App\Console\Commands\Pegawai;
use App\Models\Verifikator\Dosen;
use App\Models\Verifikator\Tendik;
use App\Services\SiskaService;
use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
class UpdateNoHpPimpinanCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'pegawai:update-no-hp-pimpinan';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update nomor HP dosen dan tendik dari SISKA API (api/v2/user/pimpinan)';
/**
* Execute the console command.
*/
public function handle(SiskaService $siskaService)
{
$this->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;
}
}
+15
View File
@@ -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 = [