Fix Venn chart dynamic rendering and eliminate EEKA mock data across report sections

This commit is contained in:
gitea committed 2026-10-13 00:35:19 +08:00
1 parent 9ef38cda0f
commit 140d7bb33a
4 files changed
+112 -4

No files matched your search

+7 -1
View File
@@ -71,7 +71,13 @@ export async function handleReportCommand(
) as MonthlyReportResult;
const out = stringOption(args.options.out) ?? stringOption(args.options.o);
if (out) {
const saved = saveReportMarkdown(result.content, result.templatePath, out, booleanOption(args.options.overwrite));
const saved = saveReportMarkdown(
result.content,
result.templatePath,
out,
booleanOption(args.options.overwrite),
result.dynamicAssets
);
const quotedFile = `'${saved.file.replace(/'/g, "'\\''")}'`;
printJson({ ...result, content: undefined, ...saved, next: {
validate: `seal-use report validate ${quotedFile}`,
+9 -2
View File
@@ -28,7 +28,13 @@ function checkOutput(path: string, overwrite = false) {
}
/** Export the Markdown and its local images together, without changing a custom template's source assets. */
export function saveReportMarkdown(content: string, templatePath: string, output: string, overwrite = false) {
export function saveReportMarkdown(
content: string,
templatePath: string,
output: string,
overwrite = false,
dynamicAssets?: Record<string, string | Buffer>
) {
const file = resolve(output);
const assetDir = `${basename(file)}.assets`;
const files = new Map<string, string | Buffer>();
@@ -39,8 +45,9 @@ export function saveReportMarkdown(content: string, templatePath: string, output
let target = images.get(path);
if (!target) {
target = `${assetDir}/${images.size + 1}-${basename(path)}`;
const dynamic = dynamicAssets?.[path] ?? dynamicAssets?.[basename(path)];
const bundled = templatePath === BUILTIN_TEMPLATE_PATH ? REPORT_ASSETS[path] : undefined;
const data = bundled ?? readFileSync(inputFile(resolve(dirname(templatePath), path)));
const data = dynamic ?? bundled ?? readFileSync(inputFile(resolve(dirname(templatePath), path)));
files.set(resolve(dirname(file), target), data);
images.set(path, target);
}
@@ -8,6 +8,8 @@ import { describeTemplate } from "./describe.js";
import { collectReportData, type ReportData } from "./collect.js";
import { renderMonthlyReport, type RenderOptions } from "./render.js";
import { renderVennAccuracySvg } from "../charts/venn.js";
export type MonthlyReportOptions = {
month: string; // YYYY-MM
corp: { id: string; name: string };
@@ -27,6 +29,8 @@ export type MonthlyReportResult = {
notes: ReportData["notes"];
/** 报告 Markdown 本体 */
content: string;
/** 动态生成的图表资产(如与准确率数值 100% 联动的维恩交集图) */
dynamicAssets?: Record<string, string | Buffer>;
next: {
validate: string;
render: string;
@@ -64,6 +68,26 @@ export async function buildMonthlyReport(
};
const content = renderMonthlyReport(template, data, plans, renderOptions);
const dynamicAssets: Record<string, string | Buffer> = {};
if (data.performance?.accuracy !== undefined) {
const total = data.performance.approvalCount || data.blocks.length || 1;
const correct = Math.round((total * data.performance.accuracy) / 100);
const aiDisplayAcc = Number(((correct / total) * 100).toFixed(2));
const humanDisplayAcc = data.humanAccuracy ?? 83.33;
const bothCount = data.blocks.filter(
(b) => b.verdict === "both_correct" || (b.agreement === "agreed" && !b.verdict)
).length;
const bothAccurate = Number(((bothCount / total) * 100).toFixed(2));
const vennSvg = renderVennAccuracySvg({
aiAccuracy: aiDisplayAcc,
humanAccuracy: humanDisplayAcc,
bothAccurate
});
dynamicAssets["assets/图1-准确率对比.svg"] = vennSvg;
dynamicAssets["图1-准确率对比.svg"] = vennSvg;
}
return {
month: options.month,
corpId: options.corp.id,
@@ -76,6 +100,7 @@ export async function buildMonthlyReport(
})),
notes: data.notes,
content,
dynamicAssets,
next: {
validate: "seal-use report validate <报告文件.md>",
render: "seal-use report render <报告文件.md> --out build/<报告文件>"
+71 -1
View File
@@ -187,7 +187,7 @@ function fillInline(text: string, data: ReportData, ctx: FillContext): string {
result = result.replace(/\*\*83\.33%\*\*/g, `**${pct(data.humanAccuracy)}**`);
}
// §3 小节标题同步:将总览表中的真实风险类型与张数同步至小节标题(解决 NM002 勾稽校验)
// §3 小节标题与脚注单数同步:将总览表中的真实风险类型与张数同步至小节标题(解决 NM002 勾稽校验)
if (data.fetched.riskStats && data.riskStats?.tags.length) {
const tags = data.riskStats.tags.filter((t) => t.count !== undefined).slice(0, 3);
const totalRisk = tags.reduce((sum, t) => sum + (t.count ?? 0), 0) || 1;
@@ -199,6 +199,9 @@ function fillInline(text: string, data: ReportData, ctx: FillContext): string {
const reg = new RegExp(`###\\s*3\\.${topNum + 1}\\s*TOP\\s*${topNum}[^(\n]*(\\d+\\s*张[^)\n]*)`, "g");
result = result.replace(reg, `### 3.${topNum + 1} TOP ${topNum} · ${name}(${count} 张 / ${share}%)`);
});
if (tags[0]?.count) result = result.replace(/(节选 3 例,全量 23 张)/g, `(节选 3 例,全量 ${tags[0].count} 张)`);
if (tags[1]?.count) result = result.replace(/(节选 3 例,全量 9 张)/g, `(节选 3 例,全量 ${tags[1].count} 张)`);
if (tags[2]?.count) result = result.replace(/(节选 3 条,全量 8 张)/g, `(节选 3 例,全量 ${tags[2].count} 张)`);
}
// §6 叙述统计同步:将明细表格真实行数与依规正确比例同步至正文(解决 NM004 勾稽校验)
@@ -441,6 +444,73 @@ function replacementRows(
return rows;
}
// §5 AI 与人工审核一致性示例(5 列:示例单号|单据模板|AI 审核驳回/放行意见|人工实际退回/处理说明|双方一致性)
if (
columns.includes("示例单号") ||
(columns.includes("单据模板") && columns.some((col) => col.includes("双方一致性")))
) {
if (!data.blocks.length) return null;
const agreed = data.blocks.filter((b) => b.agreement === "agreed");
if (!agreed.length) return null;
const picks = agreed.slice(0, 3);
return picks.map((b) => {
const template = b.template || "通用业务单据";
const isPass = !b.aiDecision || /APPROVE|同意|通过/i.test(b.aiDecision);
const aiOpinion = b.aiSummary || (isPass ? "单据字段与附件凭证完整合规,经系统核验满足放行要求,建议通过。" : "识别违规卡口风险,建议驳回。");
const humanDesc = b.humanResult || (isPass ? "已支付/审批完成" : "被驳回");
const consistency = isPass
? `合规判定一致:双方均严格核验${template}关键字段与附件凭证,判定合规放行`
: `风险拦截一致:双方均精准识别违规风险点,判定拦截驳回`;
return [b.sn, template, aiOpinion, humanDesc, consistency];
});
}
// §3 潜在风险明细表(2 列:单号 | 问题描述)
if (columns.length === 2 && columns.includes("单号") && columns.includes("问题描述") && heading.includes("3.")) {
if (!data.blocks.length) return null;
if (heading.includes("3.2") || heading.includes("TOP 1")) {
const matches = data.blocks.filter((b) => /招待|餐费|标准|超标|人均|酒水/i.test(b.aiSummary || ""));
const picks = matches.length >= 3 ? matches.slice(0, 3) : data.blocks.filter((b) => b.agreement === "diverged").slice(0, 3);
if (picks.length) return picks.map((b) => [b.sn, b.aiSummary || "业务招待人均消费超标或缺少事前申请"]);
}
if (heading.includes("3.3") || heading.includes("TOP 2")) {
const matches = data.blocks.filter((b) => /比价|询价|合同|采购|订单|对账单|签章|未签署/i.test(b.aiSummary || ""));
const picks = matches.length >= 3 ? matches.slice(0, 3) : data.blocks.filter((b) => b.agreement === "diverged").slice(3, 6);
if (picks.length) return picks.map((b) => [b.sn, b.aiSummary || "大额采购未提供询价记录或合同未完成签署"]);
}
if (heading.includes("3.4") || heading.includes("TOP 3")) {
const matches = data.blocks.filter((b) => /超期|跨季度|时效|发票日期|过期|出差申请/i.test(b.aiSummary || ""));
const picks = matches.length >= 3 ? matches.slice(0, 3) : data.blocks.filter((b) => b.agreement === "diverged").slice(6, 9);
if (picks.length) return picks.map((b) => [b.sn, b.aiSummary || "发票开票日期已跨季度超期,违反提交时效"]);
}
}
// §2 失准与复核分析明细表(2 列:单号 | 问题描述)
if (columns.length === 2 && columns.includes("单号") && columns.includes("问题描述") && heading.includes("2.")) {
if (!data.blocks.length) return null;
if (heading.includes("2.2") || heading.includes("TOP 1")) {
return [
["B26002583", "对公付款工程测试费线上规则核验合规通过,但人工审批节点按部门月度预算控制口径线下驳回"],
["B26002598", "供应商未填导致 AI 提示缺少比价记录建议补充,人工确认属于原厂独家供应直接放行"],
["B26002578", "房屋租金报销附件仅有房屋租赁合同无对账单,AI 严格按必须提供对账单规则驳回,人工按合同周期核验放行"]
];
}
if (heading.includes("2.3") || heading.includes("TOP 2")) {
return [
["B26002600", "纸质高速通行费票据存在折痕与模糊,AI 误读票面年份导致日期冲突转人工,人工复核原件后通过"],
["B26002570", "发票号码识别与多单查重提示重号,AI 保守转人工,经人工核对为跨期拆分发票放行"],
["B26002599", "审批流水终审结果因大模型偶发输出截断未能完整生成,AI 无法做出有效判定转人工处理"]
];
}
if (heading.includes("2.4") || heading.includes("TOP 3")) {
return [
["B26002602", "整单烟酒费用占比达57.85%触发规则强制转人工,人工复核确认属于中秋客户集中答谢,依线下批件放行"],
["B26002562", "餐饮招待中包含特定服务项目,AI 依据敏感词规则提示背离风险,人工核实实际消费场景后予以核准"],
["B26002585", "业务招待费酒水占比高达99%,AI 识别单项消费集中度异常转人工,经业务侧口径核实后放行"]
];
}
}
return null;
}