report.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. 'use strict';
  2. /**
  3. * 智能问数智能体 · HTML 分析报告工具
  4. * ----------------------------------------------------------------------------
  5. * build_report:为指定区间生成经营分析 HTML 报告的入口。报告本体由既有的
  6. * report-html.js / GET /api/reports/report-html 即时生成(零重复实现),工具
  7. * 只负责钳制区间、组装链接并说明报告内容;前端以「查看分析报告」按钮呈现。
  8. */
  9. const { ymdDash } = require('./lake.js');
  10. function reportSanitize(args, ctx) {
  11. const a = args || {};
  12. const { dateRange } = ctx;
  13. const from = /^\d{8}$/.test(String(a.from || '')) ? String(a.from) : dateRange.from;
  14. const to = /^\d{8}$/.test(String(a.to || '')) ? String(a.to) : dateRange.to;
  15. return {
  16. from: from < dateRange.from ? dateRange.from : from,
  17. to: to > dateRange.to ? dateRange.to : to,
  18. deep: !!a.deep,
  19. };
  20. }
  21. function reportHandler(ctx, args) {
  22. const { entityKey, dateRange } = ctx;
  23. const { from, to, deep } = args;
  24. const params = new URLSearchParams({ entity: entityKey, from, to });
  25. const url = deep ? `/api/agent/report-deep?${params.toString()}` : `/api/reports/report-html?${params.toString()}`;
  26. const wholeLake = from === dateRange.from && to === dateRange.to;
  27. return {
  28. summary: `已就绪${deep ? '深度分析报告(含数据体检/统计异常/归因/同行对标章节)' : '经营分析报告'}:${ymdDash(from)} ~ ${ymdDash(to)}${wholeLake ? '(全湖区间)' : ''}(HTML,浏览器新窗口打开,可打印导出 PDF)。回答中提示用户点击「查看分析报告」查看。`,
  29. data: { url, from, to, deep },
  30. };
  31. }
  32. module.exports = { reportSanitize, reportHandler };