'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,
deep: !!a.deep,
};
}
function reportHandler(ctx, args) {
const { entityKey, dateRange } = ctx;
const { from, to, deep } = args;
const params = new URLSearchParams({ entity: entityKey, from, to });
const url = deep ? `/api/agent/report-deep?${params.toString()}` : `/api/reports/report-html?${params.toString()}`;
const wholeLake = from === dateRange.from && to === dateRange.to;
return {
summary: `已就绪${deep ? '深度分析报告(含数据体检/统计异常/归因/同行对标章节)' : '经营分析报告'}:${ymdDash(from)} ~ ${ymdDash(to)}${wholeLake ? '(全湖区间)' : ''}(HTML,浏览器新窗口打开,可打印导出 PDF)。回答中提示用户点击「查看分析报告」查看。`,
data: { url, from, to, deep },
};
}
module.exports = { reportSanitize, reportHandler };