修复勤务日榜在线时长:CASE WHEN 实时算 open session 时长;关闭 stale 日志时补算 duration_seconds

This commit is contained in:
2026-03-18 21:03:36 +08:00
parent afd02b38e3
commit 42beed5c93
2 changed files with 13 additions and 1 deletions

View File

@@ -50,7 +50,17 @@ class DutyHallController extends Controller
// ① 在线时长position_duty_logs
$dutyQuery = PositionDutyLog::query()
->selectRaw('user_id, SUM(duration_seconds) as total_seconds, COUNT(*) as checkin_count');
->selectRaw('
user_id,
SUM(
CASE
WHEN logout_at IS NULL
THEN GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))
ELSE duration_seconds
END
) as total_seconds,
COUNT(*) as checkin_count
');
// ② 管理操作position_authority_logs排除任命/撤销等人事操作)
$authQuery = PositionAuthorityLog::query()