From 2b677c6f89dcb67162abe4671a438b4ff4c2ad14 Mon Sep 17 00:00:00 2001 From: augushong Date: Tue, 28 Jul 2026 06:02:07 +0800 Subject: [PATCH] =?UTF-8?q?feat(nginx-log):=20NginxLogStatAggregate=20?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E4=BB=BB=E5=8A=A1=20+=20timer=20config=20?= =?UTF-8?q?=E6=B3=A8=E5=86=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../timer/NginxLogStatAggregate.php | 20 +++++ .../timer/NginxLogStatAggregateBase.php | 81 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 app/tools/controller/timer/NginxLogStatAggregate.php create mode 100644 extend/base/tools/controller/timer/NginxLogStatAggregateBase.php diff --git a/app/tools/controller/timer/NginxLogStatAggregate.php b/app/tools/controller/timer/NginxLogStatAggregate.php new file mode 100644 index 0000000..a21f7b4 --- /dev/null +++ b/app/tools/controller/timer/NginxLogStatAggregate.php @@ -0,0 +1,20 @@ +request->param('date', ''); + $manualHour = $this->request->param('hour', ''); + + if ($manualDate !== '' && $manualHour !== '') { + // 手动模式:强校验 + $dateInt = (int) $manualDate; + $hourInt = (int) $manualHour; + // YYYYMMDD 范围:10000101 ~ 99991231;hour: 0-23 + if ($dateInt < 10000101 || $dateInt > 99991231) { + return json_encode(['error' => 'invalid date format, expect YYYYMMDD'], JSON_UNESCAPED_UNICODE); + } + if ($hourInt < 0 || $hourInt > 23) { + return json_encode(['error' => 'invalid hour, expect 0-23'], JSON_UNESCAPED_UNICODE); + } + } else { + // 默认模式:取当前时间 - 1 小时(按服务器时区,框架 default_timezone=Asia/Shanghai) + $ts = time() - 3600; + $dateInt = (int) date('Ymd', $ts); + $hourInt = (int) date('G', $ts); + } + + // 3. 依赖倒置:调用 app 层入口类(业务侧可重写拦截) + $aggregator = new \app\common\service\NginxLogAggregator(); + $result = $aggregator->aggregateHour($dateInt, $hourInt); + + // 4. return JSON(补充窗口信息便于日志检索) + return json_encode(array_merge([ + 'stat_date' => $dateInt, + 'stat_hour' => $hourInt, + ], $result), JSON_UNESCAPED_UNICODE); + } +}