Switch biometric agent to staging JSON cache flow

This commit is contained in:
2026-05-19 16:27:54 +08:00
parent ceb03224b5
commit 7f92eff3eb
2 changed files with 71 additions and 71 deletions

View File

@@ -63,6 +63,29 @@ class BiometricAttendanceController extends Controller
$zk->disconnect();
}
} catch (\Throwable $th) {}
// Read from local JSON cache if agent pushed data
try {
$cacheFile = storage_path("app/biometric_cache_branch_{$branch->id}.json");
if (file_exists($cacheFile)) {
$cached_attendance = json_decode(file_get_contents($cacheFile), true) ?? [];
$startTs = strtotime(strlen($start_date) == 10 ? $start_date . ' 00:00:00' : $start_date);
$endTs = strtotime(strlen($end_date) == 10 ? $end_date . ' 23:59:59' : $end_date);
foreach ($cached_attendance as $record) {
$punchTs = strtotime($record['timestamp']);
if ($punchTs >= $startTs && $punchTs <= $endTs) {
$attendances[] = [
'id' => $record['uid'],
'emp_code' => (string) $record['id'],
'punch_time' => $record['timestamp'],
'punch_state_display' => $record['type'] == 0 ? 'Clock In' : 'Clock Out',
'terminal_alias' => $branch->name . ' (Agent)',
'branch_id' => $branch->id
];
}
}
}
} catch (\Throwable $th) {}
}
} else if (!empty($api_urls)) {
if ($isDirectIP) {
@@ -370,6 +393,27 @@ class BiometricAttendanceController extends Controller
$zk->disconnect();
}
} catch (\Throwable $th) {}
// Read from local JSON cache if agent pushed data
try {
$cacheFile = storage_path("app/biometric_cache_branch_{$branch->id}.json");
if (file_exists($cacheFile)) {
$cached_attendance = json_decode(file_get_contents($cacheFile), true) ?? [];
$startTs = strtotime(strlen($start_date) == 10 ? $start_date . ' 00:00:00' : $start_date);
$endTs = strtotime(strlen($end_date) == 10 ? $end_date . ' 23:59:59' : $end_date);
foreach ($cached_attendance as $record) {
$punchTs = strtotime($record['timestamp']);
if ($punchTs >= $startTs && $punchTs <= $endTs) {
$attendances[] = [
'id' => $record['uid'],
'emp_code' => (string) $record['id'],
'punch_time' => $record['timestamp'],
'branch_id' => $branch->id
];
}
}
}
} catch (\Throwable $th) {}
}
} else if (!empty($api_urls)) {
if ($isDirectIP) {