165 lines
3.4 KiB
Markdown
165 lines
3.4 KiB
Markdown
# Setup Perizinan API Integration
|
|
|
|
## Overview
|
|
|
|
Sistem ini mengintegrasikan data perizinan dari API Jakarta dengan database lokal menggunakan cron job yang berjalan setiap hari pada jam 12 malam.
|
|
|
|
## Setup Instructions
|
|
|
|
### 1. Environment Configuration
|
|
|
|
Update file `.env` dengan credentials API:
|
|
|
|
```env
|
|
# Perizinan API Configuration
|
|
PERIZINAN_API_BASE_URL=https://wsdev.jakarta.go.id/gateway/DataPerizinanLingkungan/1.0
|
|
PERIZINAN_API_BEARER_TOKEN=your_actual_bearer_token
|
|
PERIZINAN_API_KEY=your_actual_api_key
|
|
```
|
|
|
|
### 2. Database Migration
|
|
|
|
Jalankan migration untuk membuat tabel:
|
|
|
|
```bash
|
|
php artisan migrate
|
|
```
|
|
|
|
### 3. Manual Sync (Testing)
|
|
|
|
Untuk test sync manual:
|
|
|
|
```bash
|
|
# Sync semua kategori
|
|
php artisan perizinan:sync
|
|
|
|
# Sync kategori tertentu
|
|
php artisan perizinan:sync pertek
|
|
php artisan perizinan:sync amdal
|
|
```
|
|
|
|
### 4. Cron Job Setup (Linux Production Server)
|
|
|
|
Sistem sudah dikonfigurasi untuk berjalan otomatis setiap hari jam 12 malam. Untuk aktivasi cron job di server Linux:
|
|
|
|
#### Opsi 1: Laravel Scheduler (Recommended)
|
|
|
|
```bash
|
|
# Edit crontab
|
|
crontab -e
|
|
|
|
# Add this line (runs every minute):
|
|
* * * * * cd /var/www/perling && ./run-scheduler.sh >/dev/null 2>&1
|
|
```
|
|
|
|
#### Opsi 2: Direct Sync
|
|
|
|
```bash
|
|
# Edit crontab
|
|
crontab -e
|
|
|
|
# Add this line (runs daily at midnight):
|
|
0 0 * * * cd /var/www/perling && ./sync-perizinan.sh >/dev/null 2>&1
|
|
```
|
|
|
|
### 5. Production Deployment
|
|
|
|
Untuk deployment ke production server, lihat file `PRODUCTION_DEPLOY.md` untuk panduan lengkap.
|
|
|
|
### 6. Monitoring
|
|
|
|
Cek log file untuk monitoring sync process:
|
|
|
|
```bash
|
|
# Application logs
|
|
tail -f storage/logs/laravel.log
|
|
|
|
# Cron job logs
|
|
tail -f storage/logs/cron.log
|
|
|
|
# Scheduler logs (if using Laravel Scheduler)
|
|
tail -f storage/logs/scheduler.log
|
|
|
|
# Check cron service status
|
|
sudo systemctl status cron
|
|
|
|
# View cron job list
|
|
crontab -l
|
|
```
|
|
|
|
## API Response Format
|
|
|
|
```json
|
|
{
|
|
"success": true,
|
|
"message": "Summary by status retrieved successfully.",
|
|
"data": [
|
|
{
|
|
"id": "ditolak",
|
|
"label": "Izin Ditolak",
|
|
"value": 1443
|
|
},
|
|
{
|
|
"id": "selesai",
|
|
"label": "Izin Selesai",
|
|
"value": 8379
|
|
},
|
|
{
|
|
"id": "proses",
|
|
"label": "Dalam Proses",
|
|
"value": 143
|
|
},
|
|
{
|
|
"id": "total",
|
|
"label": "Total Pengajuan",
|
|
"value": 9965
|
|
}
|
|
],
|
|
"last_updated": "2025-07-14 08:55:04"
|
|
}
|
|
```
|
|
|
|
## Database Schema
|
|
|
|
Table: `perizinan_status`
|
|
|
|
- `id` - Primary key
|
|
- `kategori` - Category (pertek, amdal)
|
|
- `status_id` - Status ID (ditolak, selesai, proses, total)
|
|
- `label` - Human readable label
|
|
- `value` - Count value
|
|
- `api_last_updated` - Last updated timestamp from API
|
|
- `sync_date` - Date when data was synced
|
|
- `created_at` / `updated_at` - Laravel timestamps
|
|
|
|
## Features
|
|
|
|
- ✅ Daily automatic sync at midnight
|
|
- ✅ Duplicate prevention (same data per day)
|
|
- ✅ Comprehensive logging
|
|
- ✅ Fallback to static data if API fails
|
|
- ✅ Manual sync commands for testing
|
|
- ✅ Database storage with indexing for performance
|
|
|
|
## Troubleshooting
|
|
|
|
### Command not found
|
|
|
|
```bash
|
|
php artisan optimize:clear
|
|
composer dump-autoload
|
|
```
|
|
|
|
### API Connection Issues
|
|
|
|
1. Verify credentials in `.env`
|
|
2. Check network connectivity
|
|
3. Review logs for detailed error messages
|
|
|
|
### Database Issues
|
|
|
|
```bash
|
|
php artisan migrate:fresh
|
|
php artisan migrate
|
|
```
|