v0.3.20: 每日汇报系统 — 每天8点自动收集前一日数据并推送汇总报告

新增:
- src/services/daily-report.service.ts (核心服务: 数据收集/报告生成/格式化/调度器)
- API: GET/PUT daily-report/config, GET daily-report/preview, POST daily-report/test, GET daily-report/last-run
- 前端: 侧边栏"📊 每日汇报"菜单 + SystemConfig.vue 配置面板(时间/内容开关/预览/测试发送)
- main.ts: 每60秒检查调度, 08:00-08:04 窗口内运行

报告内容: 搜索统计/转存统计(成功率)/各网盘容量和活跃状态/用户数
This commit is contained in:
2026-05-17 17:10:39 +08:00
parent 95df193e26
commit 0e0cad1271
45 changed files with 622 additions and 64 deletions

View File

@@ -796,5 +796,71 @@ router.delete('/admin/push-users/:id', (req: Request, res: Response) => {
}
});
// ═══════════════════════════════════════════════
// Daily Report
// ═══════════════════════════════════════════════
/** GET /api/admin/daily-report/config */
router.get('/admin/daily-report/config', (_req, res) => {
try {
const { getDailyReportConfig } = require('../services/daily-report.service');
const cfg = getDailyReportConfig();
res.json(cfg);
} catch (err: any) {
res.status(500).json({ error: err.message || 'Failed to get daily report config' });
}
});
/** PUT /api/admin/daily-report/config */
router.put('/admin/daily-report/config', (req, res) => {
try {
const { saveDailyReportConfig } = require('../services/daily-report.service');
saveDailyReportConfig(req.body);
const { getDailyReportConfig } = require('../services/daily-report.service');
res.json(getDailyReportConfig());
} catch (err: any) {
res.status(500).json({ error: err.message || 'Failed to save daily report config' });
}
});
/** GET /api/admin/daily-report/preview */
router.get('/admin/daily-report/preview', (req, res) => {
try {
const { previewDailyReport, generateDailyReport } = require('../services/daily-report.service');
const date = req.query.date as string || undefined;
const content = previewDailyReport(date);
const report = generateDailyReport(date);
res.json({ content, report });
} catch (err: any) {
res.status(500).json({ error: err.message || 'Failed to preview daily report' });
}
});
/** POST /api/admin/daily-report/test — send a test report immediately */
router.post('/admin/daily-report/test', async (_req, res) => {
try {
const { sendTestDailyReport } = require('../services/daily-report.service');
const result = await sendTestDailyReport();
res.json(result);
} catch (err: any) {
res.status(500).json({ error: err.message || 'Failed to send test report' });
}
});
/** GET /api/admin/daily-report/last-run */
router.get('/admin/daily-report/last-run', (_req, res) => {
try {
const { getSystemConfig } = require('../admin/system-config.service');
const raw = getSystemConfig('daily_report_last_run') || '{}';
let data: any = {};
try { data = JSON.parse(raw); } catch {}
res.json(data);
} catch (err: any) {
res.status(500).json({ error: err.message });
}
});
export default router;