勤务榜只统计已关闭记录(whereNotNull logout_at);清理今日重复坏数据

This commit is contained in:
2026-03-18 21:31:44 +08:00
parent f3579ae9fe
commit c9cab898c2

View File

@@ -50,17 +50,9 @@ class DutyHallController extends Controller
// ① 在线时长position_duty_logs
$dutyQuery = PositionDutyLog::query()
->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
');
->selectRaw('user_id, SUM(duration_seconds) as total_seconds, COUNT(*) as checkin_count')
// 只统计有离开时间的已完结记录open session 不计入(防止实时计算偏差)
->whereNotNull('logout_at');
// ② 管理操作position_authority_logs排除任命/撤销等人事操作)
$authQuery = PositionAuthorityLog::query()