修复勤务日榜在线时长:CASE WHEN 实时算 open session 时长;关闭 stale 日志时补算 duration_seconds
This commit is contained in:
@@ -50,6 +50,8 @@ class CloseStaleDutyLogs extends Command
|
|||||||
->where('updated_at', '<=', $threshold)
|
->where('updated_at', '<=', $threshold)
|
||||||
->update([
|
->update([
|
||||||
'logout_at' => DB::raw('NOW()'),
|
'logout_at' => DB::raw('NOW()'),
|
||||||
|
// 补算最终在线时长,避免日榜 SUM 使用过时的旧值
|
||||||
|
'duration_seconds' => DB::raw('GREATEST(0, TIMESTAMPDIFF(SECOND, login_at, NOW()))'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if ($affected > 0) {
|
if ($affected > 0) {
|
||||||
|
|||||||
@@ -50,7 +50,17 @@ class DutyHallController extends Controller
|
|||||||
|
|
||||||
// ① 在线时长(position_duty_logs)
|
// ① 在线时长(position_duty_logs)
|
||||||
$dutyQuery = PositionDutyLog::query()
|
$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,排除任命/撤销等人事操作)
|
// ② 管理操作(position_authority_logs,排除任命/撤销等人事操作)
|
||||||
$authQuery = PositionAuthorityLog::query()
|
$authQuery = PositionAuthorityLog::query()
|
||||||
|
|||||||
Reference in New Issue
Block a user