'use strict'; /** * 智能问数智能体 · HTML 分析报告工具 * ---------------------------------------------------------------------------- * build_report:为指定区间生成经营分析 HTML 报告的入口。报告本体由既有的 * report-html.js / GET /api/reports/report-html 即时生成(零重复实现),工具 * 只负责钳制区间、组装链接并说明报告内容;前端以「查看分析报告」按钮呈现。 */ const { ymdDash } = require('./lake.js'); function reportSanitize(args, ctx) { const a = args || {}; const { dateRange } = ctx; const from = /^\d{8}$/.test(String(a.from || '')) ? String(a.from) : dateRange.from; const to = /^\d{8}$/.test(String(a.to || '')) ? String(a.to) : dateRange.to; return { from: from < dateRange.from ? dateRange.from : from, to: to > dateRange.to ? dateRange.to : to }; } function reportHandler(ctx, args) { const { entityKey, dateRange } = ctx; const { from, to } = args; const params = new URLSearchParams({ entity: entityKey, from, to }); const url = `/api/reports/report-html?${params.toString()}`; const wholeLake = from === dateRange.from && to === dateRange.to; return { summary: `已就绪经营分析报告:${ymdDash(from)} ~ ${ymdDash(to)}${wholeLake ? '(全湖区间)' : ''},包含 KPI 概览、逐日趋势与门店明细(HTML,浏览器新窗口打开,可打印导出 PDF)。回答中提示用户点击「查看分析报告」查看。`, data: { url, from, to }, }; } module.exports = { reportSanitize, reportHandler };